Search in sources :

Example 81 with CommonGeneratorProperties

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

the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassActionToRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldPassActionToRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(POST).with(mapping().withName("contextA.someAction").withRequestType("application/vnd.somemediatype1+json")).withMediaTypeWithDefaultSchema("application/vnd.somemediatype1+json").withHttpActionResponseAndNoBody())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiUserResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Class<?> actionMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiUserResourceActionMapper");
    final Object actionMapperObject = actionMapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    setField(resourceObject, "actionMapper", actionMapperObject);
    setField(resourceObject, "headers", headersWith("Content-Type", "application/vnd.somemediatype1+json"));
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    verify(restProcessor).process(anyString(), any(Function.class), eq("contextA.someAction"), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Test(org.junit.Test)

Example 82 with CommonGeneratorProperties

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

Example 83 with CommonGeneratorProperties

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

the class SubscriptionJmsEndpointGenerator method run.

/**
 * Generates JMS endpoint classes from a SubscriptionDescriptorDef document.
 *
 * @param subscriptionDescriptor          the subscriptionDescriptor document
 * @param configuration contains package of generated sources, as well as source and destination
 *                      folders
 */
@Override
public void run(final SubscriptionDescriptor subscriptionDescriptor, final GeneratorConfig configuration) {
    final CommonGeneratorProperties commonGeneratorProperties = (CommonGeneratorProperties) configuration.getGeneratorProperties();
    final String basePackageName = configuration.getBasePackageName();
    final List<Subscription> subscriptions = subscriptionDescriptor.getSubscriptions();
    subscriptions.stream().flatMap(subscription -> generatedClassesFrom(subscriptionDescriptor, subscription, commonGeneratorProperties, basePackageName)).forEach(generatedClass -> writeClass(configuration, basePackageName, generatedClass, LOGGER));
    final List<Event> allEvents = subscriptions.stream().map(Subscription::getEvents).flatMap(Collection::stream).collect(toList());
    final String contextName = subscriptionDescriptor.getService();
    final String componentName = subscriptionDescriptor.getServiceComponent();
    subscriptionMediaTypeToSchemaIdGenerator.generateMediaTypeToSchemaIdMapper(contextName, componentName, allEvents, configuration);
}
Also used : GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) Subscription(uk.gov.justice.subscription.domain.Subscription) JmsEndPointGeneratorUtil.shouldGenerateEventFilter(uk.gov.justice.subscription.jms.core.JmsEndPointGeneratorUtil.shouldGenerateEventFilter) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SubscriptionMediaTypeToSchemaIdGenerator(uk.gov.justice.services.generators.commons.mapping.SubscriptionMediaTypeToSchemaIdGenerator) TypeSpec(com.squareup.javapoet.TypeSpec) EventValidationInterceptorCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventValidationInterceptorCodeGenerator) EventFilterInterceptorCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventFilterInterceptorCodeGenerator) Generator(uk.gov.justice.maven.generator.io.files.parser.core.Generator) EventListenerInterceptorChainProviderCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventListenerInterceptorChainProviderCodeGenerator) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Event(uk.gov.justice.subscription.domain.Event) Stream(java.util.stream.Stream) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratedClassWriter.writeClass(uk.gov.justice.services.generators.commons.helper.GeneratedClassWriter.writeClass) Event(uk.gov.justice.subscription.domain.Event) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Subscription(uk.gov.justice.subscription.domain.Subscription)

Example 84 with CommonGeneratorProperties

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

the class RamlMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost.

@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost() throws Exception {
    final String schemaId = "http://justice.gov.uk/test/schema.json";
    final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
    new RamlMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(POST).withMediaTypeWithDefaultSchema(mimeType_1))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameMediaTypeToSchemaIdMapper");
    final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
    final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
    assertThat(mediaTypeToSchemaIdMap.size(), is(1));
    assertThat(mediaTypeToSchemaIdMap.get(MEDIA_TYPE_1), is(schemaId));
}
Also used : MediaTypeToSchemaIdMapper(uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper) MediaType(uk.gov.justice.services.core.mapping.MediaType) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 85 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForGETResource2.

@Test
public void shouldReturnActionNameForGETResource2() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/status").with(httpActionWithDefaultMapping(GET).with(mapping().withName("ctxA.actionA").withResponseType("application/vnd.ctx.query.mediatype1+json")).withResponseTypes("application/vnd.ctx.query.mediatype1+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultQueryApiStatusResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    final Object action = actionMethod.invoke(mapperObject, "getStatus", "GET", headersWith("Accept", "application/vnd.ctx.query.mediatype1+json"));
    assertThat(action, is("ctxA.actionA"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) 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