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");
}
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));
}
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"))))));
}
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")))));
}
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");
}
Aggregations