use of uk.gov.justice.services.core.cdi.SubscriptionName 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()));
}
use of uk.gov.justice.services.core.cdi.SubscriptionName in project microservice_framework by CJSCommonPlatform.
the class SubscriptionNameAnnotationExtractor method getFrom.
public SubscriptionName getFrom(final InjectionPoint injectionPoint) {
final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
final Annotation subscriptionNameAnnotation = qualifiers.stream().filter(annotation -> annotation.annotationType() == SubscriptionName.class).findFirst().orElseThrow(() -> new SubscriptionManagerProducerException(format("Failed to find SubscriptionName annotation on EventListener '%s'", injectionPoint.getBean().getName())));
return (SubscriptionName) subscriptionNameAnnotation;
}
use of uk.gov.justice.services.core.cdi.SubscriptionName in project microservice_framework by CJSCommonPlatform.
the class SubscriptionManagerProducerTest method shouldThrowASubscriptioManagerProducerExceptionIfTheEventSourceInstanceReturnsANull.
@Test
public void shouldThrowASubscriptioManagerProducerExceptionIfTheEventSourceInstanceReturnsANull() throws Exception {
final InjectionPoint injectionPoint = mock(InjectionPoint.class);
final SubscriptionName subscriptionName = mock(SubscriptionName.class);
when(subscriptionNameAnnotationExtractor.getFrom(injectionPoint)).thenReturn(subscriptionName);
when(eventsourceInstance.select(subscriptionName)).thenReturn(null);
when(subscriptionName.value()).thenReturn("my-subscription");
try {
subscriptionManagerProducer.subscriptionManager(injectionPoint);
fail();
} catch (final SubscriptionManagerProducerException expected) {
assertThat(expected.getMessage(), is("Failed to find instance of event souce with Qualifier 'my-subscription'"));
}
}
use of uk.gov.justice.services.core.cdi.SubscriptionName in project microservice_framework by CJSCommonPlatform.
the class MyOtherEventListener method shouldGetTheSubscriptionNameQualifierFromAnEventListenerClass.
@Test
public void shouldGetTheSubscriptionNameQualifierFromAnEventListenerClass() throws Exception {
final InjectionPoint injectionPoint = mock(InjectionPoint.class);
final Annotation annotation = MyEventListener.class.getDeclaredAnnotation(SubscriptionName.class);
when(injectionPoint.getQualifiers()).thenReturn(ImmutableSet.of(annotation));
final SubscriptionName subscriptionNameAnnotation = subscriptionNameAnnotationExtractor.getFrom(injectionPoint);
assertThat(subscriptionNameAnnotation.value(), is("my-subscription"));
}
use of uk.gov.justice.services.core.cdi.SubscriptionName 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));
}
Aggregations