Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to create a fixture for a state stored aggregate #1772

Merged
merged 9 commits into from
May 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public final FixtureConfiguration<T> withSubtypes(Class<? extends T>... subtypes
return this;
}

@Override
public FixtureConfiguration<T> useStateStorage() {
return this.registerRepository(new InMemoryRepository<>(aggregateType,
smcvb marked this conversation as resolved.
Show resolved Hide resolved
subtypes,
eventStore,
getParameterResolverFactory(),
getHandlerDefinition(),
getRepositoryProvider()));
}

@Override
public FixtureConfiguration<T> registerRepository(Repository<T> repository) {
this.repository = new IdentifierValidatingRepository<>(repository);
Expand Down Expand Up @@ -314,12 +324,7 @@ public TestExecutor<T> givenState(Supplier<T> aggregate) {
clearGivenWhenState();
DefaultUnitOfWork.startAndGet(null).execute(() -> {
if (repository == null) {
registerRepository(new InMemoryRepository<>(aggregateType,
subtypes,
eventStore,
getParameterResolverFactory(),
getHandlerDefinition(),
getRepositoryProvider()));
this.useStateStorage();
}
try {
repository.newInstance(aggregate::get);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public interface FixtureConfiguration<T> {
*/
FixtureConfiguration<T> withSubtypes(Class<? extends T>... subtypes);

/**
* Configures the fixture for state stored aggregates.
sascha-eisenmann marked this conversation as resolved.
Show resolved Hide resolved
* This will register an {@link org.axonframework.test.aggregate.AggregateTestFixture.InMemoryRepository} with the fixture
*
* @return the current FixtureConfiguration, for fluent interfacing
*/
FixtureConfiguration<T> useStateStorage();

/**
* Registers an arbitrary {@code repository} with the fixture. The repository must be wired
* with the Event Store of this test fixture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ void testCreateStateStoredAggregate() {
.expectState(aggregate -> assertEquals("message2", aggregate.getMessage()));
}

@Test
void testCreateStateStoredAggregateWithCommand() {
fixture
smcvb marked this conversation as resolved.
Show resolved Hide resolved
.useStateStorage()
.givenCommands(new InitializeCommand(AGGREGATE_ID, "message"))
.when(new SetMessageCommand(AGGREGATE_ID, "message2"))
.expectEvents(new StubDomainEvent())
.expectState(aggregate -> assertEquals("message2", aggregate.getMessage()));
}

@Test
void testEmittedEventsFromExpectStateAreNotStored() {
fixture.givenState(() -> new StateStoredAggregate(AGGREGATE_ID, "message"))
Expand Down