Search in sources :

Example 16 with Subscription

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

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

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

the class SubscriptionBuilderTest method shouldBuildASubscription.

@Test
public void shouldBuildASubscription() 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).withEvents(asList(event_1, 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));
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 19 with Subscription

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

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

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