Search in sources :

Example 91 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ApplicationTest method shouldIncludeStandardProviders.

@SuppressWarnings("unchecked")
@Test
public void shouldIncludeStandardProviders() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    Set<Class<?>> compiledClasses = compiler.compiledClassesOf(BASE_PACKAGE);
    Class<?> applicationClass = compiler.classOf(compiledClasses, BASE_PACKAGE, "CommandApiRestServiceApplication");
    Object application = applicationClass.newInstance();
    CommonProviders commonProviders = mock(CommonProviders.class);
    when(commonProviders.providers()).thenReturn(newHashSet(JaxRsProviderA.class, JaxRsProviderB.class));
    setField(application, "commonProviders", commonProviders);
    Method method = applicationClass.getDeclaredMethod("getClasses");
    Object result = method.invoke(application);
    assertThat(result, is(instanceOf(Set.class)));
    Set<Class<?>> classes = (Set<Class<?>>) result;
    assertThat(classes, hasItems(JaxRsProviderA.class, JaxRsProviderB.class));
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Set(java.util.Set) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) CommonProviders(uk.gov.justice.services.adapter.rest.application.CommonProviders) Test(org.junit.Test)

Example 92 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ApplicationTest method shouldNotGenerateExistingClasses.

@SuppressWarnings("unchecked")
@Test
public void shouldNotGenerateExistingClasses() throws Exception {
    Path sourcePath = existingFilePath();
    generator.run(restRamlWithQueryApiDefaults().with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties(), singletonList(sourcePath)));
    Path outputPath = Paths.get(outputFolder.newFile().getAbsolutePath(), EXISTING_FILE_PATH);
    assertThat(outputPath.toFile().exists(), equalTo(FALSE));
}
Also used : Path(java.nio.file.Path) ApplicationPath(javax.ws.rs.ApplicationPath) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Test(org.junit.Test)

Example 93 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionNameToMediaTypesMapperTest method shouldGenerateMediaTypeToSchemaIdMapper.

@Test
public void shouldGenerateMediaTypeToSchemaIdMapper() throws Exception {
    final String actionName = "contextA.someAction";
    generator.run(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).with(mapping().withName(actionName).withResponseType(MEDIA_TYPE_1.toString())).withResponseTypes(MEDIA_TYPE_1.toString()))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mediaTypesMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameActionNameToMediaTypesMapper");
    final ActionNameToMediaTypesMapper instance = (ActionNameToMediaTypesMapper) mediaTypesMapperClass.newInstance();
    final Map<String, MediaTypes> actionNameToMediaTypesMap = instance.getActionNameToMediaTypesMap();
    assertThat(actionNameToMediaTypesMap.size(), is(1));
    assertThat(actionNameToMediaTypesMap.get(actionName).getResponseMediaType(), is(Optional.of(MEDIA_TYPE_1)));
    assertThat(actionNameToMediaTypesMap.get(actionName).getRequestMediaType(), is(Optional.empty()));
}
Also used : ActionNameToMediaTypesMapper(uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMapper) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MediaTypes(uk.gov.justice.services.core.mapping.MediaTypes) Test(org.junit.Test)

Example 94 with CommonGeneratorProperties

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

the class RestAdapterGenerator_MediaTypeToSchemaIdMapperTest method shouldGenerateMediaTypeToSchemaIdMapper.

@Test
public void shouldGenerateMediaTypeToSchemaIdMapper() throws Exception {
    final String schemaId = "http://justice.gov.uk/test/schema.json";
    final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
    generator.run(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).with(mapping().withName("contextA.someAction").withResponseType(MEDIA_TYPE_1.toString())).withResponseTypes(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 95 with CommonGeneratorProperties

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

the class RestAdapterGenerator_MultipartMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path").with(httpAction().withHttpActionType(POST).withMediaTypeWithoutSchema(multipartWithFileFormParameter("photoId")).with(mapping().withName("upload").withRequestType(MULTIPART_FORM_DATA)))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Response processorResponse = Response.ok().build();
    when(restProcessor.process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), any(Collection.class), any(List.class))).thenReturn(processorResponse);
    final Method method = firstMethodOf(resourceClass).get();
    final Object result = method.invoke(resourceObject, mock(MultipartFormDataInput.class));
    assertThat(result, is(processorResponse));
}
Also used : Response(javax.ws.rs.core.Response) Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) MultipartFormDataInput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) List(java.util.List) Method(java.lang.reflect.Method) 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