Search in sources :

Example 6 with MediaTypes

use of uk.gov.justice.services.core.mapping.MediaTypes in project microservice_framework by CJSCommonPlatform.

the class MediaTypeProviderTest method shouldReturnEmptyIfNoResponseMediaTypeFoundForTheActionName.

@Test
public void shouldReturnEmptyIfNoResponseMediaTypeFoundForTheActionName() throws Exception {
    final String actionName = "example.add-recipe";
    final MediaTypes mediaTypes = mock(MediaTypes.class);
    when(mediaTypesMappingCache.mediaTypesFor(actionName)).thenReturn(of(mediaTypes));
    when(mediaTypes.getResponseMediaType()).thenReturn(empty());
    assertThat(mediaTypeProvider.getResponseMediaType(actionName), is(empty()));
}
Also used : MediaTypes(uk.gov.justice.services.core.mapping.MediaTypes) Test(org.junit.Test)

Example 7 with MediaTypes

use of uk.gov.justice.services.core.mapping.MediaTypes in project microservice_framework by CJSCommonPlatform.

the class MediaTypeProviderTest method shouldReturnEmptyIfNoRequestMediaTypeFoundForTheActionName.

@Test
public void shouldReturnEmptyIfNoRequestMediaTypeFoundForTheActionName() throws Exception {
    final String actionName = "example.add-recipe";
    final MediaTypes mediaTypes = mock(MediaTypes.class);
    when(mediaTypesMappingCache.mediaTypesFor(actionName)).thenReturn(of(mediaTypes));
    when(mediaTypes.getRequestMediaType()).thenReturn(empty());
    assertThat(mediaTypeProvider.getRequestMediaType(actionName), is(empty()));
}
Also used : MediaTypes(uk.gov.justice.services.core.mapping.MediaTypes) Test(org.junit.Test)

Example 8 with MediaTypes

use of uk.gov.justice.services.core.mapping.MediaTypes 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)

Aggregations

Test (org.junit.Test)8 MediaTypes (uk.gov.justice.services.core.mapping.MediaTypes)8 MediaType (uk.gov.justice.services.core.mapping.MediaType)5 ActionNameToMediaTypesMapper (uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMapper)4 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)3 TypeSpec (com.squareup.javapoet.TypeSpec)1 MediaTypesMapper (uk.gov.justice.services.core.annotation.MediaTypesMapper)1