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