Search in sources :

Example 1 with MetadataBuilder

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

the class DefaultJsonEnvelopeProviderTest method shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonObjectBuilder.

@Test
public void shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonObjectBuilder() throws Exception {
    final UUID id = randomUUID();
    final String name = "name";
    final MetadataBuilder metadataBuilder = metadataBuilder().withId(id).withName(name);
    final JsonObjectBuilder jsonObjectBuilder = createObjectBuilder().add("test", "value");
    final JsonEnvelope envelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadataBuilder, jsonObjectBuilder);
    assertThat(envelope, instanceOf(DefaultJsonEnvelope.class));
    final Metadata metadata = envelope.metadata();
    assertThat(metadata.id(), is(id));
    assertThat(metadata.name(), is(name));
    with(envelope.payload().toString()).assertEquals("test", "value");
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) Metadata(uk.gov.justice.services.messaging.Metadata) 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 2 with MetadataBuilder

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

the class DefaultJsonEnvelopeProviderTest method shouldProvideJsonObjectMetadataBuilderFromMetadata.

@Test
public void shouldProvideJsonObjectMetadataBuilderFromMetadata() 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);
    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 3 with MetadataBuilder

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

the class JsonEnvelopeBuilderTest method shouldBuildComplexEnvelopePayload.

@Test
@SuppressWarnings("unchecked")
public void shouldBuildComplexEnvelopePayload() {
    final String metadataName = "metadata name";
    final UUID metadataId = randomUUID();
    final MetadataBuilder metadata = metadataOf(metadataId, metadataName);
    final UUID testId = randomUUID();
    final JsonEnvelope jsonEnvelope = JsonEnvelopeBuilder.envelope().with(metadata).withPayloadOf(1, "int").withPayloadOf(Boolean.FALSE, "bool").withPayloadOf("String", "string").withPayloadOf(ONE, "bigd").withPayloadOf(testId, "uuid").withPayloadOf(new String[] { "value1", "value2", "value3" }, "arrayProperty").withPayloadOf(createObjectBuilder().add("someData", "data").build(), "jsonObject").build();
    assertThat(jsonEnvelope, jsonEnvelope(metadata().withId(metadataId).withName(metadataName), payloadIsJson(allOf(withJsonPath("$.int", equalTo(1)), withJsonPath("$.bool", equalTo(false)), withJsonPath("$.string", equalTo("String")), withJsonPath("$.bigd", equalTo(1)), withJsonPath("$.uuid", equalTo(testId.toString())), withJsonPath("$.arrayProperty", hasItems("value1", "value2", "value3")), withJsonPath("$.jsonObject.someData", equalTo("data"))))));
}
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) Test(org.junit.Test)

Example 4 with MetadataBuilder

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

the class JsonEnvelopeBuilderTest method shouldBuildJsonEnvelopeContainingPayloadFromJsonEnvelope.

@Test
public void shouldBuildJsonEnvelopeContainingPayloadFromJsonEnvelope() 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 = JsonEnvelopeBuilder.envelope().withPayloadFrom(JsonEnvelope.envelopeFrom(metadata, payload)).build();
    assertThat(envelope.metadata(), nullValue());
    assertThat(envelope, jsonEnvelope().withPayloadOf(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 5 with MetadataBuilder

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

the class JsonEnvelopeBuilderTest method shouldBuildAsJsonString.

@Test
public void shouldBuildAsJsonString() {
    final String metadataName = "metadata name";
    final UUID metadataId = randomUUID();
    final MetadataBuilder metadata = metadataOf(metadataId, metadataName);
    final UUID testId = randomUUID();
    final String jsonEnvelope = JsonEnvelopeBuilder.envelope().with(metadata).withPayloadOf(1, "int").withPayloadOf(Boolean.FALSE, "bool").withPayloadOf("String", "string").withPayloadOf(ONE, "bigd").withPayloadOf(testId, "uuid").withPayloadOf(new String[] { "value1", "value2", "value3" }, "arrayProperty").withPayloadOf(createObjectBuilder().add("someData", "data").build(), "jsonObject").toJsonString();
    with(jsonEnvelope).assertEquals("_metadata.id", metadataId.toString()).assertEquals("_metadata.name", metadataName).assertEquals("$.int", 1).assertEquals("$.bool", false).assertEquals("$.string", "String").assertEquals("$.bigd", 1).assertEquals("$.uuid", testId.toString()).assertThat("arrayProperty", hasItems("value1", "value2", "value3")).assertNotNull("$.jsonObject");
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

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