use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorParserTest method shouldParsePathsToYaml.
@Test
public void shouldParsePathsToYaml() {
final Path path = getFromClasspath("subscription.yaml");
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptorParser.read(path);
assertSubscriptionDescriptor(subscriptionDescriptor);
final List<Subscription> subscriptions = subscriptionDescriptor.getSubscriptions();
for (final Subscription subscription : subscriptions) {
if (subscription.getName().equalsIgnoreCase("subscription1")) {
assertExampleEvents(subscription);
assertExampleEventSource(subscription.getEventsource());
}
if (subscription.getName().equalsIgnoreCase("subscription2")) {
assertPeopleEvents(subscription);
assertPeopleEventSource(subscription.getEventsource());
}
}
}
use of uk.gov.justice.subscription.domain.Subscription 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.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.
the class SubscriptionBuilderTest method shouldBeAbleToAddEventsOneAtATime.
@Test
public void shouldBeAbleToAddEventsOneAtATime() throws Exception {
final String name = "name";
final Event event_1 = mock(Event.class);
final Event event_2 = mock(Event.class);
final Eventsource eventsource = mock(Eventsource.class);
final Subscription subscription = subscription().withName(name).withEvent(event_1).withEvent(event_2).withEventsource(eventsource).build();
assertThat(subscription.getName(), is(name));
assertThat(subscription.getEventsource(), is(eventsource));
assertThat(subscription.getEvents(), hasItem(event_1));
assertThat(subscription.getEvents(), hasItem(event_2));
}
use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorBuilderTest method shouldBuildASubscription.
@Test
public void shouldBuildASubscription() throws Exception {
final String specVersion = "specVersion";
final String service = "service";
final String serviceComponent = "serviceComponent";
final Subscription subscription_1 = mock(Subscription.class);
final Subscription subscription_2 = mock(Subscription.class);
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion(specVersion).withService(service).withServiceComponent(serviceComponent).withSubscriptions(asList(subscription_1, subscription_2)).build();
assertThat(subscriptionDescriptor.getSpecVersion(), is(specVersion));
assertThat(subscriptionDescriptor.getService(), is(service));
assertThat(subscriptionDescriptor.getServiceComponent(), is(serviceComponent));
assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_1));
assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_2));
}
use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.
the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForTopic.
@Test
public void shouldGenerateMDBForTopic() throws Exception {
final String basePackageName = "uk.gov.moj.base.package.name";
final String serviceName = "my-context";
final String componentName = "EVENT_LISTENER";
final String jmsUri = "jms:topic:my-context.handler.command";
final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withCustomMDBPool();
final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"EVENT_LISTENER\")\n" + "@javax.ejb.MessageDriven(\n" + " activationConfig = {\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Topic\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionDurability\", propertyValue = \"Durable\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"clientId\", propertyValue = \"my-context.event.listener\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionName\", propertyValue = \"my-context.event.listener.my-context.handler.command\")\n" + " }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + " uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + " uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandEventValidationInterceptor.class\n" + "})\n" + "@org.jboss.ejb3.annotation.Pool(\"my-context-handler-command-event-listener-pool\")\n" + "public class MyContextEventListenerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + " private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandJmsListener.class);\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + " @java.lang.Override\n" + " public void onMessage(javax.jms.Message message) {\n" + " uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + " jmsProcessor.process(interceptorChainProcessor::process, message);\n" + " }\n" + "}\n"));
}
Aggregations