-
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.
Merge pull request #38 from CJSCommonPlatform/improve-integation-test
Improve integration tests
- Loading branch information
Showing
35 changed files
with
840 additions
and
604 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
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: 0 additions & 81 deletions
81
...l-integration-test/src/test/java/uk/gov/justice/framework/tools/replay/DatabaseUtils.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
...integration-test/src/test/java/uk/gov/justice/framework/tools/replay/EventOrderingIT.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,96 @@ | ||
package uk.gov.justice.framework.tools.replay; | ||
|
||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.UUID.randomUUID; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import uk.gov.justice.framework.tools.replay.database.DatasourceCreator; | ||
import uk.gov.justice.framework.tools.replay.database.EventInserter; | ||
import uk.gov.justice.framework.tools.replay.database.LiquibaseRunner; | ||
import uk.gov.justice.framework.tools.replay.events.User; | ||
import uk.gov.justice.framework.tools.replay.events.UserFactory; | ||
import uk.gov.justice.framework.tools.replay.h2.InMemoryDatabaseRunner; | ||
import uk.gov.justice.framework.tools.replay.wildfly.WildflyRunner; | ||
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class EventOrderingIT { | ||
|
||
private static final Boolean SHOULD_LOG_WILDFLY_PROCESS_TO_CONSOLE = true; | ||
private static final Boolean ENABLE_REMOTE_DEBUGGING_FOR_WILDFLY = false; | ||
|
||
private static final int WILDFLY_TIMEOUT_IN_SECONDS = 60; | ||
|
||
private final LiquibaseRunner liquibaseRunner = new LiquibaseRunner(); | ||
private final DatasourceCreator datasourceCreator = new DatasourceCreator(); | ||
private final WildflyRunner wildflyRunner = new WildflyRunner(); | ||
|
||
private final DataSource viewStoreDataSource = datasourceCreator.createViewStoreDataSource(); | ||
private final DataSource eventStoreDataSource = datasourceCreator.createEventStoreDataSource(); | ||
private final EventInserter eventInserter = new EventInserter(eventStoreDataSource, viewStoreDataSource); | ||
private final UserFactory userFactory = new UserFactory(); | ||
private final InMemoryDatabaseRunner inMemoryDatabaseRunner = new InMemoryDatabaseRunner(); | ||
|
||
@Before | ||
public void startDatabase() { | ||
inMemoryDatabaseRunner.startH2Database(); | ||
} | ||
|
||
@Before | ||
public void runLiquibase() throws Exception { | ||
liquibaseRunner.createEventStoreSchema(eventStoreDataSource); | ||
liquibaseRunner.createViewStoreSchema(viewStoreDataSource); | ||
} | ||
|
||
@After | ||
public void stopDB() throws Exception { | ||
inMemoryDatabaseRunner.stopH2Database(); | ||
} | ||
|
||
@Test | ||
public void shouldInsertEventsInTheCorrectOrder() throws Exception { | ||
|
||
final UUID streamId = randomUUID(); | ||
final String eventName = "framework.update-user"; | ||
|
||
final UUID userId = randomUUID(); | ||
|
||
|
||
final User user = new User(userId, "Fred", "Bloggs"); | ||
final User updatedUser = new User(userId, "Billy", "Bloggs"); | ||
|
||
|
||
final List<Event> someEvents = userFactory.convertToEvents(asList(user, updatedUser), eventName, streamId); | ||
|
||
eventInserter.insertEventsIntoVewstore( | ||
streamId, | ||
someEvents); | ||
|
||
final boolean wildflyRanSuccessfully = wildflyRunner.run( | ||
WILDFLY_TIMEOUT_IN_SECONDS, | ||
SHOULD_LOG_WILDFLY_PROCESS_TO_CONSOLE, | ||
ENABLE_REMOTE_DEBUGGING_FOR_WILDFLY | ||
); | ||
|
||
assertTrue("Wildfly process exited abnormally", wildflyRanSuccessfully); | ||
|
||
final List<User> usersFromViewStore = eventInserter.getUsersFromViewStore(); | ||
|
||
assertThat(usersFromViewStore.size(), is(1)); | ||
|
||
assertThat(usersFromViewStore.get(0).getUserId(), is(userId)); | ||
assertThat(usersFromViewStore.get(0).getFirstName(), is("Billy")); | ||
assertThat(usersFromViewStore.get(0).getLastName(), is("Bloggs")); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...t/src/test/java/uk/gov/justice/framework/tools/replay/InsertAllEventsIntoViewStoreIT.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,103 @@ | ||
package uk.gov.justice.framework.tools.replay; | ||
|
||
|
||
import static java.lang.String.format; | ||
import static java.util.UUID.randomUUID; | ||
import static java.util.stream.Collectors.toList; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import uk.gov.justice.framework.tools.replay.database.DatasourceCreator; | ||
import uk.gov.justice.framework.tools.replay.database.EventInserter; | ||
import uk.gov.justice.framework.tools.replay.database.LiquibaseRunner; | ||
import uk.gov.justice.framework.tools.replay.events.User; | ||
import uk.gov.justice.framework.tools.replay.events.UserFactory; | ||
import uk.gov.justice.framework.tools.replay.h2.InMemoryDatabaseRunner; | ||
import uk.gov.justice.framework.tools.replay.wildfly.WildflyRunner; | ||
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class InsertAllEventsIntoViewStoreIT { | ||
|
||
private static final Boolean SHOULD_LOG_WILDFLY_PROCESS_TO_CONSOLE = true; | ||
private static final Boolean ENABLE_REMOTE_DEBUGGING_FOR_WILDFLY = false; | ||
|
||
private static final int WILDFLY_TIMEOUT_IN_SECONDS = 60; | ||
private static final int NUMBER_OF_EVENTS_TO_INSERT = 100; | ||
|
||
private final LiquibaseRunner liquibaseRunner = new LiquibaseRunner(); | ||
private final DatasourceCreator datasourceCreator = new DatasourceCreator(); | ||
private final WildflyRunner wildflyRunner = new WildflyRunner(); | ||
|
||
private final DataSource viewStoreDataSource = datasourceCreator.createViewStoreDataSource(); | ||
private final DataSource eventStoreDataSource = datasourceCreator.createEventStoreDataSource(); | ||
private final EventInserter eventInserter = new EventInserter(eventStoreDataSource, viewStoreDataSource); | ||
private final UserFactory userFactory = new UserFactory(); | ||
private final InMemoryDatabaseRunner inMemoryDatabaseRunner = new InMemoryDatabaseRunner(); | ||
|
||
@Before | ||
public void startDatabase() { | ||
inMemoryDatabaseRunner.startH2Database(); | ||
} | ||
|
||
@Before | ||
public void runLiquibase() throws Exception { | ||
liquibaseRunner.createEventStoreSchema(eventStoreDataSource); | ||
liquibaseRunner.createViewStoreSchema(viewStoreDataSource); | ||
} | ||
|
||
@After | ||
public void stopDB() throws Exception { | ||
inMemoryDatabaseRunner.stopH2Database(); | ||
} | ||
|
||
@Test | ||
public void shouldReadEventsFromEventStoreAndInsertIntoViewStore() throws Exception { | ||
|
||
System.out.println(format("Inserting %d events with timeout of %d seconds", NUMBER_OF_EVENTS_TO_INSERT, WILDFLY_TIMEOUT_IN_SECONDS)); | ||
|
||
final UUID streamId = randomUUID(); | ||
final String eventName = "framework.update-user"; | ||
|
||
final List<User> users = userFactory.createSomeUsers(NUMBER_OF_EVENTS_TO_INSERT); | ||
final List<Event> someEvents = userFactory.convertToEvents(users, eventName, streamId); | ||
|
||
eventInserter.insertEventsIntoVewstore( | ||
streamId, | ||
someEvents); | ||
|
||
final List<Event> insertedEvents = eventInserter.getAllFromEventStore().collect(toList()); | ||
|
||
assertThat(insertedEvents.size(), is(NUMBER_OF_EVENTS_TO_INSERT)); | ||
|
||
System.out.println(format("%d events inserted into view store", insertedEvents.size())); | ||
|
||
final boolean wildflyRanSuccessfully = wildflyRunner.run( | ||
WILDFLY_TIMEOUT_IN_SECONDS, | ||
SHOULD_LOG_WILDFLY_PROCESS_TO_CONSOLE, | ||
ENABLE_REMOTE_DEBUGGING_FOR_WILDFLY | ||
); | ||
|
||
assertTrue("Wildfly process exited abnormally", wildflyRanSuccessfully); | ||
|
||
final List<User> usersFromViewStore = eventInserter.getUsersFromViewStore(); | ||
|
||
|
||
System.out.println(usersFromViewStore.size() + " events of " + NUMBER_OF_EVENTS_TO_INSERT + " were replayed into the view store"); | ||
|
||
assertThat(usersFromViewStore.size(), is(NUMBER_OF_EVENTS_TO_INSERT)); | ||
|
||
users.forEach(usersFromViewStore::remove); | ||
|
||
assertTrue(usersFromViewStore.isEmpty()); | ||
} | ||
} |
Oops, something went wrong.