EventTemplate and saga fixtures

Hello list,

I was trying to asset assert the correct behaviour of a saga with the AnnotatedSagaTestFixture.

The first implementation was using an injected EventTemplate, but it appears that the fixture does not have an EventTemplate dummy available by default.

As a workaround I resolved by injecting the EventBus and instantiating an EventTemplate on the fly, with this tedious piece of code:

`

@Transient
private transient EventTemplate eventTemplate;

@Autowired
public void setEventBus(EventBus eventBus) {
eventTemplate = new EventTemplate(eventBus);
}

`

At this point I was wondering if this is the best way to publish events from sagas.

Alternatively, is there a correct way to register an EventTemplate with the fixture so that published event will reach the fixture’s EventBus?

Cheers,
Andrea

Hi Andrea,

you can register resources to be injected using “registerResource” on the test fixture. If your saga has a setter (sorry, setter injection only), the resource will be automatically injected. You can use the fixture to access the EventBus instance to inject into the EventTemplate.

Cheers,

Allard