Search in sources :

Example 11 with Subscription

use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForCommandHandlerQueue.

@Test
public void shouldGenerateMDBForCommandHandlerQueue() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    final String serviceName = "my-context";
    final String componentName = "COMMAND_HANDLER";
    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().withServiceComponentOf(componentName);
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_HANDLER\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandHandlerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandHandlerMyContextHandlerCommandJmsListener.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"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 12 with Subscription

use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForQueue.

@Test
public void shouldGenerateMDBForQueue() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    final String serviceName = "my-context";
    final String componentName = "COMMAND_API";
    final String jmsUri = "jms:queue: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().withServiceComponentOf("COMMAND_API");
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_API\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandApiMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandApiMyContextHandlerCommandJmsListener.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"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 13 with Subscription

use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method setUpMessageSubscription.

private SubscriptionDescriptor setUpMessageSubscription(String jmsUri, String eventName, String serviceName, String componentName) {
    Event event = event().withName(eventName).withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/" + eventName + ".json").build();
    Subscription subscription = subscription().withName("subscription").withEvent(event).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    return subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
}
Also used : Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription)

Example 14 with Subscription

use of uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.

the class RamlToJmsSubscriptionConverterTest method shouldCreateASchemaObjectFromARamlObject.

@SuppressWarnings("unchecked")
@Test
public void shouldCreateASchemaObjectFromARamlObject() throws Exception {
    final String componentName = "EVENT_LISTENER";
    final String contextName = "people";
    final String baseUri = "message://command/handler/message/people";
    final Raml raml = mock(Raml.class, RETURNS_DEEP_STUBS.get());
    final Resource resource_1 = mock(Resource.class);
    final Resource resource_2 = mock(Resource.class);
    final Resource resource_3 = mock(Resource.class);
    final Subscription subscription_1 = mock(Subscription.class);
    final Subscription subscription_2 = mock(Subscription.class);
    final Subscription subscription_3 = mock(Subscription.class);
    final List<Subscription> subscriptions = asList(subscription_1, subscription_2, subscription_3);
    when(raml.getBaseUri()).thenReturn(baseUri);
    when(subscriptionNamesGenerator.createContextNameFrom(baseUri)).thenReturn(contextName);
    when(raml.getResources().values()).thenReturn(asList(resource_1, resource_2, resource_3));
    when(resourcesListToSubscriptionListConverter.getSubscriptions(raml.getResources().values())).thenReturn(subscriptions);
    final SubscriptionDescriptorDef subscriptionDescriptorDef = ramlToJmsSubscriptionConverter.convert(raml, componentName);
    final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptorDef.getSubscriptionDescriptor();
    assertThat(subscriptionDescriptor.getSpecVersion(), is("1.0.0"));
    assertThat(subscriptionDescriptor.getService(), is(contextName));
    assertThat(subscriptionDescriptor.getServiceComponent(), is(componentName));
    assertThat(subscriptionDescriptor.getSubscriptions().size(), is(3));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_1));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_2));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_3));
}
Also used : Raml(org.raml.model.Raml) Resource(org.raml.model.Resource) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 15 with Subscription

use of uk.gov.justice.subscription.domain.Subscription 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

Subscription (uk.gov.justice.subscription.domain.Subscription)24 Test (org.junit.Test)19 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)14 Event (uk.gov.justice.subscription.domain.Event)12 Resource (org.raml.model.Resource)6 TypeSpec (com.squareup.javapoet.TypeSpec)5 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 Eventsource (uk.gov.justice.subscription.domain.Eventsource)4 Action (org.raml.model.Action)3 MimeType (org.raml.model.MimeType)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)3 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SubscriptionName (uk.gov.justice.services.core.cdi.SubscriptionName)2 EventSource (uk.gov.justice.services.eventsourcing.source.core.EventSource)2 Location (uk.gov.justice.subscription.domain.Location)2 File (java.io.File)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1