Search in sources :

Example 1 with SubscriptionDescriptorDef

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

the class SubscriptionDescriptorDefBuilderTest method shouldBuildASubscriptionDescriptorDef.

@Test
public void shouldBuildASubscriptionDescriptorDef() throws Exception {
    final SubscriptionDescriptor subscriptionDescriptor = mock(SubscriptionDescriptor.class);
    final SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
    assertThat(subscriptionDescriptorDef.getSubscriptionDescriptor(), is(subscriptionDescriptor));
}
Also used : SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 2 with SubscriptionDescriptorDef

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

the class JmsEndpointGeneratorTest method shouldConvertRamlToASubscriptionThenRunTheEndpointGenerators.

@Test
public void shouldConvertRamlToASubscriptionThenRunTheEndpointGenerators() throws Exception {
    final String serviceComponent = "EVENT_LISTENER";
    final Raml raml = mock(Raml.class);
    final GeneratorConfig configuration = mock(GeneratorConfig.class);
    final CommonGeneratorProperties commonGeneratorProperties = mock(CommonGeneratorProperties.class);
    final SubscriptionDescriptorDef subscriptionDescriptorDef = mock(SubscriptionDescriptorDef.class);
    final SubscriptionDescriptor subscriptionDescriptor = mock(SubscriptionDescriptor.class);
    when(configuration.getGeneratorProperties()).thenReturn(commonGeneratorProperties);
    when(commonGeneratorProperties.getServiceComponent()).thenReturn(serviceComponent);
    when(ramlToJmsSubscriptionConverter.convert(raml, serviceComponent)).thenReturn(subscriptionDescriptorDef);
    when(subscriptionDescriptorDef.getSubscriptionDescriptor()).thenReturn(subscriptionDescriptor);
    jmsEndpointGenerator.run(raml, configuration);
    final InOrder inOrder = inOrder(ramlValidator, ramlToJmsSubscriptionConverter, subscriptionJmsEndpointGenerator);
    inOrder.verify(ramlValidator).validate(raml);
    inOrder.verify(ramlToJmsSubscriptionConverter).convert(raml, serviceComponent);
    inOrder.verify(subscriptionJmsEndpointGenerator).run(subscriptionDescriptor, configuration);
}
Also used : InOrder(org.mockito.InOrder) Raml(org.raml.model.Raml) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 3 with SubscriptionDescriptorDef

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

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

Example 5 with SubscriptionDescriptorDef

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

the class JmsEndpointGenerator method run.

/**
 * Generates JMS endpoint classes from a RAML document.
 *
 * @param raml          the RAML document
 * @param configuration contains package of generated sources, as well as source and destination
 *                      folders
 */
@Override
public void run(final Raml raml, final GeneratorConfig configuration) {
    ramlValidator.validate(raml);
    final CommonGeneratorProperties commonGeneratorProperties = (CommonGeneratorProperties) configuration.getGeneratorProperties();
    final SubscriptionDescriptorDef subscriptionDescriptorDef = ramlToJmsSubscriptionConverter.convert(raml, commonGeneratorProperties.getServiceComponent());
    subscriptionJmsEndpointGenerator.run(subscriptionDescriptorDef.getSubscriptionDescriptor(), configuration);
}
Also used : SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)

Aggregations

SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)6 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)5 Test (org.junit.Test)4 Subscription (uk.gov.justice.subscription.domain.Subscription)3 Raml (org.raml.model.Raml)2 Resource (org.raml.model.Resource)2 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 HashMap (java.util.HashMap)1 InOrder (org.mockito.InOrder)1 Action (org.raml.model.Action)1 ActionType (org.raml.model.ActionType)1 MimeType (org.raml.model.MimeType)1 GeneratorConfig (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig)1 Event (uk.gov.justice.subscription.domain.Event)1