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"));
}
}
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));
}
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));
}
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));
}
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"));
}
Aggregations