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