Search in sources :

Example 91 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventBufferAndFilterChainIT method shouldAllowUnsupportedEventThroughBufferAndFilterOutAfterwards.

// Uncomment below to test when deplpoyed to the vagrant vm
/*

    @Configuration
    public Properties postgresqlConfiguration() {
        return OpenEjbConfigurationBuilder.createOpenEjbConfigurationBuilder()
                .addInitialContext()
                .addPostgresqlViewStore()
                .build();
    }

    */
@Test
public void shouldAllowUnsupportedEventThroughBufferAndFilterOutAfterwards() {
    final UUID metadataId1 = randomUUID();
    final UUID metadataId2 = randomUUID();
    final UUID metadataId3 = randomUUID();
    final UUID streamId = randomUUID();
    final JsonEnvelope jsonEnvelope_1 = envelope().with(metadataOf(metadataId2, EVENT_UNSUPPORTED_DEF).withStreamId(streamId).withVersion(2L)).build();
    final JsonEnvelope jsonEnvelope_2 = envelope().with(metadataOf(metadataId3, EVENT_SUPPORTED_ABC).withStreamId(streamId).withVersion(3L)).build();
    final JsonEnvelope jsonEnvelope_3 = envelope().with(metadataOf(metadataId1, EVENT_SUPPORTED_ABC).withStreamId(streamId).withVersion(1L)).build();
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope_1));
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope_2));
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope_3));
    assertThat(abcEventHandler.recordedEnvelopes(), not(empty()));
    assertThat(abcEventHandler.recordedEnvelopes().get(0).metadata().id(), equalTo(metadataId1));
    assertThat(abcEventHandler.recordedEnvelopes().get(0).metadata().version(), contains(1L));
    assertThat(abcEventHandler.recordedEnvelopes().get(1).metadata().id(), equalTo(metadataId3));
    assertThat(abcEventHandler.recordedEnvelopes().get(1).metadata().version(), contains(3L));
    assertThat(defEventHandler.recordedEnvelopes(), empty());
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 92 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class JsonSchemaValidationMatcherTest method shouldFailToValidateJsonEnvelopeAgainstSchemaForActionNameOfEnvelope.

@Test(expected = AssertionError.class)
public void shouldFailToValidateJsonEnvelopeAgainstSchemaForActionNameOfEnvelope() throws Exception {
    final JsonEnvelope jsonEnvelope = envelope().with(metadataWithRandomUUID("event.action")).withPayloadOf("id", "someId").build();
    assertThat(jsonEnvelope, JsonSchemaValidationMatcher.isValidJsonEnvelopeForSchema());
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 93 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class JsonSchemaValidationMatcherTest method shouldFallbackToRamlPathIfNotFoundInJsonPath.

@Test
public void shouldFallbackToRamlPathIfNotFoundInJsonPath() throws Exception {
    final JsonEnvelope jsonEnvelope = envelope().with(metadataWithRandomUUID("fallback.action")).withPayloadOf("id", "fallback").build();
    assertThat(jsonEnvelope, JsonSchemaValidationMatcher.isValidJsonEnvelopeForSchema());
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 94 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class SnapshotAwareAggregateServiceIT method createEventStreamAndApply.

private <T extends Aggregate> void createEventStreamAndApply(final UUID streamId, final long count, final String eventName, final Class<T> aggregateClass) throws EventStreamException {
    final EventStream eventStream = eventSource.getStreamById(streamId);
    final T aggregate = aggregateService.get(eventStream, aggregateClass);
    final List<JsonEnvelope> envelopes = new LinkedList<>();
    for (int i = 1; i <= count; i++) {
        final JsonEnvelope envelope = envelope().with(metadataWithRandomUUID(eventName).createdAt(clock.now()).withStreamId(streamId)).withPayloadOf("value", "name").build();
        aggregate.apply(new EventA(String.valueOf(i)));
        envelopes.add(envelope);
    }
    eventStream.append(envelopes.stream());
}
Also used : SnapshotAwareEnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) EventA(uk.gov.justice.domain.event.EventA) LinkedList(java.util.LinkedList)

Example 95 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class SnapshotAwareAggregateServiceIT method createEventAndApply.

private Stream<JsonEnvelope> createEventAndApply(final UUID streamId, final long count, final TestAggregate aggregate) {
    final List<JsonEnvelope> envelopes = new LinkedList<>();
    for (int i = 1; i <= count; i++) {
        final JsonEnvelope envelope = envelope().with(metadataWithRandomUUID("context.eventA").createdAt(clock.now()).withStreamId(streamId)).withPayloadOf("value", "name").build();
        aggregate.addEvent(envelope);
        envelopes.add(envelope);
    }
    return envelopes.stream();
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) LinkedList(java.util.LinkedList)

Aggregations

JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)276 Test (org.junit.Test)249 UUID (java.util.UUID)69 UUID.randomUUID (java.util.UUID.randomUUID)64 JsonObject (javax.json.JsonObject)30 JsonValue (javax.json.JsonValue)26 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)24 Metadata (uk.gov.justice.services.messaging.Metadata)18 Method (java.lang.reflect.Method)17 Function (java.util.function.Function)14 StreamBufferEvent (uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent)10 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)9 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)9 EndpointDefinition (uk.gov.justice.services.clients.core.EndpointDefinition)8 MediaType (uk.gov.justice.services.core.mapping.MediaType)8 StreamStatus (uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus)7 ZonedDateTime (java.time.ZonedDateTime)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 HttpHeaders (javax.ws.rs.core.HttpHeaders)6