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);
}
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));
}
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));
}
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);
}
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));
}
Aggregations