Axon 3 RC1: Test Fixture changes

199 views
Skip to first unread message

Dominic Heutelbeck

unread,
Nov 21, 2016, 11:05:52 AM11/21/16
to Axon Framework Users
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


Dominic Heutelbeck

unread,
Nov 21, 2016, 2:16:42 PM11/21/16
to Axon Framework Users
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

Allard Buijze

unread,
Nov 21, 2016, 4:31:23 PM11/21/16
to Axon Framework Users
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

--
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.

Harinder Singh

unread,
Oct 5, 2017, 3:08:47 AM10/5/17
to Axon Framework Users
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

Allard Buijze

unread,
Oct 6, 2017, 3:04:52 AM10/6/17
to Axon Framework Users
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

Op do 5 okt. 2017 om 09:08 schreef Harinder Singh <kainth...@gmail.com>:
--
Reply all
Reply to author
Forward
0 new messages