Search in sources :

Example 26 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class SchemaIdParserTest method shouldParseSchemaIdFromJsonSchemaFromMediaType.

@Test
public void shouldParseSchemaIdFromJsonSchemaFromMediaType() throws Exception {
    final MimeType mimeType = new MimeType();
    mimeType.setType(MEDIA_TYPE);
    mimeType.setSchema(format(VALID_JSON_SCHEMA, SCHEMA_ID));
    final Optional<String> schemaId = schemaIdParser.schemaIdFrom(mimeType);
    assertThat(schemaId, is(Optional.of(SCHEMA_ID)));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 27 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class SchemaIdParserTest method shouldReturnOptionalEmptyIfJsonSchemaIsNotSet.

@Test
public void shouldReturnOptionalEmptyIfJsonSchemaIsNotSet() throws Exception {
    final MimeType mimeType = new MimeType();
    mimeType.setType(MEDIA_TYPE);
    schemaIdParser.schemaIdFrom(mimeType);
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 28 with MimeType

use of org.raml.model.MimeType 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 29 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class NamesTest method shouldGenerateCorrectResourceNameForGetWithResponseMimeType.

@Test
public void shouldGenerateCorrectResourceNameForGetWithResponseMimeType() {
    final Action action = HttpActionBuilder.defaultGetAction().withResourceUri("/some/path/{recipeId}/").build();
    final ActionMimeTypeDefinition actionMimeTypeDefinition = ActionMimeTypeDefinition.definitionWithResponse(new MimeType("application/vnd.command.create-user+json"));
    assertThat(Names.buildResourceMethodNameFromVerbUriAndMimeType(action, actionMimeTypeDefinition), equalTo("getSomePathRecipeIdCommandCreateUser"));
}
Also used : ActionMimeTypeDefinition(uk.gov.justice.services.generators.commons.client.ActionMimeTypeDefinition) HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 30 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class NamesTest method shouldConstructDelimitedStringOfMimeTypes.

@Test
public void shouldConstructDelimitedStringOfMimeTypes() throws Exception {
    final String expectedResult = "command.create-user,command.update-user,command.delete-user";
    final Stream<MimeType> mimeTypeStream = Stream.of(new MimeType("application/vnd.command.create-user+json"), new MimeType("application/vnd.command.update-user+json"), new MimeType("application/vnd.command.delete-user+json"));
    assertThat(Names.namesListStringFrom(mimeTypeStream, ","), is(expectedResult));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Aggregations

MimeType (org.raml.model.MimeType)38 Test (org.junit.Test)30 Action (org.raml.model.Action)6 Event (uk.gov.justice.subscription.domain.Event)6 HttpActionBuilder.httpAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction)4 MediaType (uk.gov.justice.services.core.mapping.MediaType)3 MediaTypeToSchemaIdMapper (uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper)3 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)3 Subscription (uk.gov.justice.subscription.domain.Subscription)3 HashMap (java.util.HashMap)2 Resource (org.raml.model.Resource)2 ActionMimeTypeDefinition (uk.gov.justice.services.generators.commons.client.ActionMimeTypeDefinition)2 Eventsource (uk.gov.justice.subscription.domain.Eventsource)2 Location (uk.gov.justice.subscription.domain.Location)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 ActionType (org.raml.model.ActionType)1 Response (org.raml.model.Response)1 SchemaParsingException (uk.gov.justice.services.generators.commons.mapping.SchemaParsingException)1 MappingBuilder (uk.gov.justice.services.generators.test.utils.builder.MappingBuilder)1 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)1