Writing Saga Fixture tests when a Saga has constructor parameters

78 views
Skip to first unread message

Sadique Ali

unread,
Nov 17, 2015, 8:26:33 AM11/17/15
to Axon Framework Users
Hi,

I have a Saga that executes a command in the saga's EndSaga handler. It looks like this (Not actual code, just similar).


public class ScheduleEmailSaga extends AbstractAnnotatedSaga {
   
private EmailAddress emailAddress;

   
CommandGateway gateway;

   
public ScheduleEmailSaga() {
   
}

   
public ScheduleEmailSaga(CommandGateway gateway) {
     
this.gateway = gateway;
   
}

   
@StartSaga
   
public void on(EmailCreatedEvent event) {
     
this.associateWith("accountEmail", event.getEmailAddress());
   
}

   
@EndSaga
   
public void on(EmailVerifiedEvent event) {
     
this.gateway.executeAsync(new ScheduleWelcomeEmailCommand(event.getEmailAddress()));
   
}
}



I am trying to test this interaction using an AnnotatedSagaTestFixture, but could not find any way to inject the CommandGateway instance in to the saga under test. The AnnotatedSagaTestFixture can construct the saga only with the default no-argument constructor.

What approach should I take here?

Thank you.
Sadique Ali





Allard Buijze

unread,
Nov 18, 2015, 2:39:27 PM11/18/15
to Axon Framework Users
Hi,

injection in Sagas is done (by default) using setters. For the fixture, you need a setter for the resources that you want to use. 
Resources you want to inject need to be registered with the fixture, except for the CommandGateway, CommandBus and EventBus.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages