Search in sources :

Example 1 with JsonEnvelope

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

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

Example 3 with JsonEnvelope

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

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

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

Aggregations

JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)276 Test (org.junit.Test)249 UUID (java.util.UUID)69 UUID.randomUUID (java.util.UUID.randomUUID)64 JsonObject (javax.json.JsonObject)30 JsonValue (javax.json.JsonValue)26 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)24 Metadata (uk.gov.justice.services.messaging.Metadata)18 Method (java.lang.reflect.Method)17 Function (java.util.function.Function)14 StreamBufferEvent (uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent)10 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)9 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)9 EndpointDefinition (uk.gov.justice.services.clients.core.EndpointDefinition)8 MediaType (uk.gov.justice.services.core.mapping.MediaType)8 StreamStatus (uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus)7 ZonedDateTime (java.time.ZonedDateTime)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 HttpHeaders (javax.ws.rs.core.HttpHeaders)6