Search in sources :

Example 1 with DefaultEnveloper

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);
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) ObjectMapperProducer(uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer) ObjectToJsonValueConverter(uk.gov.justice.services.common.converter.ObjectToJsonValueConverter) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with DefaultEnveloper

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));
}
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 3 with DefaultEnveloper

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;
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) Event(uk.gov.justice.domain.annotation.Event)

Aggregations

DefaultEnveloper (uk.gov.justice.services.core.enveloper.DefaultEnveloper)3 ObjectToJsonValueConverter (uk.gov.justice.services.common.converter.ObjectToJsonValueConverter)2 ObjectMapperProducer (uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer)2 UtcClock (uk.gov.justice.services.common.util.UtcClock)2 EventFoundEvent (uk.gov.justice.services.core.extension.EventFoundEvent)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Test (org.junit.Test)1 Event (uk.gov.justice.domain.annotation.Event)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1 Metadata (uk.gov.justice.services.messaging.Metadata)1