use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.
the class DefaultAggregateServiceIT method shouldCreateAggregateFromSingletonStream.
@Test
public void shouldCreateAggregateFromSingletonStream() throws EventStreamException {
final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
aggregateService.register(new EventFoundEvent(EventA.class, "context.eventA"));
aggregateService.get(eventStream, TestAggregate.class);
eventStream.append(Stream.of(envelopeFrom("context.eventA")));
final TestAggregate aggregate = aggregateService.get(eventSource.getStreamById(STREAM_ID), TestAggregate.class);
assertThat(aggregate, notNullValue());
assertThat(aggregate.recordedEvents(), hasSize(1));
assertThat(aggregate.recordedEvents().get(0).getClass(), equalTo(EventA.class));
assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
}
use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.
the class DefaultAggregateServiceIT method shouldCreateAggregateFromStreamOfTwo.
@Test
public void shouldCreateAggregateFromStreamOfTwo() throws EventStreamException {
final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
aggregateService.register(new EventFoundEvent(EventA.class, "context.eventA"));
aggregateService.register(new EventFoundEvent(EventB.class, "context.eventB"));
aggregateService.get(eventStream, TestAggregate.class);
eventStream.append(Stream.of(envelopeFrom("context.eventA"), envelopeFrom("context.eventB")));
final TestAggregate aggregate = aggregateService.get(eventSource.getStreamById(STREAM_ID), TestAggregate.class);
assertThat(aggregate, notNullValue());
assertThat(aggregate.recordedEvents(), hasSize(2));
assertThat(aggregate.recordedEvents().get(0).getClass(), equalTo(EventA.class));
assertThat(aggregate.recordedEvents().get(1).getClass(), equalTo(EventB.class));
assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, STREAM_ID), is(2));
assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
}
use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.
the class MakeCakeCommandHandler method makeCake.
@Handles("example.command.make-cake")
public void makeCake(final JsonEnvelope command) throws EventStreamException {
LOGGER.info("=============> Inside make-cake Command Handler");
final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
final UUID cakeId = getUUID(command.payloadAsJsonObject(), FIELD_CAKE_ID).get();
final EventStream eventStream = eventSource.getStreamById(recipeId);
final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
eventStream.append(recipe.makeCake(cakeId).map(toEnvelopeWithMetadataFrom(command)), Tolerance.CONSECUTIVE);
}
use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandler method uploadPhotograph.
@Handles("example.command.upload-photograph")
public void uploadPhotograph(final JsonEnvelope command) throws EventStreamException {
LOGGER.trace("=============> Inside upload-photograph Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
final UUID photoId = getUUID(command.payloadAsJsonObject(), FIELD_PHOTO_ID).get();
final EventStream eventStream = eventSource.getStreamById(recipeId);
final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
eventStream.append(recipe.addPhotograph(photoId).map(toEnvelopeWithMetadataFrom(command)), Tolerance.NON_CONSECUTIVE);
}
use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandler method renameRecipe.
@Handles("example.command.rename-recipe")
public void renameRecipe(final Envelope<RenameRecipe> command) throws EventStreamException {
LOGGER.trace("=============> Inside rename-recipe Command Handler");
final UUID recipeId = UUID.fromString(command.payload().getRecipeId());
final String name = command.payload().getName();
final EventStream eventStream = eventSource.getStreamById(recipeId);
final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
eventStream.append(recipe.renameRecipe(name).map(toEnvelopeWithMetadataFrom(command)), Tolerance.NON_CONSECUTIVE);
}
Aggregations