use of uk.gov.justice.services.messaging.Metadata in project microservice_framework by CJSCommonPlatform.
the class RestEnvelopeBuilder method payload.
private JsonObject payload() {
final JsonObjectBuilder payloadBuilder = initialPayload.map(jsonObject -> createObjectBuilderWithFilter(jsonObject, key -> !key.equals(METADATA))).orElse(Json.createObjectBuilder());
params.ifPresent(parameters -> parameters.forEach(param -> {
switch(param.getType()) {
case NUMERIC:
payloadBuilder.add(param.getName(), param.getNumericValue());
break;
case BOOLEAN:
payloadBuilder.add(param.getName(), param.getBooleanValue());
break;
default:
payloadBuilder.add(param.getName(), param.getStringValue());
}
}));
return payloadBuilder.build();
}
use of uk.gov.justice.services.messaging.Metadata in project microservice_framework by CJSCommonPlatform.
the class RestEnvelopeBuilderTest method shouldNotFailIfSessionIdIsSetInBothHeaderAndPayloadAndAreEqual.
@Test
public void shouldNotFailIfSessionIdIsSetInBothHeaderAndPayloadAndAreEqual() throws Exception {
final Optional<JsonObject> initialPayload = Optional.of(createObjectBuilder().add(METADATA, createObjectBuilder().add(ID, randomUUID().toString()).add(NAME, PAYLOAD_NAME).add(CONTEXT, createObjectBuilder().add(SESSION_ID, UUID_SESSION_ID.toString()))).build());
final JsonEnvelope envelope = builderWithDefaultAction().withInitialPayload(initialPayload).withHeaders(httpHeadersOf(ImmutableMap.of(HeaderConstants.SESSION_ID, UUID_SESSION_ID.toString()))).build();
final Metadata metadata = envelope.metadata();
assertThat(metadata.sessionId(), is(Optional.of(UUID_SESSION_ID.toString())));
}
use of uk.gov.justice.services.messaging.Metadata in project microservice_framework by CJSCommonPlatform.
the class RestEnvelopeBuilderTest method shouldNotFailIfUserIdIsSetInBothHeaderAndPayloadAndAreEqual.
@Test
public void shouldNotFailIfUserIdIsSetInBothHeaderAndPayloadAndAreEqual() throws Exception {
final Optional<JsonObject> initialPayload = Optional.of(createObjectBuilder().add(METADATA, createObjectBuilder().add(ID, randomUUID().toString()).add(NAME, PAYLOAD_NAME).add(CONTEXT, createObjectBuilder().add(USER_ID, UUID_USER_ID.toString()))).build());
final JsonEnvelope envelope = builderWithDefaultAction().withInitialPayload(initialPayload).withHeaders(httpHeadersOf(ImmutableMap.of(HeaderConstants.USER_ID, UUID_USER_ID.toString()))).build();
final Metadata metadata = envelope.metadata();
assertThat(metadata.userId(), is(Optional.of(UUID_USER_ID.toString())));
}
use of uk.gov.justice.services.messaging.Metadata in project microservice_framework by CJSCommonPlatform.
the class RestEnvelopeBuilderTest method shouldRemoveMetadataFromPayloadAndAddToMetadataOfEnvelope.
@Test
public void shouldRemoveMetadataFromPayloadAndAddToMetadataOfEnvelope() throws Exception {
final String payloadCausationId = randomUUID().toString();
final Optional<JsonObject> initialPayload = Optional.of(createObjectBuilder().add(METADATA, createObjectBuilder().add(ID, PAYLOAD_METADATA_ID.toString()).add(NAME, PAYLOAD_NAME).add(CONTEXT, createObjectBuilder().add(SESSION_ID, UUID_SESSION_ID.toString()).add(USER_ID, UUID_USER_ID.toString())).add(CAUSATION, createArrayBuilder().add(payloadCausationId)).add(CORRELATION, createObjectBuilder().add(CLIENT_ID, UUID_CLIENT_CORRELATION_ID.toString())).add(STREAM, createObjectBuilder().add(STREAM_ID, UUID_STREAM_ID.toString()).add(VERSION, VERSION_VALUE))).add("test", "value").build());
final JsonEnvelope envelope = builderWithDefaultAction().withInitialPayload(initialPayload).build();
final JsonObject payload = envelope.payloadAsJsonObject();
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).toString(), is(payloadCausationId));
assertThat(getString(payload, METADATA, ID), is(Optional.empty()));
assertThat(getString(payload, METADATA, NAME), is(Optional.empty()));
assertThat(getJsonObject(payload, METADATA, CONTEXT), is(Optional.empty()));
assertThat(getJsonObject(payload, METADATA, CORRELATION), is(Optional.empty()));
assertThat(getJsonObject(payload, METADATA, STREAM), is(Optional.empty()));
assertThat(getString(payload, "test"), is(Optional.of("value")));
}
use of uk.gov.justice.services.messaging.Metadata in project microservice_framework by CJSCommonPlatform.
the class EnvelopeInspectorTest method shouldGetTheMetadataOfAnEnvelope.
@Test
public void shouldGetTheMetadataOfAnEnvelope() throws Exception {
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final Metadata metadata = mock(Metadata.class);
when(jsonEnvelope.metadata()).thenReturn(metadata);
assertThat(envelopeInspector.getMetadataFor(jsonEnvelope), is(metadata));
}
Aggregations