Search in sources :

Example 26 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceIT method shouldThrowExceptionForUnregisteredEvent.

@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionForUnregisteredEvent() throws EventStreamException {
    final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
    eventStream.append(Stream.of(envelopeFrom("context.eventA")));
    aggregateService.get(eventStream, TestAggregate.class);
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Test(org.junit.Test)

Example 27 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceIT method shouldThrowExceptionForNonInstantiatableEvent.

@Test(expected = RuntimeException.class)
public void shouldThrowExceptionForNonInstantiatableEvent() throws EventStreamException {
    final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
    aggregateService.register(new EventFoundEvent(EventA.class, "eventA"));
    aggregateService.get(eventStream, PrivateAggregate.class);
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 28 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class RecipeCommandHandler method removeRecipe.

@Handles("example.command.remove-recipe")
public void removeRecipe(final JsonEnvelope command) throws EventStreamException {
    LOGGER.trace("=============> Inside remove-recipe Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
    final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
    final EventStream eventStream = eventSource.getStreamById(recipeId);
    final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
    eventStream.append(recipe.removeRecipe().map(toEnvelopeWithMetadataFrom(command)));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Aggregations

EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)28 Test (org.junit.Test)19 UUID (java.util.UUID)18 UUID.randomUUID (java.util.UUID.randomUUID)13 EnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream)10 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)9 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)7 ZonedDateTime (java.time.ZonedDateTime)5 Stream (java.util.stream.Stream)5 Handles (uk.gov.justice.services.core.annotation.Handles)5 SnapshotAwareEnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream)5 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)5 JsonObjects.getUUID (uk.gov.justice.services.messaging.JsonObjects.getUUID)5 JsonObject (javax.json.JsonObject)4 AggregateSnapshot (uk.gov.justice.domain.snapshot.AggregateSnapshot)3 EventA (uk.gov.justice.services.core.aggregate.event.EventA)3 EventFoundEvent (uk.gov.justice.services.core.extension.EventFoundEvent)3 MetadataBuilderFactory.metadataWithRandomUUID (uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID)3 DefaultObjectInputStreamStrategy (uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy)2 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)2