Help about Saga test and Spring Configuration

Hello,
I want to use the spring configuration class to inject the commandGateway inside a saga instance.
I set as @Autowired the CommandGateway transient field in Saga class, but my test fails due to a NullPointerException. The CommandGateway is not injected.

Do you see what I can’t see? Maybe it’s something missing in Axon configuration properties that gives me this “I don’t know what happen but it happens, sorry” exception? :smiley:

Here’s the Saga code:

`

@Component
public class EnrollmentSaga extends AbstractAnnotatedSaga {
private boolean personalInfoChanged = false;

@Autowired
private transient CommandGateway commandGateway;

@StartSaga
@SagaEventHandler(associationProperty = “enrollmentId”)
public void handle(final EnrollmentStartedEvent event) {

associateWith(“employeeId”, event.getEmployeeId().toString());

commandGateway.send(new RegisterPersonalInfo(event.getEmployeeId(), event.getPerson()));
}
}

`

Here’s the Test code:

`

@Test
public void shouldEnrollANewEmployee() {
val employeeId = UUID.randomUUID();
val hiringDate = DateTime.parse(“2015-09-05T12:00”);
val enrollmentId = new EnrollmentId(UUID.randomUUID());

final AnnotatedSagaTestFixture fixture = new AnnotatedSagaTestFixture(EnrollmentSaga.class);
// fixture.registerCommandGateway(CommandGateway.class, commandGateway);
fixture.givenAggregate(enrollmentId).published()
.whenPublishingA(new EnrollmentStartedEvent(enrollmentId, employeeId,
person,
contract))

// or, to match against the payload of a Command Message only
.expectDispatchedCommandsMatching(payloadsMatching(listWithAllOf(equalTo(
new RegisterPersonalInfo(employeeId, person)))));
}

`

Thank you very much,
Samuele

Hi,

unfortunately, the Saga fixtures don’t work using Spring dependency injection annotations (yet). To be able to inject the gateway, you’ll need a setter that accepts the Gateway as parameter.

Cheers,

Allard