Search in sources :

Example 6 with MetadataBuilder

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));
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) JsonEnvelope.metadataBuilder(uk.gov.justice.services.messaging.JsonEnvelope.metadataBuilder) MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) Json.createObjectBuilder(javax.json.Json.createObjectBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Test(org.junit.Test)

Example 7 with MetadataBuilder

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));
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) JsonValue(javax.json.JsonValue) Metadata(uk.gov.justice.services.messaging.Metadata) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 8 with MetadataBuilder

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));
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) JsonEnvelope.metadataBuilder(uk.gov.justice.services.messaging.JsonEnvelope.metadataBuilder) MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) Json.createObjectBuilder(javax.json.Json.createObjectBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Metadata(uk.gov.justice.services.messaging.Metadata) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 9 with MetadataBuilder

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")))));
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) JsonObjectBuilder(javax.json.JsonObjectBuilder) Test(org.junit.Test)

Example 10 with MetadataBuilder

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();
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) Metadata(uk.gov.justice.services.messaging.Metadata)

Aggregations

MetadataBuilder (uk.gov.justice.services.messaging.MetadataBuilder)10 Test (org.junit.Test)9 UUID (java.util.UUID)8 UUID.randomUUID (java.util.UUID.randomUUID)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)6 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)5 Metadata (uk.gov.justice.services.messaging.Metadata)5 Json.createObjectBuilder (javax.json.Json.createObjectBuilder)3 JsonEnvelope.metadataBuilder (uk.gov.justice.services.messaging.JsonEnvelope.metadataBuilder)3 JsonValue (javax.json.JsonValue)1