-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
284 additions
and
11 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
...xample/cakeshop/event/listener/provider/ExampleEventListenerInterceptorChainProvider.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,27 @@ | ||
package uk.gov.justice.services.example.cakeshop.event.listener.provider; | ||
|
||
import uk.gov.justice.services.core.interceptor.InterceptorChainEntry; | ||
import uk.gov.justice.services.core.interceptor.InterceptorChainEntryProvider; | ||
import uk.gov.justice.services.event.source.subscriptions.interceptors.SubscriptionEventInterceptor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExampleEventListenerInterceptorChainProvider implements InterceptorChainEntryProvider { | ||
|
||
private final List<InterceptorChainEntry> interceptorChainEntries = new ArrayList<InterceptorChainEntry>(); | ||
|
||
public ExampleEventListenerInterceptorChainProvider() { | ||
interceptorChainEntries.add(new InterceptorChainEntry(1000, SubscriptionEventInterceptor.class)); | ||
} | ||
|
||
@Override | ||
public String component() { | ||
return "EVENT_LISTENER"; | ||
} | ||
|
||
@Override | ||
public List<InterceptorChainEntry> interceptorChainTypes() { | ||
return interceptorChainEntries; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...le/cakeshop/event/listener/provider/ExampleEventListenerInterceptorChainProviderTest.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,30 @@ | ||
package uk.gov.justice.services.example.cakeshop.event.listener.provider; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import uk.gov.justice.services.core.interceptor.InterceptorChainEntry; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
public class ExampleEventListenerInterceptorChainProviderTest { | ||
|
||
@Test | ||
public void shouldCreateInterceptorChainEntriesWithSubscriptionEventInterceptor() { | ||
|
||
final List<InterceptorChainEntry> interceptorChainEntries = new ExampleEventListenerInterceptorChainProvider().interceptorChainTypes(); | ||
|
||
assertThat(interceptorChainEntries.size(), is(1)); | ||
|
||
final InterceptorChainEntry interceptorChainEntry = interceptorChainEntries.get(0); | ||
assertThat(interceptorChainEntry.getInterceptorType().getName(), is("uk.gov.justice.services.event.source.subscriptions.interceptors.SubscriptionEventInterceptor")); | ||
assertThat(interceptorChainEntry.getPriority(), is(1000)); | ||
} | ||
|
||
@Test | ||
public void shouldReturnComponentName() { | ||
assertThat(new ExampleEventListenerInterceptorChainProvider().component(), is("EVENT_LISTENER")); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
example-context/example-service/example-initialisation-liquibase/pom.xml
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>example-service</artifactId> | ||
<groupId>uk.gov.justice.services.example</groupId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>example-initialisation-liquibase</artifactId> | ||
|
||
<properties> | ||
<sonar.skip>true</sonar.skip> | ||
</properties> | ||
|
||
</project> |
1 change: 1 addition & 0 deletions
1
.../example-service/example-initialisation-liquibase/src/main/resources/liquibase.properties
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 @@ | ||
changeLogFile=liquibase/initialise-event-log-db-changelog.xml |
9 changes: 9 additions & 0 deletions
9
...itialisation-liquibase/src/main/resources/liquibase/initialise-event-log-db-changelog.xml
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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd"> | ||
|
||
<includeAll relativeToChangelogFile="true" path="initialise-event-log-db-changesets"/> | ||
|
||
</databaseChangeLog> |
54 changes: 54 additions & 0 deletions
54
...rc/main/resources/liquibase/initialise-event-log-db-changesets/001-add-initial-events.xml
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,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd"> | ||
<changeSet id="001-add-initial-events" author="techpod" | ||
logicalFilePath="001-add-initial-events.xml"> | ||
|
||
<insert tableName="event_log"> | ||
<column name="id" value="00b78ee7-5d2c-4b6d-858e-0701d0412515"/> | ||
<column name="stream_id" value="489c5e3b-8c0c-4e26-855f-34592604bd98"/> | ||
<column name="position_in_stream" value="1"/> | ||
<column name="name" value="example.recipe-added"/> | ||
<column name="payload" value="{"recipeId":"489c5e3b-8c0c-4e26-855f-34592604bd98","name":"Carrot Cake","ingredients":[{"name":"someIngredient","quantity":1}],"glutenFree":false}" /> | ||
<column name="metadata" value="{"createdAt":"2018-12-06T16:32:48.725Z","id":"00b78ee7-5d2c-4b6d-858e-0701d0412515","name":"example.recipe-added","causation":["63bc8905-2705-41f9-892e-946e632b1837","ffbf5c08-df37-4203-ad81-f8f12edfed2b"],"stream":{"id":"489c5e3b-8c0c-4e26-855f-34592604bd98","version":1},"source":"event.source","event":{"eventNumber":1,"previousEventNumber":0}}"/> | ||
<column name="date_created" value="2018-12-06 16:32:48.725+00"/> | ||
<column name="event_number" value="1"/> | ||
</insert> | ||
|
||
<insert tableName="event_log"> | ||
<column name="id" value="f05cc199-52ab-40a6-ae88-465f810340f6"/> | ||
<column name="stream_id" value="8440bcc3-a4d6-4bd1-817c-ab89ffd307ae"/> | ||
<column name="position_in_stream" value="1"/> | ||
<column name="name" value="example.recipe-added"/> | ||
<column name="payload" value="{"recipeId":"8440bcc3-a4d6-4bd1-817c-ab89ffd307ae","name":"Lemon Drizzle Cake","ingredients":[{"name":"someIngredient","quantity":1}],"glutenFree":false}" /> | ||
<column name="metadata" value="{"createdAt":"2018-12-07T13:29:54.719Z","id":"f05cc199-52ab-40a6-ae88-465f810340f6","name":"example.recipe-added","causation":["ed137a6a-551c-4f8e-8ca2-b1a1cafe2e0d","c6da75ac-41c2-4994-81b7-1a9705c1550f"],"stream":{"id":"8440bcc3-a4d6-4bd1-817c-ab89ffd307ae","version":1},"source":"event.source","event":{"eventNumber":2,"previousEventNumber":1}}"/> | ||
<column name="date_created" value="2018-12-06 16:32:48.725+00"/> | ||
<column name="event_number" value="2"/> | ||
</insert> | ||
|
||
<insert tableName="event_log"> | ||
<column name="id" value="a4fd2ad1-1bef-47dc-9ba5-7525dee670b0"/> | ||
<column name="stream_id" value="489c5e3b-8c0c-4e26-855f-34592604bd98"/> | ||
<column name="position_in_stream" value="2"/> | ||
<column name="name" value="example.recipe-renamed"/> | ||
<column name="payload" value="{"recipeId":"489c5e3b-8c0c-4e26-855f-34592604bd98","name":"Turnip Cake"}" /> | ||
<column name="metadata" value="{"createdAt":"2018-12-06T16:32:52.325Z","id":"a4fd2ad1-1bef-47dc-9ba5-7525dee670b0","name":"example.recipe-renamed","causation":["6d1aa026-85fc-4757-8f67-634d43f74969","0868cb11-6fd8-49ac-8f77-69e8ee203ee1"],"stream":{"id":"489c5e3b-8c0c-4e26-855f-34592604bd98","version":2},"source":"event.source","event":{"eventNumber":3,"previousEventNumber":2}}"/> | ||
<column name="date_created" value="2018-12-06 16:32:52.325+00"/> | ||
<column name="event_number" value="3"/> | ||
</insert> | ||
|
||
<insert tableName="event_log"> | ||
<column name="id" value="ceeb2594-3d66-4187-b660-4eae72ab6dac"/> | ||
<column name="stream_id" value="8440bcc3-a4d6-4bd1-817c-ab89ffd307ae"/> | ||
<column name="position_in_stream" value="2"/> | ||
<column name="name" value="example.recipe-renamed"/> | ||
<column name="payload" value="{"recipeId":"8440bcc3-a4d6-4bd1-817c-ab89ffd307ae","name":"Rock Cake"}" /> | ||
<column name="metadata" value="{"createdAt":"2018-12-07T13:29:57.250Z","id":"ceeb2594-3d66-4187-b660-4eae72ab6dac","name":"example.recipe-renamed","causation":["e67cbf7c-ede1-4a17-8966-2da413967849","5c31a322-f201-4340-939a-8e0cd4c67836"],"stream":{"id":"8440bcc3-a4d6-4bd1-817c-ab89ffd307ae","version":2},"source":"event.source","event":{"eventNumber":4,"previousEventNumber":3}}"/> | ||
<column name="date_created" value="2018-12-06 16:32:52.325+00"/> | ||
<column name="event_number" value="4"/> | ||
</insert> | ||
|
||
</changeSet> | ||
</databaseChangeLog> |
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
2 changes: 1 addition & 1 deletion
2
...justice/services/eventsourcing/jdbc/snapshot/StandaloneSnapshotJdbcRepositoryFactory.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
81 changes: 81 additions & 0 deletions
81
...-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.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,81 @@ | ||
package uk.gov.justice.services.example.cakeshop.it; | ||
|
||
import static com.jayway.jsonassert.JsonAssert.with; | ||
import static java.util.UUID.fromString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.CONTEXT_NAME; | ||
|
||
import uk.gov.justice.services.event.buffer.core.repository.subscription.Subscription; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.CakeShopRepositoryManager; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.CommandFactory; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFinder; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.Querier; | ||
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory; | ||
|
||
import javax.ws.rs.client.Client; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class CakeShopReplayEventsIT { | ||
|
||
private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); | ||
|
||
private final EventFactory eventFactory = new EventFactory(); | ||
private final EventFinder eventFinder = new EventFinder(CAKE_SHOP_REPOSITORY_MANAGER); | ||
private final CommandFactory commandFactory = new CommandFactory(); | ||
|
||
private Client client; | ||
private Querier querier; | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
CAKE_SHOP_REPOSITORY_MANAGER.initialise(); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
client = new RestEasyClientFactory().createResteasyClient(); | ||
querier = new Querier(client); | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
client.close(); | ||
} | ||
|
||
@Test | ||
public void shouldFindReplayedRecipesInViewStore() { | ||
|
||
final String recipeId_1 = "489c5e3b-8c0c-4e26-855f-34592604bd98"; | ||
final String recipeId_2 = "8440bcc3-a4d6-4bd1-817c-ab89ffd307ae"; | ||
|
||
final ApiResponse response_1 = querier.queryForRecipe(recipeId_1); | ||
final ApiResponse response_2 = querier.queryForRecipe(recipeId_2); | ||
|
||
with(response_1.body()) | ||
.assertThat("$.id", equalTo(recipeId_1)) | ||
.assertThat("$.name", equalTo("Turnip Cake")); | ||
|
||
with(response_2.body()) | ||
.assertThat("$.id", equalTo(recipeId_2)) | ||
.assertThat("$.name", equalTo("Rock Cake")); | ||
|
||
assertThat(subscription(recipeId_1).getPosition(), is(2L)); | ||
assertThat(subscription(recipeId_2).getPosition(), is(2L)); | ||
} | ||
|
||
@SuppressWarnings("OptionalGetWithoutIsPresent") | ||
private Subscription subscription(final String recipeId) { | ||
return CAKE_SHOP_REPOSITORY_MANAGER | ||
.getSubscriptionJdbcRepository() | ||
.findByStreamIdAndSource(fromString(recipeId), CONTEXT_NAME) | ||
.get(); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...ice/services/example/cakeshop/it/helpers/StandaloneSubscriptionJdbcRepositoryFactory.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
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