Search in sources :

Example 16 with Metadata

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

the class JsonEnvelopeMetadataMatcherTest method shouldMatchMetadataByClientCorrelationId.

@Test
public void shouldMatchMetadataByClientCorrelationId() throws Exception {
    final Metadata metadata = metadataWithRandomUUID(EVENT_NAME).withClientCorrelationId(CLIENT_CORRELATION_ID).build();
    assertThat(metadata, JsonEnvelopeMetadataMatcher.metadata().withClientCorrelationId(CLIENT_CORRELATION_ID));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Test(org.junit.Test)

Example 17 with Metadata

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

the class JsonEnvelopeMetadataMatcherTest method shouldFailIfVersionDoesNotMatch.

@Test(expected = AssertionError.class)
public void shouldFailIfVersionDoesNotMatch() throws Exception {
    final Metadata metadata = metadataWithRandomUUID(EVENT_NAME).withVersion(1L).build();
    assertThat(metadata, JsonEnvelopeMetadataMatcher.metadata().withVersion(2L));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) Test(org.junit.Test)

Example 18 with Metadata

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

the class EventsPageIT method storeEvents.

private void storeEvents(final int eventNumber) throws InvalidPositionException {
    for (int i = 1; i <= eventNumber; i++) {
        final UUID id = randomUUID();
        final Metadata metadata = JsonEnvelope.metadataBuilder().withId(id).withStreamId(STREAM_ID).withName("name").createdAt(now()).withVersion(i).build();
        final Event event = new Event(randomUUID(), STREAM_ID, valueOf(i), "Test Name" + i, metadata.asJsonObject().toString(), createObjectBuilder().add("field" + i, "value" + i).build().toString(), new UtcClock().now());
        eventsRepository.insert(event);
    }
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) Metadata(uk.gov.justice.services.messaging.Metadata) Event(uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID)

Example 19 with Metadata

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

the class EnvelopeInspectorTest method shouldGetTheActionNameOfAnEnvelope.

@Test
public void shouldGetTheActionNameOfAnEnvelope() throws Exception {
    final String actionName = "example.an-action";
    final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
    final Metadata metadata = mock(Metadata.class);
    when(jsonEnvelope.metadata()).thenReturn(metadata);
    when(metadata.name()).thenReturn(actionName);
    assertThat(envelopeInspector.getActionNameFor(jsonEnvelope), is(actionName));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 20 with Metadata

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

the class DefaultEnveloperProviderTest method shouldEnvelopWithDefaultEnvelope.

@Test
public void shouldEnvelopWithDefaultEnvelope() {
    final Metadata metadata = createMetadata();
    final TestPojo payload = new TestPojo(TEST_EVENT_NAME);
    final Envelope<TestPojo> envelope = envelopeFrom(metadata, payload);
    final Envelope<TestPojo> resultEnvelope = new DefaultEnveloperProvider().envelop(payload).withName(TEST_EVENT_NAME).withMetadataFrom(envelope);
    assertThat(resultEnvelope, instanceOf(DefaultEnvelope.class));
    assertThat(resultEnvelope.metadata().name(), is(metadata.name()));
    assertThat(resultEnvelope.payload(), is(payload));
}
Also used : Metadata(uk.gov.justice.services.messaging.Metadata) DefaultEnvelope(uk.gov.justice.services.messaging.spi.DefaultEnvelope) 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