use of uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event in project microservice_framework by CJSCommonPlatform.
the class EventsPageIT method storeEvents.
private void storeEvents(final int eventNumber) throws InvalidPositionException {
for (int i = 1; i <= eventNumber; i++) {
final UUID id = randomUUID();
final Metadata metadata = JsonEnvelope.metadataBuilder().withId(id).withStreamId(STREAM_ID).withName("name").createdAt(now()).withVersion(i).build();
final Event event = new Event(randomUUID(), STREAM_ID, valueOf(i), "Test Name" + i, metadata.asJsonObject().toString(), createObjectBuilder().add("field" + i, "value" + i).build().toString(), new UtcClock().now());
eventsRepository.insert(event);
}
}
use of uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event in project microservice_framework by CJSCommonPlatform.
the class DefaultEventRepository method storeEvent.
@Override
@Transactional(dontRollbackOn = OptimisticLockingRetryException.class)
public void storeEvent(final JsonEnvelope envelope) throws StoreEventRequestFailedException {
try {
final Event event = eventConverter.eventOf(envelope);
logger.trace("Storing event {} into stream {} at position {}", event.getName(), event.getStreamId(), event.getSequenceId());
eventJdbcRepository.insert(event);
} catch (InvalidPositionException ex) {
throw new StoreEventRequestFailedException(String.format("Could not store event for position %d of stream %s", envelope.metadata().position().orElse(null), envelope.metadata().streamId().orElse(null)), ex);
}
}
use of uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event in project microservice_framework by CJSCommonPlatform.
the class DefaultEventRepositoryTest method shouldStoreEventEnvelope.
@Test
public void shouldStoreEventEnvelope() throws Exception {
final String name = "name123";
final Event event = new Event(null, STREAM_ID, POSITION, name, null, null, now());
when(eventConverter.eventOf(envelope)).thenReturn(event);
defaultEventRepository.storeEvent(envelope);
verify(eventJdbcRepository).insert(event);
verify(logger).trace("Storing event {} into stream {} at position {}", name, STREAM_ID, POSITION);
}
use of uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldSetDateCreatedTimestampInEventStore.
@Test
public void shouldSetDateCreatedTimestampInEventStore() {
final UUID orderId = randomUUID();
final Response commandResponse = sendTo(ORDERS_RESOURCE_URI + orderId.toString()).request().post(entity(jsonObject().add("recipeId", randomUUID().toString()).add("deliveryDate", "2016-01-21T23:42:03.522+07:00").build().toString(), ORDER_CAKE_MEDIA_TYPE));
assertThat(commandResponse.getStatus(), is(ACCEPTED));
await().until(() -> queryForOrder(orderId.toString()).httpCode() == OK);
final Stream<Event> events = EVENT_LOG_REPOSITORY.findByStreamIdOrderByPositionAsc(orderId);
final Event event = events.findFirst().get();
assertThat(event.getCreatedAt(), is(notNullValue()));
assertThat(event.getCreatedAt(), is(within(10L, SECONDS, new UtcClock().now())));
}
use of uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldRegisterRecipeAddedEvent.
@Test
public void shouldRegisterRecipeAddedEvent() {
final String recipeId = "163af847-effb-46a9-96bc-32a0f7526f99";
sendTo(RECIPES_RESOURCE_URI + recipeId).request().post(entity(jsonObject().add("name", "Vanilla cake").add("glutenFree", false).add("ingredients", createArrayBuilder().add(createObjectBuilder().add("name", "vanilla").add("quantity", 2)).build()).build().toString(), ADD_RECIPE_MEDIA_TYPE));
await().until(() -> eventsWithPayloadContaining(recipeId).size() == 1);
final Event event = eventsWithPayloadContaining(recipeId).get(0);
assertThat(event.getName(), is("example.recipe-added"));
with(event.getMetadata()).assertEquals("stream.id", recipeId).assertEquals("stream.version", 1);
final String eventPayload = event.getPayload();
with(eventPayload).assertThat("$.recipeId", equalTo(recipeId)).assertThat("$.name", equalTo("Vanilla cake")).assertThat("$.glutenFree", equalTo(false)).assertThat("$.ingredients[0].name", equalTo("vanilla")).assertThat("$.ingredients[0].quantity", equalTo(2));
}
Aggregations