use of uk.gov.justice.services.messaging.JsonEnvelope 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.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonEnvelopeProviderTest method shouldProvideDefaultJsonEnvelopeFromMetadataAndJsonValue.
@Test
public void shouldProvideDefaultJsonEnvelopeFromMetadataAndJsonValue() throws Exception {
final Metadata metadata = mock(Metadata.class);
final JsonValue payload = mock(JsonValue.class);
final JsonEnvelope envelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadata, payload);
assertThat(envelope, instanceOf(DefaultJsonEnvelope.class));
assertThat(envelope.metadata(), is(metadata));
assertThat(envelope.payload(), is(payload));
}
use of uk.gov.justice.services.messaging.JsonEnvelope 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.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeBuilderTest method shouldBuildJsonEnvelopeFromDeprecatedMetadataBuilderAndJsonObjectBuilder.
@Test
public void shouldBuildJsonEnvelopeFromDeprecatedMetadataBuilderAndJsonObjectBuilder() throws Exception {
final UUID id = randomUUID();
final String name = "name";
final JsonObjectMetadata.Builder metadataBuilder = JsonObjectMetadata.metadataOf(id, name);
final JsonObjectBuilder jsonObjectBuilder = createObjectBuilder().add("test", "value");
final JsonEnvelope envelope = JsonEnvelopeBuilder.envelopeFrom(metadataBuilder, jsonObjectBuilder);
assertThat(envelope, jsonEnvelope(metadata().withId(id).withName(name), payloadIsJson(withJsonPath("$.test", equalTo("value")))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeBuilderTest method shouldBuildJsonEnvelopeFromMetadataAndJsonValue.
@Test
public void shouldBuildJsonEnvelopeFromMetadataAndJsonValue() throws Exception {
final Metadata metadata = mock(Metadata.class);
final JsonValue payload = mock(JsonValue.class);
final JsonEnvelope envelope = JsonEnvelopeBuilder.envelopeFrom(metadata, payload);
assertThat(envelope.metadata(), is(metadata));
assertThat(envelope.payload(), is(payload));
}
Aggregations