Search in sources :

Example 41 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_PUTMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PUT).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Response processorResponse = Response.ok().build();
    when(restProcessor.process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class))).thenReturn(processorResponse);
    final Method method = firstMethodOf(resourceClass).get();
    final Object result = method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    assertThat(result, is(processorResponse));
}
Also used : Response(javax.ws.rs.core.Response) Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 42 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_PUTMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PUT).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    final ArgumentCaptor<Function> functionCaptor = ArgumentCaptor.forClass(Function.class);
    verify(restProcessor).process(anyString(), functionCaptor.capture(), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
    final JsonEnvelope envelope = mock(JsonEnvelope.class);
    final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
    functionCaptor.getValue().apply(interceptorContext);
    verify(interceptorChainProcessor).process(interceptorContext);
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 43 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_SynchronousPOSTMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestAndResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Response processorResponse = Response.ok().build();
    when(restProcessor.process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class))).thenReturn(processorResponse);
    final Method method = firstMethodOf(resourceClass).get();
    final Object result = method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    assertThat(result, is(processorResponse));
}
Also used : Response(javax.ws.rs.core.Response) Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 44 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties 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 45 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForTopic.

@Test
public void shouldGenerateMDBForTopic() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    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 ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
    GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withCustomMDBPool();
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"EVENT_LISTENER\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Topic\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionDurability\", propertyValue = \"Durable\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"clientId\", propertyValue = \"my-context.event.listener\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionName\", propertyValue = \"my-context.event.listener.my-context.handler.command\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandEventValidationInterceptor.class\n" + "})\n" + "@org.jboss.ejb3.annotation.Pool(\"my-context-handler-command-event-listener-pool\")\n" + "public class MyContextEventListenerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandJmsListener.class);\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + "  @java.lang.Override\n" + "  public void onMessage(javax.jms.Message message) {\n" + "    uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + "    jmsProcessor.process(interceptorChainProcessor::process, message);\n" + "  }\n" + "}\n"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Aggregations

CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)96 Test (org.junit.Test)93 Method (java.lang.reflect.Method)72 Collection (java.util.Collection)33 HttpHeaders (javax.ws.rs.core.HttpHeaders)33 Function (java.util.function.Function)32 JsonObject (javax.json.JsonObject)31 Response (javax.ws.rs.core.Response)30 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)21 Optional (java.util.Optional)18 ActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper)11 BasicActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper)11 Parameter (uk.gov.justice.services.adapter.rest.parameter.Parameter)10 Consumes (javax.ws.rs.Consumes)9 Field (java.lang.reflect.Field)7 Parameter (java.lang.reflect.Parameter)7 Produces (javax.ws.rs.Produces)6 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)6 MediaType (uk.gov.justice.services.core.mapping.MediaType)6 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)6