Search in sources :

Example 31 with SubscriptionDescriptor

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

the class SubscriptionDescriptorRegistryTest method shouldThrowASubscriptioManagerProducerExceptionIfNoSubscriptionCanBeFoundWithTheSpecifiedName.

@Test
public void shouldThrowASubscriptioManagerProducerExceptionIfNoSubscriptionCanBeFoundWithTheSpecifiedName() throws Exception {
    final String thisSubscriptionDoesNotExist = "thisSubscriptionDoesNotExist";
    final Subscription subscription_1_1 = mock(Subscription.class);
    final Subscription subscription_1_2 = mock(Subscription.class);
    final Subscription subscription_2_1 = mock(Subscription.class);
    final Subscription subscription_2_2 = mock(Subscription.class);
    final SubscriptionDescriptor subscriptionDescriptor_1 = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptor subscriptionDescriptor_2 = mock(SubscriptionDescriptor.class);
    when(subscriptionDescriptor_1.getSubscriptions()).thenReturn(asList(subscription_1_1, subscription_1_2));
    when(subscriptionDescriptor_2.getSubscriptions()).thenReturn(asList(subscription_2_1, subscription_2_2));
    when(subscription_1_1.getName()).thenReturn("subscription_1_1");
    when(subscription_1_2.getName()).thenReturn("subscription_1_2");
    when(subscription_2_1.getName()).thenReturn("subscription_2_1");
    when(subscription_2_2.getName()).thenReturn("subscription_2_2");
    final Map<String, SubscriptionDescriptor> registry = of("service_1", subscriptionDescriptor_1, "service_2", subscriptionDescriptor_2);
    final SubscriptionDescriptorRegistry subscriptionDescriptorRegistry = new SubscriptionDescriptorRegistry(registry);
    try {
        subscriptionDescriptorRegistry.getSubscription(thisSubscriptionDoesNotExist);
        fail();
    } catch (final SubscriptionManagerProducerException expected) {
        assertThat(expected.getMessage(), is("Failed to find subscription 'thisSubscriptionDoesNotExist' in registry"));
    }
}
Also used : Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 32 with SubscriptionDescriptor

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

the class SubscriptionDescriptorRegistryTest method shouldMaintainARegistryOfServiceNamesToSubscriptionDescriptions.

@Test
public void shouldMaintainARegistryOfServiceNamesToSubscriptionDescriptions() throws Exception {
    final String service_1 = "service_1";
    final String service_2 = "service_2";
    final SubscriptionDescriptor subscriptionDescriptor_1 = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptor subscriptionDescriptor_2 = mock(SubscriptionDescriptor.class);
    when(subscriptionDescriptor_1.getService()).thenReturn(service_1);
    when(subscriptionDescriptor_2.getService()).thenReturn(service_2);
    final Map<String, SubscriptionDescriptor> registry = of(service_1, subscriptionDescriptor_1, service_2, subscriptionDescriptor_2);
    final SubscriptionDescriptorRegistry subscriptionDescriptorRegistry = new SubscriptionDescriptorRegistry(registry);
    assertThat(subscriptionDescriptorRegistry.getSubscriptionDescriptorFor(service_1), is(Optional.of(subscriptionDescriptor_1)));
    assertThat(subscriptionDescriptorRegistry.getSubscriptionDescriptorFor(service_2), is(Optional.of(subscriptionDescriptor_2)));
}
Also used : SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 33 with SubscriptionDescriptor

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

the class SubscriptionDescriptorRegistryTest method shouldGetASubscriptionByNameBySearchingAllASubscriptionDescriptors.

@Test
public void shouldGetASubscriptionByNameBySearchingAllASubscriptionDescriptors() throws Exception {
    final Subscription subscription_1_1 = mock(Subscription.class);
    final Subscription subscription_1_2 = mock(Subscription.class);
    final Subscription subscription_2_1 = mock(Subscription.class);
    final Subscription subscription_2_2 = mock(Subscription.class);
    final SubscriptionDescriptor subscriptionDescriptor_1 = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptor subscriptionDescriptor_2 = mock(SubscriptionDescriptor.class);
    when(subscriptionDescriptor_1.getSubscriptions()).thenReturn(asList(subscription_1_1, subscription_1_2));
    when(subscriptionDescriptor_2.getSubscriptions()).thenReturn(asList(subscription_2_1, subscription_2_2));
    when(subscription_1_1.getName()).thenReturn("subscription_1_1");
    when(subscription_1_2.getName()).thenReturn("subscription_1_2");
    when(subscription_2_1.getName()).thenReturn("subscription_2_1");
    when(subscription_2_2.getName()).thenReturn("subscription_2_2");
    final Map<String, SubscriptionDescriptor> registry = of("service_1", subscriptionDescriptor_1, "service_2", subscriptionDescriptor_2);
    final SubscriptionDescriptorRegistry subscriptionDescriptorRegistry = new SubscriptionDescriptorRegistry(registry);
    assertThat(subscriptionDescriptorRegistry.getSubscription("subscription_2_1"), is(subscription_2_1));
}
Also used : Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 34 with SubscriptionDescriptor

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

the class SubscriptionDescriptorBuilderTest method shouldBeAbleToAddSubscriptionsOneAtATime.

@Test
public void shouldBeAbleToAddSubscriptionsOneAtATime() 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).withSubscription(subscription_1).withSubscription(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));
}
Also used : Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 35 with SubscriptionDescriptor

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

the class EventFilterCodeGeneratorTest method shouldGenerateCorrectEventFilterJavaCode.

@Test
public void shouldGenerateCorrectEventFilterJavaCode() throws Exception {
    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 SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
    final HashMap<ActionType, Action> actions = new HashMap<>();
    final Resource resource = new Resource();
    resource.setActions(actions);
    final Action action = mock(Action.class, RETURNS_DEEP_STUBS.get());
    actions.put(POST, action);
    final MimeType mimeType_1 = new MimeType("application/vnd.my-context.events.something-happened+json");
    final MimeType mimeType_2 = new MimeType("application/vnd.my-context.events.something-else-happened+json");
    final String basePackageName = "uk.gov.moj.base.package.name";
    when(action.getBody().values()).thenReturn(asList(mimeType_1, mimeType_2));
    final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
    final TypeSpec typeSpec = eventFilterCodeGenerator.generate(subscription, classNameFactory);
    assertThat(typeSpec.toString(), is("@javax.enterprise.context.ApplicationScoped\n" + "public class MyContextEventListenerMyContextHandlerCommandEventFilter extends uk.gov.justice.services.event.buffer.api.AbstractEventFilter {\n" + "  public MyContextEventListenerMyContextHandlerCommandEventFilter() {\n" + "    super(\"my-context.events.something-happened\",\"my-context.events.something-else-happened\");}\n" + "}\n"));
}
Also used : Action(org.raml.model.Action) ActionType(org.raml.model.ActionType) HashMap(java.util.HashMap) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) Resource(org.raml.model.Resource) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) MimeType(org.raml.model.MimeType) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) TypeSpec(com.squareup.javapoet.TypeSpec) 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