Search in sources :

Example 1 with EventSource

use of uk.gov.justice.services.eventsourcing.source.core.EventSource in project microservice_framework by CJSCommonPlatform.

the class SubscriptionManagerProducer method subscriptionManager.

@Produces
public SubscriptionManager subscriptionManager(final InjectionPoint injectionPoint) {
    final SubscriptionName subscriptionName = subscriptionNameAnnotationExtractor.getFrom(injectionPoint);
    final Instance<EventSource> eventSourceInstance = eventsourceInstance.select(subscriptionName);
    if (eventSourceInstance != null) {
        final EventSource eventSource = eventSourceInstance.get();
        final Subscription subscription = subscriptionDescriptorRegistry.getSubscription(subscriptionName.value());
        return new SubscriptionManager(subscription, eventSource);
    }
    throw new SubscriptionManagerProducerException(format("Failed to find instance of event souce with Qualifier '%s'", subscriptionName.value()));
}
Also used : EventSource(uk.gov.justice.services.eventsourcing.source.core.EventSource) SubscriptionName(uk.gov.justice.services.core.cdi.SubscriptionName) Subscription(uk.gov.justice.subscription.domain.Subscription) Produces(javax.enterprise.inject.Produces)

Example 2 with EventSource

use of uk.gov.justice.services.eventsourcing.source.core.EventSource in project microservice_framework by CJSCommonPlatform.

the class SubscriptionManagerProducerTest method shouldCreateSubscriptionManagersOnStartUp.

@Test
public void shouldCreateSubscriptionManagersOnStartUp() throws Exception {
    final InjectionPoint injectionPoint = mock(InjectionPoint.class);
    final SubscriptionName subscriptionName = mock(SubscriptionName.class);
    final EventSource eventSource = mock(EventSource.class);
    final Subscription subscription = mock(Subscription.class);
    when(subscriptionNameAnnotationExtractor.getFrom(injectionPoint)).thenReturn(subscriptionName);
    when(eventsourceInstance.select(subscriptionName).get()).thenReturn(eventSource);
    when(subscriptionDescriptorRegistry.getSubscription(subscriptionName.value())).thenReturn(subscription);
    final SubscriptionManager subscriptionManager = subscriptionManagerProducer.subscriptionManager(injectionPoint);
    assertThat(subscriptionManager.getEventSource(), is(eventSource));
    assertThat(subscriptionManager.getSubscription(), is(subscription));
}
Also used : EventSource(uk.gov.justice.services.eventsourcing.source.core.EventSource) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) SubscriptionName(uk.gov.justice.services.core.cdi.SubscriptionName) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Aggregations

SubscriptionName (uk.gov.justice.services.core.cdi.SubscriptionName)2 EventSource (uk.gov.justice.services.eventsourcing.source.core.EventSource)2 Subscription (uk.gov.justice.subscription.domain.Subscription)2 Produces (javax.enterprise.inject.Produces)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Test (org.junit.Test)1