Search in sources :

Example 66 with Metadata

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

the class RestEnvelopeBuilderTest method shouldMergeHeaderWithPayloadMetadataWithMultipleCausation.

@Test
public void shouldMergeHeaderWithPayloadMetadataWithMultipleCausation() throws Exception {
    final List<UUID> uuids = asList(randomUUID(), randomUUID());
    final String uuidsCsv = String.join(",", uuids.stream().map(UUID::toString).collect(toList()));
    final Optional<JsonObject> initialPayload = Optional.of(createObjectBuilder().add(METADATA, createObjectBuilder().add(ID, PAYLOAD_METADATA_ID.toString()).add(NAME, PAYLOAD_NAME).add(STREAM, createObjectBuilder().add(STREAM_ID, UUID_STREAM_ID.toString()).add(VERSION, VERSION_VALUE))).add("test", "value").build());
    final JsonEnvelope envelope = builderWithDefaultAction().withInitialPayload(initialPayload).withHeaders(httpHeadersOf(ImmutableMap.of(CLIENT_CORRELATION_ID, UUID_CLIENT_CORRELATION_ID.toString(), HeaderConstants.USER_ID, UUID_USER_ID.toString(), HeaderConstants.SESSION_ID, UUID_SESSION_ID.toString(), HeaderConstants.CAUSATION, uuidsCsv))).build();
    final Metadata metadata = envelope.metadata();
    assertThat(metadata.id(), is(PAYLOAD_METADATA_ID));
    assertThat(metadata.name(), is(PAYLOAD_NAME));
    assertThat(metadata.sessionId(), is(Optional.of(UUID_SESSION_ID.toString())));
    assertThat(metadata.userId(), is(Optional.of(UUID_USER_ID.toString())));
    assertThat(metadata.clientCorrelationId(), is(Optional.of(UUID_CLIENT_CORRELATION_ID.toString())));
    assertThat(metadata.streamId(), is(Optional.of(UUID_STREAM_ID)));
    assertThat(metadata.version(), is(Optional.of(VERSION_VALUE)));
    assertThat(metadata.causation(), is(uuids));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) JsonObject(javax.json.JsonObject) JsonObjects.getJsonObject(uk.gov.justice.services.messaging.JsonObjects.getJsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) JsonObjects.getString(uk.gov.justice.services.messaging.JsonObjects.getString) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 67 with Metadata

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

the class RestEnvelopeBuilderTest method shouldMergeHeaderWithPayloadMetadata.

@Test
public void shouldMergeHeaderWithPayloadMetadata() throws Exception {
    final Optional<JsonObject> initialPayload = Optional.of(createObjectBuilder().add(METADATA, createObjectBuilder().add(ID, PAYLOAD_METADATA_ID.toString()).add(NAME, PAYLOAD_NAME).add(STREAM, createObjectBuilder().add(STREAM_ID, UUID_STREAM_ID.toString()).add(VERSION, VERSION_VALUE))).add("test", "value").build());
    final JsonEnvelope envelope = builderWithDefaultAction().withInitialPayload(initialPayload).withHeaders(httpHeadersOf(ImmutableMap.of(CLIENT_CORRELATION_ID, UUID_CLIENT_CORRELATION_ID.toString(), HeaderConstants.USER_ID, UUID_USER_ID.toString(), HeaderConstants.SESSION_ID, UUID_SESSION_ID.toString(), HeaderConstants.CAUSATION, SINGLE_CAUSATION_ID.toString()))).build();
    final Metadata metadata = envelope.metadata();
    assertThat(metadata.id(), is(PAYLOAD_METADATA_ID));
    assertThat(metadata.name(), is(PAYLOAD_NAME));
    assertThat(metadata.sessionId(), is(Optional.of(UUID_SESSION_ID.toString())));
    assertThat(metadata.userId(), is(Optional.of(UUID_USER_ID.toString())));
    assertThat(metadata.clientCorrelationId(), is(Optional.of(UUID_CLIENT_CORRELATION_ID.toString())));
    assertThat(metadata.streamId(), is(Optional.of(UUID_STREAM_ID)));
    assertThat(metadata.version(), is(Optional.of(VERSION_VALUE)));
    assertThat(metadata.causation().get(0), is(SINGLE_CAUSATION_ID));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) JsonObject(javax.json.JsonObject) JsonObjects.getJsonObject(uk.gov.justice.services.messaging.JsonObjects.getJsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Aggregations

Metadata (uk.gov.justice.services.messaging.Metadata)67 Test (org.junit.Test)58 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)19 UUID (java.util.UUID)17 UUID.randomUUID (java.util.UUID.randomUUID)11 JsonObject (javax.json.JsonObject)10 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)8 MetadataBuilder (uk.gov.justice.services.messaging.MetadataBuilder)6 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 JsonValue (javax.json.JsonValue)3 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)3 Json.createObjectBuilder (javax.json.Json.createObjectBuilder)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 UtcClock (uk.gov.justice.services.common.util.UtcClock)2 Interceptor (uk.gov.justice.services.core.interceptor.Interceptor)2 InterceptorChain (uk.gov.justice.services.core.interceptor.InterceptorChain)2 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)2 JsonEnvelope.metadataBuilder (uk.gov.justice.services.messaging.JsonEnvelope.metadataBuilder)2 EqualsTester (com.google.common.testing.EqualsTester)1 String.format (java.lang.String.format)1