Search in sources :

Example 26 with SubscriptionDescriptor

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

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateAnnotatedCommandControllerEndpointWithDestinationLookupProperty.

@Test
public void shouldCreateAnnotatedCommandControllerEndpointWithDestinationLookupProperty() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:people.controller.command", "people.abc", serviceName, "EVENT_PROCESSOR");
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorPeopleControllerCommandJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), hasItemInArray(allOf(propertyName(equalTo("destinationLookup")), propertyValue(equalTo("people.controller.command")))));
}
Also used : MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 27 with SubscriptionDescriptor

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

the class SubscriptionJmsEndpointGeneratorTest method shouldNotAddMessageSelectorForEventListener.

@Test
public void shouldNotAddMessageSelectorForEventListener() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:structure.event", "structure.test-event", serviceName, "EVENT_LISTENER");
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventListenerStructureEventJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), not(hasItemInArray(propertyName(equalTo("messageSelector")))));
}
Also used : MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 28 with SubscriptionDescriptor

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

the class SubscriptionDescriptorFileParserTest method shouldParseEverySubsctiptionYamlFileIntoASubscriptionDescriptor.

@Test
public void shouldParseEverySubsctiptionYamlFileIntoASubscriptionDescriptor() throws Exception {
    final Path baseDir = mock(Path.class, RETURNS_DEEP_STUBS.get());
    final Path subscriptionFile_1 = mock(Path.class);
    final Path subscriptionFile_2 = mock(Path.class);
    final Path filePath_1 = mock(Path.class);
    final Path filePath_2 = mock(Path.class);
    final SubscriptionDescriptor subscriptionDescriptor_1 = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptor subscriptionDescriptor_2 = mock(SubscriptionDescriptor.class);
    when(baseDir.resolve(subscriptionFile_1).toAbsolutePath()).thenReturn(filePath_1);
    when(baseDir.resolve(subscriptionFile_2).toAbsolutePath()).thenReturn(filePath_2);
    when(subscriptionDescriptorParser.read(filePath_1)).thenReturn(subscriptionDescriptor_1);
    when(subscriptionDescriptorParser.read(filePath_2)).thenReturn(subscriptionDescriptor_2);
    final Collection<SubscriptionDescriptor> subscriptionDescriptors = subscriptionDescriptorFileParser.parse(baseDir, asList(subscriptionFile_1, subscriptionFile_2));
    assertThat(subscriptionDescriptors.size(), is(2));
    assertThat(subscriptionDescriptors, hasItem(subscriptionDescriptor_1));
    assertThat(subscriptionDescriptors, hasItem(subscriptionDescriptor_2));
}
Also used : Path(java.nio.file.Path) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 29 with SubscriptionDescriptor

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

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

the class SubscriptionRegistryProducerTest method shouldCreateARegistryOfAllSubscriptionsFromTheClasspath.

@Test
public void shouldCreateARegistryOfAllSubscriptionsFromTheClasspath() throws Exception {
    final Path path_1 = mock(Path.class);
    final Path path_2 = mock(Path.class);
    final SubscriptionDescriptor subscriptionDescriptor_1 = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptor subscriptionDescriptor_2 = mock(SubscriptionDescriptor.class);
    final String service_1 = "service_1";
    final String service_2 = "service_2";
    when(subscriptionDescriptorFileFinder.findOnClasspath()).thenReturn(asList(path_1, path_2));
    when(subscriptionDescriptorParser.read(path_1)).thenReturn(subscriptionDescriptor_1);
    when(subscriptionDescriptorParser.read(path_2)).thenReturn(subscriptionDescriptor_2);
    when(subscriptionDescriptor_1.getService()).thenReturn(service_1);
    when(subscriptionDescriptor_2.getService()).thenReturn(service_2);
    final SubscriptionDescriptorRegistry subscriptionDescriptorRegistry = subscriptionRegistryProducer.subscriptionDescriptorRegistry(mock(InjectionPoint.class));
    assertThat(subscriptionDescriptorRegistry.getSubscriptionDescriptorFor(service_1), is(of(subscriptionDescriptor_1)));
    assertThat(subscriptionDescriptorRegistry.getSubscriptionDescriptorFor(service_2), is(of(subscriptionDescriptor_2)));
}
Also used : Path(java.nio.file.Path) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Aggregations

SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)54 Test (org.junit.Test)52 MessageDriven (javax.ejb.MessageDriven)16 Subscription (uk.gov.justice.subscription.domain.Subscription)14 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)11 Event (uk.gov.justice.subscription.domain.Event)7 TypeSpec (com.squareup.javapoet.TypeSpec)5 Adapter (uk.gov.justice.services.core.annotation.Adapter)5 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)5 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)5 Field (java.lang.reflect.Field)4 ReflectionUtil.setField (uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField)4 File (java.io.File)3 Path (java.nio.file.Path)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 ActivationConfigProperty (javax.ejb.ActivationConfigProperty)2 Inject (javax.inject.Inject)2 Message (javax.jms.Message)2 MessageListener (javax.jms.MessageListener)2