Search in sources :

Example 31 with Metadata

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

the class DefaultAccessControlServiceTest method setup.

@Before
public void setup() {
    final Metadata metadata = mock(Metadata.class);
    when(jsonEnvelope.metadata()).thenReturn(metadata);
    when(metadata.name()).thenReturn(ACTION_NAME);
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Before(org.junit.Before)

Example 32 with Metadata

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

the class DefaultEnveloperProviderTest method shouldDelegateToDefaultEnveloperFromCdiToEnvelopeWithMetadateFrom.

@Test
public void shouldDelegateToDefaultEnveloperFromCdiToEnvelopeWithMetadateFrom() throws Exception {
    final DefaultEnveloper enveloper = new DefaultEnveloper(new UtcClock(), new ObjectToJsonValueConverter(new ObjectMapperProducer().objectMapper()));
    enveloper.register(new EventFoundEvent(DefaultEnveloperProviderTest.TestEvent.class, TEST_EVENT_NAME));
    final Metadata metadata = createMetadata();
    final TestPojo payload = new TestPojo(TEST_EVENT_NAME);
    final Envelope<TestPojo> envelope = envelopeFrom(metadata, payload);
    final Function<Object, JsonEnvelope> envelope1 = new DefaultEnveloperProvider().toEnvelopeWithMetadataFrom(envelope);
    final TestEvent testEvent = new TestEvent();
    assertThat(envelope1.apply(testEvent).metadata().name(), is(metadata.name()));
    assertThat(envelope.payload(), is(payload));
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) Metadata(uk.gov.justice.services.messaging.Metadata) ObjectToJsonValueConverter(uk.gov.justice.services.common.converter.ObjectToJsonValueConverter) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) ObjectMapperProducer(uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) Test(org.junit.Test)

Example 33 with Metadata

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

the class HandlerMethodTest method shouldHandlePojoSynchronously.

@Test
public void shouldHandlePojoSynchronously() {
    final TestPojo testPojo = new TestPojo();
    final String payloadId = "3f47ab7e-aecc-4cec-9246-c32066ef5ba1";
    final String payloadName = "payload name";
    final long payloadVersion = 200L;
    testPojo.setPayloadId(payloadId);
    testPojo.setPayloadName(payloadName);
    testPojo.setPayloadVersion(payloadVersion);
    final Metadata metadata = Envelope.metadataBuilder().withId(UUID.randomUUID()).withName("test").build();
    final Envelope<TestPojo> requestPojoEnvelope = Envelope.envelopeFrom(metadata, testPojo);
    final Envelope<TestPojo> result = syncPojoHandlerInstance().execute(requestPojoEnvelope);
    verify(synchronousPojoCommandHandler).handles(any(Envelope.class));
    final TestPojo resultPojo = result.payload();
    assertThat(resultPojo.getPayloadId(), is(payloadId));
    assertThat(resultPojo.getPayloadName(), is(payloadName));
    assertThat(resultPojo.getPayloadVersion(), is(payloadVersion));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Envelope(uk.gov.justice.services.messaging.Envelope) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 34 with Metadata

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

the class SystemEventService method clonedEventFor.

public JsonEnvelope clonedEventFor(final UUID streamId) {
    final Metadata metadata = provider().metadataBuilder().withId(randomUUID()).withName(format(SYSTEM_EVENT_PATTERN, "cloned")).withUserId(SYSTEM_USER).createdAt(clock.now()).build();
    final JsonObject payload = createObjectBuilder().add("originatingStream", streamId.toString()).add("operation", "cloned").build();
    return provider().envelopeFrom(metadata, payload);
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) JsonObject(javax.json.JsonObject)

Example 35 with Metadata

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

the class DefaultJsonEnvelopeProviderTest method shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonValue.

@Test
public void shouldProvideDefaultJsonEnvelopeFromMetadataBuilderAndJsonValue() throws Exception {
    final UUID id = randomUUID();
    final String name = "name";
    final MetadataBuilder metadataBuilder = metadataBuilder().withId(id).withName(name);
    final JsonValue payload = mock(JsonValue.class);
    final JsonEnvelope envelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadataBuilder, payload);
    assertThat(envelope, instanceOf(DefaultJsonEnvelope.class));
    final Metadata metadata = envelope.metadata();
    assertThat(metadata.id(), is(id));
    assertThat(metadata.name(), is(name));
    assertThat(envelope.payload(), is(payload));
}
Also used : MetadataBuilder(uk.gov.justice.services.messaging.MetadataBuilder) JsonValue(javax.json.JsonValue) Metadata(uk.gov.justice.services.messaging.Metadata) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) 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