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