use of uk.gov.justice.services.core.enveloper.DefaultEnveloper in project microservice_framework by CJSCommonPlatform.
the class EnveloperFactory method create.
public DefaultEnveloper create() {
final ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper();
final ObjectToJsonValueConverter converter = new ObjectToJsonValueConverter(objectMapper);
return new DefaultEnveloper(new UtcClock(), converter);
}
use of uk.gov.justice.services.core.enveloper.DefaultEnveloper 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.core.enveloper.DefaultEnveloper in project microservice_framework by CJSCommonPlatform.
the class EnveloperFactory method createWithEvents.
public Enveloper createWithEvents(final Class<?>... events) {
final DefaultEnveloper enveloper = create();
stream(events).forEach(eventClass -> {
if (eventClass.isAnnotationPresent(Event.class)) {
final Event eventClassAnnotation = eventClass.getAnnotation(Event.class);
enveloper.register(new EventFoundEvent(eventClass, eventClassAnnotation.value()));
}
});
return enveloper;
}
Aggregations