Search in sources :

Example 36 with Metadata

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

the class DefaultJsonEnvelopeProviderTest method shouldProvideJsonObjectMetadataBuilderFromJsonObject.

@Test
public void shouldProvideJsonObjectMetadataBuilderFromJsonObject() 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.asJsonObject());
    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 37 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildFromMetadataAndOverwriteFields.

@Test
public void shouldBuildFromMetadataAndOverwriteFields() throws Exception {
    final UUID id = randomUUID();
    final UUID streamId = randomUUID();
    final UUID causationId1 = randomUUID();
    final UUID causationId2 = randomUUID();
    final String name = "some.name";
    final Metadata originalMetadata = metadataBuilder().withId(id).withName(name).withUserId("usrIdAAAA").withStreamId(streamId).withCausation(causationId1, causationId2).build();
    final Metadata metadata = metadataBuilderFrom(originalMetadata).withUserId("usrIdBBBB").withVersion(4L).build();
    assertThat(metadata.version(), contains(4L));
    assertThat(metadata.userId(), contains("usrIdBBBB"));
    assertThat(metadata.id(), is(id));
    assertThat(metadata.name(), is(name));
    assertThat(metadata.streamId(), contains(streamId));
    assertThat(metadata.causation(), hasItems(causationId1, causationId2));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) UUID.randomUUID(java.util.UUID.randomUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 38 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildMetadataWithSessionId.

@Test
public void shouldBuildMetadataWithSessionId() {
    final String sessionId = "b51597dc-2526-4c71-bd08-5031c79f11e3";
    final Metadata metadata = metadataWithDefaults().withSessionId(sessionId).build();
    assertThat(metadata.sessionId().get(), is(sessionId));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Test(org.junit.Test)

Example 39 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildMetadataWithStreamIdAndVersion.

@Test
public void shouldBuildMetadataWithStreamIdAndVersion() {
    final UUID streamId = randomUUID();
    final Long version = 1234567l;
    final Metadata metadata = metadataWithDefaults().withStreamId(streamId).withVersion(version).build();
    assertThat(metadata.streamId().get(), is(streamId));
    assertThat(metadata.version().get(), is(version));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) UUID.randomUUID(java.util.UUID.randomUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 40 with Metadata

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

the class DefaultJsonMetadataBuilderTest method shouldBuildMetadataWithMandatoryElements.

@Test
public void shouldBuildMetadataWithMandatoryElements() {
    final UUID id = randomUUID();
    final String name = "some.name";
    final Metadata metadata = metadataBuilder().withId(id).withName(name).build();
    assertThat(metadata.id(), is(id));
    assertThat(metadata.name(), is(name));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) UUID.randomUUID(java.util.UUID.randomUUID) UUID(java.util.UUID) 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