Search in sources :

Example 86 with JsonEnvelope

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

the class RestClientProcessorIT method shouldReturnJsonNullPayloadFor404ResponseCode.

@Test
public void shouldReturnJsonNullPayloadFor404ResponseCode() throws Exception {
    final String path = "/my/resource";
    final String mimetype = format("application/vnd.%s+json", QUERY_NAME);
    stubFor(get(urlEqualTo(path)).withHeader(ACCEPT, equalTo(mimetype)).withHeader(CLIENT_CORRELATION_ID, equalTo(CLIENT_CORRELATION_ID_VALUE)).withHeader(USER_ID, equalTo(USER_ID_VALUE)).withHeader(SESSION_ID, equalTo(SESSION_ID_VALUE)).willReturn(aResponse().withStatus(404).withHeader(CONTENT_TYPE, mimetype).withBody(responseWithMetadata())));
    EndpointDefinition endpointDefinition = new EndpointDefinition(BASE_URI, path, emptySet(), emptySet(), QUERY_NAME);
    JsonEnvelope response = restClientProcessor.get(endpointDefinition, requestEnvelopeParamAParamB());
    assertThat(response, notNullValue());
    assertThat(response.payload(), is(NULL));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 87 with JsonEnvelope

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

the class EventBufferIT method shouldAddEventToBufferIfVersionNotOne.

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

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

    */
@Test
public void shouldAddEventToBufferIfVersionNotOne() {
    final UUID metadataId = randomUUID();
    final UUID streamId = randomUUID();
    final JsonEnvelope envelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(2L)).build();
    interceptorChainProcessor.process(interceptorContextWithInput(envelope));
    final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
    assertThat(streamBufferEvents, hasSize(1));
    assertThat(streamBufferEvents.get(0).getStreamId(), is(streamId));
    assertThat(streamBufferEvents.get(0).getVersion(), is(2L));
    assertThat(streamBufferEvents.get(0).getSource(), is(SOURCE));
    final List<JsonEnvelope> handledEnvelopes = abcEventHandler.recordedEnvelopes();
    assertThat(handledEnvelopes, empty());
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 88 with JsonEnvelope

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

the class EventBufferIT method shouldReleaseBufferWhenMissingEventArrives.

@Test
public void shouldReleaseBufferWhenMissingEventArrives() throws SQLException, NamingException {
    final UUID metadataId2 = randomUUID();
    final UUID streamId = randomUUID();
    final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId2, EVENT_ABC).withStreamId(streamId).withVersion(2L)).build();
    statusRepository.insert(new StreamStatus(streamId, 1L, SOURCE));
    final UUID metadataId3 = randomUUID();
    final UUID metadataId4 = randomUUID();
    final UUID metadataId5 = randomUUID();
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 3L, envelope().with(metadataOf(metadataId3, EVENT_ABC).withStreamId(streamId).withVersion(3L)).toJsonString(), SOURCE));
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 4L, envelope().with(metadataOf(metadataId4, EVENT_ABC).withStreamId(streamId).withVersion(4L)).toJsonString(), SOURCE));
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 5L, envelope().with(metadataOf(metadataId5, EVENT_ABC).withStreamId(streamId).withVersion(5L)).toJsonString(), SOURCE));
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
    final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
    final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
    assertThat(streamStatus.isPresent(), is(true));
    assertThat(streamStatus.get().getVersion(), is(5L));
    final List<JsonEnvelope> handledEnvelopes = abcEventHandler.recordedEnvelopes();
    assertThat(handledEnvelopes, hasSize(4));
    assertThat(handledEnvelopes.get(0).metadata().id(), is(metadataId2));
    assertThat(handledEnvelopes.get(0).metadata().version(), contains(2L));
    assertThat(handledEnvelopes.get(1).metadata().id(), is(metadataId3));
    assertThat(handledEnvelopes.get(1).metadata().version(), contains(3L));
    assertThat(handledEnvelopes.get(2).metadata().id(), is(metadataId4));
    assertThat(handledEnvelopes.get(2).metadata().version(), contains(4L));
    assertThat(handledEnvelopes.get(3).metadata().id(), is(metadataId5));
    assertThat(handledEnvelopes.get(3).metadata().version(), contains(5L));
    assertThat(streamBufferEvents, hasSize(0));
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 89 with JsonEnvelope

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

the class EventBufferIT method shouldIgnoreEventWithSupersededVersion.

@Test
public void shouldIgnoreEventWithSupersededVersion() throws SQLException, NamingException {
    final UUID metadataId = randomUUID();
    final UUID streamId = randomUUID();
    final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(1L)).build();
    final StreamBufferEvent streamBufferEvent2 = new StreamBufferEvent(streamId, 4L, "payload", SOURCE);
    final StreamBufferEvent streamBufferEvent3 = new StreamBufferEvent(streamId, 5L, "payload", SOURCE);
    statusRepository.insert(new StreamStatus(streamId, 2L, SOURCE));
    jdbcStreamBufferRepository.insert(streamBufferEvent2);
    jdbcStreamBufferRepository.insert(streamBufferEvent3);
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
    final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
    final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
    assertThat(streamBufferEvents, hasSize(2));
    assertThat(streamStatus.isPresent(), is(true));
    assertThat(streamStatus.get().getVersion(), is(2L));
    assertThat(abcEventHandler.recordedEnvelopes(), empty());
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 90 with JsonEnvelope

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

the class DefaultJsonEnvelopeTest method shouldReturnEnvelopeAsJsonObject.

@Test
public void shouldReturnEnvelopeAsJsonObject() {
    final String metadataName = "metadata name";
    final UUID metadataId = randomUUID();
    final String payloadName = "payloadName";
    final String payloadValue = "payloadValue";
    final JsonEnvelope jsonEnvelope = envelopeFrom(metadata(metadataId, metadataName), payload(payloadName, payloadValue));
    final JsonObject jsonObject = jsonEnvelope.asJsonObject();
    with(jsonObject.toString()).assertEquals("_metadata.id", metadataId.toString()).assertEquals("_metadata.name", metadataName).assertEquals("$.payloadName", payloadValue);
}
Also used : JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) JsonString(javax.json.JsonString) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

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