Axon 3 RC1: Test Fixture changes

Hello,

Thanks for releasing the RC1. I noticed, that my unit tests using the previous release broke.

Caould you please outline how the fixtures for Aggregates and Sagas are to be initialized now ?

It appears that the Factory has disappeared, and that the Annotated Saga Fixture was renamed to SagaTestFixture.

`

@Before
public void setUp() {
fixture = new SagaTestFixture<>(MySaga.class);
}

`

Results in the @Autowired command bus and scheduler not be be initialized in the Saga.

fixture.registerResource(scheduler);

Does not help (tried to mock a scheduler with mockito here) and the scheduler is still null at Saga runtime.

The documentation https://docs.axonframework.org/ does not reflect these changes yet.

Thank you.

I am looking forward to test the new replay functionality.

Dominic

Ok, I think I found the issue. I stepped through the saga construction in the debugger and noticed, that you are looking for @Inject. I can understand the reasoning to avoid spring dependencies here.

Dominic

Hi Dominic,

you beat me to it. Indeed, it’s the @Inject annotation that now triggers the resources to be injected. You may also place the annotation directly on fields.

Cheers,

Allard

Hi,

Is it possible to inject custom class as a resource? I have no issues registering CommandGateway or EventScheduler.

Under Saga declaring it transient and Autowiring instantiates the bean but registering through the AnnotatedSagaTestFixture results in null.

`
AbcSaga{

private transient SagaProps sagaProps;

@Autowired / @Inject
public void setSagaProps(SagaProps sagaProps) {
this.sagaProps = sagaProps;
}

methoA{
// sagaProps is null here

sagaProps.getValue();
}

`

`
AbcSagaTest{

//fixture is initialized through AnnotatedTestSagaFixture.

@Test
TestA{
I have mocked the SagaProps here and sending the mocked bean to register as below

fixture().registerResource(mockedSagaProps);
}
`

Axon Version: 2.4.6

Regards :
Harinder Singh

Hi,

registering the resource with the fixture should be enough to have it injected. In Axon 2.4, resources in the fixture are injected into setter methods. Their name should start with “set” and have exactly one parameter.

Are you sure you register the resource before invoking any of the given/when/then scenarios?

Cheers,

Allard