use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class NamesTest method shouldBuildResourceMethodNameFromActionAndMimeType.
@Test
public void shouldBuildResourceMethodNameFromActionAndMimeType() throws Exception {
final MappingBuilder mappingBuilder = mapping().withName("command.create-user").withRequestType("application/vnd.command.create-user+json");
final Action action = httpAction().withHttpActionType(POST).withDescription(mappingDescriptionWith(mappingBuilder).build()).build();
action.setResource(resource().withRelativeUri("test").build());
final String shortMimeType = Names.resourceMethodNameFrom(action, new MimeType("application/vnd.command.create-user+json"));
assertThat(shortMimeType, is("postCommandCreateUserTest"));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MediaTypeToSchemaIdParserTest method shouldProduceListOfMediaTypeForGet.
@Test
public void shouldProduceListOfMediaTypeForGet() throws Exception {
final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString());
final MimeType mimeType_5 = createMimeTypeWith(MEDIA_TYPE_5.toString());
when(schemaIdParser.schemaIdFrom(mimeType_1)).thenReturn(Optional.of(SCHEMA_ID_1));
when(schemaIdParser.schemaIdFrom(mimeType_5)).thenReturn(Optional.of(SCHEMA_ID_5));
final List<MediaTypeToSchemaId> mediaTypeToSchemaIds = mediaTypeToSchemaIdParser.parseFrom(restRamlWithQueryApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(GET).withResponseTypes(mimeType_1, mimeType_5))).build());
assertThat(mediaTypeToSchemaIds, hasItems(new MediaTypeToSchemaId(MEDIA_TYPE_1, SCHEMA_ID_1), new MediaTypeToSchemaId(MEDIA_TYPE_5, SCHEMA_ID_5)));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MediaTypeToSchemaIdParserTest method createMimeTypeWith.
private MimeType createMimeTypeWith(final String type) {
final MimeType mimeType = new MimeType();
mimeType.setType(type);
mimeType.setSchema("{}");
return mimeType;
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MediaTypeToSchemaIdParserTest method shouldProduceListOfMediaTypeToSchemaId.
@Test
public void shouldProduceListOfMediaTypeToSchemaId() throws Exception {
final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString());
final MimeType mimeType_2 = createMimeTypeWith(MEDIA_TYPE_2.toString());
final MimeType mimeType_3 = createMimeTypeWith(MEDIA_TYPE_3.toString());
final MimeType mimeType_4 = createMimeTypeWith(MEDIA_TYPE_4.toString());
when(schemaIdParser.schemaIdFrom(mimeType_1)).thenReturn(Optional.of(SCHEMA_ID_1));
when(schemaIdParser.schemaIdFrom(mimeType_2)).thenReturn(Optional.of(SCHEMA_ID_2));
when(schemaIdParser.schemaIdFrom(mimeType_3)).thenReturn(Optional.of(SCHEMA_ID_3));
when(schemaIdParser.schemaIdFrom(mimeType_4)).thenReturn(Optional.of(SCHEMA_ID_4));
final List<MediaTypeToSchemaId> mediaTypeToSchemaIds = mediaTypeToSchemaIdParser.parseFrom(restRamlWithQueryApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(POST).withMediaTypeWithDefaultSchema(mimeType_1).withMediaTypeWithDefaultSchema(mimeType_2)).with(httpActionWithDefaultMapping(PUT).withMediaTypeWithDefaultSchema(mimeType_3)).with(httpActionWithDefaultMapping(PATCH).withMediaTypeWithDefaultSchema(mimeType_4))).build());
assertThat(mediaTypeToSchemaIds, hasItems(new MediaTypeToSchemaId(MEDIA_TYPE_1, SCHEMA_ID_1), new MediaTypeToSchemaId(MEDIA_TYPE_2, SCHEMA_ID_2), new MediaTypeToSchemaId(MEDIA_TYPE_3, SCHEMA_ID_3), new MediaTypeToSchemaId(MEDIA_TYPE_4, SCHEMA_ID_4)));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class RamlMimeTypeListToEventListConverterTest method shouldConvertAListOfMimeTypesToAListOfEvents.
@Test
public void shouldConvertAListOfMimeTypesToAListOfEvents() throws Exception {
final MimeType mimeType_1 = mock(MimeType.class);
final MimeType mimeType_2 = mock(MimeType.class);
final MimeType mimeType_3 = mock(MimeType.class);
final Event event_1 = mock(Event.class);
final Event event_2 = mock(Event.class);
final Event event_3 = mock(Event.class);
when(mimeType_1.getType()).thenReturn("mimeType_1");
when(mimeType_2.getType()).thenReturn("mimeType_2");
when(mimeType_3.getType()).thenReturn("mimeType_3");
when(mimeTypeToEventConverter.asEvent(mimeType_1)).thenReturn(event_1);
when(mimeTypeToEventConverter.asEvent(mimeType_2)).thenReturn(event_2);
when(mimeTypeToEventConverter.asEvent(mimeType_3)).thenReturn(event_3);
final List<MimeType> mimeTypes = asList(mimeType_1, mimeType_2, mimeType_3);
final List<Event> events = ramlMimeTypeListToEventListConverter.toEvents(mimeTypes);
assertThat(events.size(), is(3));
assertThat(events.get(0), is(event_1));
assertThat(events.get(1), is(event_2));
assertThat(events.get(2), is(event_3));
}
Aggregations