use of uk.gov.justice.services.messaging.MetadataBuilder in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonEnvelopeProviderTest method shouldProvideJsonObjectMetadataBuilder.
@Test
public void shouldProvideJsonObjectMetadataBuilder() throws Exception {
final MetadataBuilder metadataBuilder = new DefaultJsonEnvelopeProvider().metadataBuilder();
assertThat(metadataBuilder, instanceOf(DefaultJsonMetadata.Builder.class));
}
use of uk.gov.justice.services.messaging.MetadataBuilder in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonEnvelopeProviderTest method shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonValue.
@Test
public void shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonValue() throws Exception {
final UUID id = randomUUID();
final String name = "name";
final MetadataBuilder metadataBuilder = metadataBuilder().withId(id).withName(name);
final JsonValue payload = mock(JsonValue.class);
final JsonEnvelope envelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadataBuilder, payload);
assertThat(envelope, instanceOf(DefaultJsonEnvelope.class));
final Metadata metadata = envelope.metadata();
assertThat(metadata.id(), is(id));
assertThat(metadata.name(), is(name));
assertThat(envelope.payload(), is(payload));
}
use of uk.gov.justice.services.messaging.MetadataBuilder in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonEnvelopeProviderTest method shouldProvideJsonObjectMetadataBuilderFromJsonObject.
@Test
public void shouldProvideJsonObjectMetadataBuilderFromJsonObject() throws Exception {
final UUID id = randomUUID();
final String name = "name";
final Metadata metadata = metadataBuilder().withId(id).withName(name).build();
final MetadataBuilder metadataBuilder = new DefaultJsonEnvelopeProvider().metadataFrom(metadata.asJsonObject());
assertThat(metadataBuilder, instanceOf(DefaultJsonMetadata.Builder.class));
final Metadata resultMetadata = metadataBuilder.build();
assertThat(resultMetadata.id(), is(id));
assertThat(resultMetadata.name(), is(name));
}
use of uk.gov.justice.services.messaging.MetadataBuilder in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeBuilderTest method shouldBuildJsonEnvelopeContainingMetadataAndPayloadFromJsonEnvelope.
@Test
public void shouldBuildJsonEnvelopeContainingMetadataAndPayloadFromJsonEnvelope() throws Exception {
final UUID id = randomUUID();
final String name = "name";
final MetadataBuilder metadata = metadataBuilder().withId(id).withName(name);
final JsonObjectBuilder payload = createObjectBuilder().add("test", "value");
final JsonEnvelope envelope = new JsonEnvelopeBuilder(JsonEnvelope.envelopeFrom(metadata, payload)).build();
assertThat(envelope, jsonEnvelope(metadata().withId(id).withName(name), payloadIsJson(withJsonPath("$.test", equalTo("value")))));
}
use of uk.gov.justice.services.messaging.MetadataBuilder in project microservice_framework by CJSCommonPlatform.
the class RestEnvelopeBuilder method buildMetadata.
private Metadata buildMetadata() {
final Optional<Metadata> payloadMetadata = metadataFromPayloadIfPresent();
final MetadataBuilder metadataBuilder = payloadMetadata.map(JsonEnvelope::metadataFrom).orElse(JsonEnvelope.metadataBuilder().withId(id).withName(this.action));
return mergeHeadersIntoMetadata(payloadMetadata, metadataBuilder).build();
}
Aggregations