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));
}
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());
}
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));
}
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());
}
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);
}
Aggregations