Search in sources :

Example 1 with EventA

use of uk.gov.justice.services.core.aggregate.event.EventA in project microservice_framework by CJSCommonPlatform.

the class TestAggregate method addEvent.

public Stream<Object> addEvent(JsonEnvelope envelope) {
    JsonObject object = envelope.payloadAsJsonObject();
    String value = object.getString("name");
    return apply(Stream.of(new EventA(value)));
}
Also used : JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA)

Example 2 with EventA

use of uk.gov.justice.services.core.aggregate.event.EventA in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceTest method shouldCreateAggregateFromStreamOfThreeWithAFilteredOutSystemEvent.

@Test
public void shouldCreateAggregateFromStreamOfThreeWithAFilteredOutSystemEvent() {
    JsonObject eventPayloadA = mock(JsonObject.class);
    JsonObject eventPayloadB = mock(JsonObject.class);
    EventA eventA = mock(EventA.class);
    EventB eventB = mock(EventB.class);
    when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
    when(jsonObjectToObjectConverter.convert(eventPayloadB, EventB.class)).thenReturn(eventB);
    when(eventStream.read()).thenReturn(Stream.of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA), envelopeFrom(metadataWithRandomUUID("eventB"), eventPayloadB), envelopeFrom(metadataWithRandomUUID("system.events.eventC"), eventPayloadB)));
    when(eventStream.getId()).thenReturn(STREAM_ID);
    aggregateService.register(new EventFoundEvent(EventA.class, "eventA"));
    aggregateService.register(new EventFoundEvent(EventB.class, "eventB"));
    TestAggregate aggregate = aggregateService.get(eventStream, TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(2));
    assertThat(aggregate.recordedEvents().get(0), equalTo(eventA));
    assertThat(aggregate.recordedEvents().get(1), equalTo(eventB));
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventA", EventA.class);
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventB", EventB.class);
    verify(logger).trace("Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
}
Also used : EventB(uk.gov.justice.services.core.aggregate.event.EventB) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 3 with EventA

use of uk.gov.justice.services.core.aggregate.event.EventA in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceTest method shouldCreateAggregateFromSingletonStream.

@Test
public void shouldCreateAggregateFromSingletonStream() {
    JsonObject eventPayloadA = mock(JsonObject.class);
    EventA eventA = mock(EventA.class);
    when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
    when(eventStream.read()).thenReturn(Stream.of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA)));
    when(eventStream.getId()).thenReturn(STREAM_ID);
    registerEvent(EventA.class, "eventA");
    TestAggregate aggregate = aggregateService.get(eventStream, TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(1));
    assertThat(aggregate.recordedEvents().get(0), equalTo(eventA));
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventA", EventA.class);
    verify(logger).trace("Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
}
Also used : TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 4 with EventA

use of uk.gov.justice.services.core.aggregate.event.EventA in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceTest method shouldCreateAggregateFromStreamOfTwo.

@Test
public void shouldCreateAggregateFromStreamOfTwo() {
    JsonObject eventPayloadA = mock(JsonObject.class);
    JsonObject eventPayloadB = mock(JsonObject.class);
    EventA eventA = mock(EventA.class);
    EventB eventB = mock(EventB.class);
    when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
    when(jsonObjectToObjectConverter.convert(eventPayloadB, EventB.class)).thenReturn(eventB);
    when(eventStream.read()).thenReturn(Stream.of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA), envelopeFrom(metadataWithRandomUUID("eventB"), eventPayloadB)));
    when(eventStream.getId()).thenReturn(STREAM_ID);
    registerEvent(EventA.class, "eventA");
    registerEvent(EventB.class, "eventB");
    TestAggregate aggregate = aggregateService.get(eventStream, TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(2));
    assertThat(aggregate.recordedEvents().get(0), equalTo(eventA));
    assertThat(aggregate.recordedEvents().get(1), equalTo(eventB));
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventA", EventA.class);
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventB", EventB.class);
    verify(logger).trace("Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
}
Also used : EventB(uk.gov.justice.services.core.aggregate.event.EventB) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 5 with EventA

use of uk.gov.justice.services.core.aggregate.event.EventA in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceTest method shouldThrowExceptionForNonInstantiatableEvent.

@Test(expected = RuntimeException.class)
public void shouldThrowExceptionForNonInstantiatableEvent() {
    JsonObject eventPayloadA = mock(JsonObject.class);
    EventA eventA = mock(EventA.class);
    when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
    when(eventStream.read()).thenReturn(Stream.of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA)));
    registerEvent(EventA.class, "eventA");
    aggregateService.get(eventStream, PrivateAggregate.class);
}
Also used : JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Aggregations

EventA (uk.gov.justice.services.core.aggregate.event.EventA)7 JsonObject (javax.json.JsonObject)6 Test (org.junit.Test)6 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)3 EventB (uk.gov.justice.services.core.aggregate.event.EventB)2 EventFoundEvent (uk.gov.justice.services.core.extension.EventFoundEvent)2 EnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream)1 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)1