-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from JohT/feature/projectiontest
Query side projection integration tests based on messages
- Loading branch information
Showing
9 changed files
with
3,581 additions
and
3,773 deletions.
There are no files selected for viewing
7,201 changes: 3,430 additions & 3,771 deletions
7,201
...e-image-agent-results/java11-axon-4-5-5-quarkus-2-6-1-Final/native-image-agent-trace.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ithub/joht/showcase/quarkuseventsourcing/messaging/query/axon/EventPublishingAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon; | ||
|
||
import static javax.transaction.Transactional.TxType.REQUIRED; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
import org.axonframework.eventhandling.gateway.EventGateway; | ||
|
||
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.EventPublishingService; | ||
|
||
public class EventPublishingAdapter implements EventPublishingService { | ||
|
||
private final EventGateway eventGateway; | ||
|
||
public EventPublishingAdapter(EventGateway eventGateway) { | ||
this.eventGateway = eventGateway; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
@Transactional(REQUIRED) | ||
public void publish(Object... events) { | ||
eventGateway.publish(events); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EventPublishingAdapter [eventGateway=" + eventGateway + "]"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...b/joht/showcase/quarkuseventsourcing/messaging/query/boundary/EventPublishingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary; | ||
|
||
/** | ||
* Provides methods to publish events. | ||
* Based on the "EventGateway" in "AxonFramework". | ||
*/ | ||
public interface EventPublishingService { | ||
|
||
/** | ||
* Publishes events that will be dispatched to all subscribed listeners. | ||
* | ||
* @param events The collection of events to publish | ||
*/ | ||
void publish(Object... events); | ||
} |
1 change: 1 addition & 0 deletions
1
...entsourcing/src/main/resources/db/command/common/V1.1.7__DomainEventEntryTypeNullable.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE "axon_on_microprofile_tryout"."domainevententry" ALTER COLUMN TYPE VARCHAR(255) NULL; |
31 changes: 31 additions & 0 deletions
31
...b/joht/showcase/quarkuseventsourcing/messaging/query/axon/EventPublishingAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon; | ||
|
||
import static org.mockito.Mockito.verify; | ||
|
||
import org.axonframework.eventhandling.gateway.EventGateway; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class EventPublishingAdapterTest { | ||
|
||
@Mock | ||
EventGateway eventGateway; | ||
|
||
@InjectMocks | ||
EventPublishingAdapter adapterUnderTest; | ||
|
||
@Test | ||
void eventPublishDelegatedToEventGateway() { | ||
TestEvent testEvent = new TestEvent(); | ||
adapterUnderTest.publish(testEvent); | ||
verify(eventGateway).publish(testEvent); | ||
} | ||
|
||
private static class TestEvent { | ||
|
||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../github/joht/showcase/quarkuseventsourcing/query/model/account/AccountProjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.github.joht.showcase.quarkuseventsourcing.query.model.account; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.github.joht.showcase.quarkuseventsourcing.message.common.Nickname; | ||
import io.github.joht.showcase.quarkuseventsourcing.message.event.account.AccountCreatedEvent; | ||
import io.github.joht.showcase.quarkuseventsourcing.message.event.account.NicknameChangedEvent; | ||
import io.github.joht.showcase.quarkuseventsourcing.message.event.account.NicknamePresetEvent; | ||
import io.github.joht.showcase.quarkuseventsourcing.message.query.account.AccountNicknameQuery; | ||
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.EventPublishingService; | ||
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.QuerySubmitterService; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
/** | ||
* Read-Side (Integration-)Test that operates on message level. | ||
* <p> | ||
* This is a black-box test. Published events represent the input. Query messages return the output, | ||
* that is compared to the expected values. | ||
* Given that there is no pre-existing state, the test is perfectly reconstructible and repeatable. | ||
* <p> | ||
* This test also shows the strength of a CQRS-Read-Side (Projection) that ideally only depends | ||
* on the events it consumes and its current state. | ||
* Test cases can be completely described as a sequence of events. | ||
*/ | ||
@QuarkusTest | ||
class AccountProjectionTest { | ||
|
||
@Inject | ||
EventPublishingService eventGateway; | ||
|
||
@Inject | ||
QuerySubmitterService queryGateway; | ||
|
||
@Test | ||
@DisplayName("After a account had been created and the nickname had been changed the new nickname is returned by the query") | ||
void nicknameChangeQueryable() throws InterruptedException, ExecutionException { | ||
String accountId = createTestAccountId(); | ||
Nickname expectedNickname = Nickname.of("Eddie"); | ||
|
||
eventGateway.publish(new AccountCreatedEvent(accountId)); | ||
eventGateway.publish(new NicknamePresetEvent(accountId, Nickname.none())); | ||
eventGateway.publish(new NicknameChangedEvent(accountId, expectedNickname, Nickname.none())); | ||
|
||
Nickname nickname = queryGateway.query(new AccountNicknameQuery(accountId), Nickname.class).get(); | ||
assertEquals(expectedNickname, nickname); | ||
} | ||
|
||
private String createTestAccountId() { | ||
return getClass().getSimpleName() + "-accountId-" + UUID.randomUUID(); | ||
} | ||
} |