Search in sources :

Example 1 with Metadata

use of uk.gov.justice.services.messaging.Metadata 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 Metadata

use of uk.gov.justice.services.messaging.Metadata 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 Metadata

use of uk.gov.justice.services.messaging.Metadata 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 4 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildMetadataWithCausation.

@Test
public void shouldBuildMetadataWithCausation() throws Exception {
    final UUID id1 = randomUUID();
    final UUID id2 = randomUUID();
    final Metadata metadata = metadataWithDefaults().withCausation(id1, id2).build();
    assertThat(metadata.causation(), hasItems(id1, id2));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) UUID.randomUUID(java.util.UUID.randomUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildMetadataWithClientCorrelationId.

@Test
public void shouldBuildMetadataWithClientCorrelationId() throws Exception {
    final String correlationId = "d51597dc-2526-4c71-bd08-5031c79f11e1";
    final Metadata metadata = metadataWithDefaults().withClientCorrelationId(correlationId).build();
    assertThat(metadata.clientCorrelationId().get(), is(correlationId));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Test(org.junit.Test)

Aggregations

Metadata (uk.gov.justice.services.messaging.Metadata)67 Test (org.junit.Test)58 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)19 UUID (java.util.UUID)17 UUID.randomUUID (java.util.UUID.randomUUID)11 JsonObject (javax.json.JsonObject)10 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)8 MetadataBuilder (uk.gov.justice.services.messaging.MetadataBuilder)6 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 JsonValue (javax.json.JsonValue)3 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)3 Json.createObjectBuilder (javax.json.Json.createObjectBuilder)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 UtcClock (uk.gov.justice.services.common.util.UtcClock)2 Interceptor (uk.gov.justice.services.core.interceptor.Interceptor)2 InterceptorChain (uk.gov.justice.services.core.interceptor.InterceptorChain)2 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)2 JsonEnvelope.metadataBuilder (uk.gov.justice.services.messaging.JsonEnvelope.metadataBuilder)2 EqualsTester (com.google.common.testing.EqualsTester)1 String.format (java.lang.String.format)1