Writing Saga Fixture tests when a Saga has constructor parameters

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

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