Using saga fixture to test the next step of a saga

Hi.

I have a saga that looks similar to:

@Saga(sagaStore = "mySagaStore")
public class ValidateAndRequestTranslationsForModifiedRecordDataSaga {
    private Set<RecordData> changedRecords = new HashSet<>();

    @StartSaga
    @SagaEventHandler(associationProperty = "uniqueId")
    public void on(RecordDataCreatedEvent event) {
        changedRecords.addAll(event.createdData());
    }

    @StartSaga
    @SagaEventHandler(associationProperty = "uniqueId")
    public void on(RecordDataUpdatedEvent event) {
        changedRecords.addAll(event.updatedData());
    }
    
    @EndSaga
    @SagaEventHandler(associationProperty = "uniqueId")
    public void on(RecordModifiedEvent event) throws JsonProcessingException {
        // act on the changed records and do something
    }
}

How can I use the saga fixture to test what happens when the RecordModifiedEvent is issued.

In the documentation you see examples like:

fixture.givenNoPriorActivity()
        .whenAggregate(event.uniqueId())
        .publishes(aRecordModifiedEvent)
        .expectActiveSagas(1)
        .expectAssociationWith("uniqueId", event.uniqueId());

But I need my saga to be pre-filled with changed records before I test the record modified event.
Did I miss something or am I thinking incorrectly?

There are some examples in the code-samples for more advanced tests. I hope those are enough, but please let us know in you have additional questions.

That did the trick.

Thank you so much for the quick answer.

If I can make a suggestion, adding a link in the saga testing documentation to these code samples file would help a lot. :slight_smile:

2 Likes