When Event Modeling we frequently model automations, and when making specifications for automations we typically do it the same way we specify state views, and specify state changes. By defining Given (events) Then (readmodel), and Given (events) When (command), Then (event(s)).
Automations are typically implemented as a readmodel that is streaming to or being polled by a concurrency-limited / single-threaded processor. But Axon Framework 5 introduced a different way of implementing automations, that introduces significant concurrency benefits.
We dont want our implementation details to change the way we model, so that got me thinking about how to create automations in AF5 in a way that maps really cleanly to the specifications. Now I've also been playing a lot with static codegen from my event models into AF5 code, and one of the best features is being able to statically generate tests from specifications with the help of the AxonTestFixture. Having those tests in place is a real success factor when it comes to letting AI implement slices. But when I generate automations I found myself needing to statically generate "readmodel assertions" on @EventSourcedEntity classes.
Heres how I currently do it:
fixture.given()
.event(new StudentCreatedEvent("student-1", "Alice"))
.then()
.events(new StudentNameChangedEvent("student-1", "Bob"))
.expect(config -> {
var stateManager = config.getComponent(StateManager.class);
var uowFactory = config.getComponent(UnitOfWorkFactory.class);
var processingContext = uowFactory.create().processingContext();
var student = stateManager.loadEntity(Student.class, "student-1", processingContext).join();
assertThat(student.name()).isEqualTo("Bob");
});
But I think that the test fixture would benefit from a "cleaner" api regarding this, something like this:
fixture.given()
.event(new StudentCreatedEvent("student-1", "Alice"))
.then()
.events(new StudentNameChangedEvent("student-1", "Bob"))
.entity(Student.class, "student-1", student -> {
assertThat(student.name()).isEqualTo("Bob");
});
Would love to know what you guys think, I could definitely make a PR for it, but I wanted to discuss it first.
When Event Modeling we frequently model automations, and when making specifications for automations we typically do it the same way we specify state views, and specify state changes. By defining Given (events) Then (readmodel), and Given (events) When (command), Then (event(s)).
Automations are typically implemented as a readmodel that is streaming to or being polled by a concurrency-limited / single-threaded processor. But Axon Framework 5 introduced a different way of implementing automations, that introduces significant concurrency benefits.
We dont want our implementation details to change the way we model, so that got me thinking about how to create automations in AF5 in a way that maps really cleanly to the specifications. Now I've also been playing a lot with static codegen from my event models into AF5 code, and one of the best features is being able to statically generate tests from specifications with the help of the AxonTestFixture. Having those tests in place is a real success factor when it comes to letting AI implement slices. But when I generate automations I found myself needing to statically generate "readmodel assertions" on @EventSourcedEntity classes.
Heres how I currently do it:
But I think that the test fixture would benefit from a "cleaner" api regarding this, something like this:
Would love to know what you guys think, I could definitely make a PR for it, but I wanted to discuss it first.