use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class ActionMappingParserTest method shouldReturnMappingFromRamlAndMimeType.
@Test
public void shouldReturnMappingFromRamlAndMimeType() throws Exception {
final ActionMapping actionMapping = actionMappingParser.valueOf(httpAction(GET).withResponseTypes("application/vnd.ctx.query2+json", "application/vnd.ctx.query1+json").with(mapping().withName("actionABC").withResponseType("application/vnd.ctx.query1+json")).with(mapping().withName("actionBCD").withResponseType("application/vnd.ctx.query2+json")).build(), new MimeType("application/vnd.ctx.query1+json"));
assertThat(actionMapping, not(nullValue()));
assertThat(actionMapping.getName(), is("actionABC"));
assertThat(actionMapping.getResponseType(), is("application/vnd.ctx.query1+json"));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MediaTypeToSchemaIdParserTest method shouldProduceListOfMediaTypeToSchemaIdAndIgnoreEmptySchemaIds.
@Test
public void shouldProduceListOfMediaTypeToSchemaIdAndIgnoreEmptySchemaIds() 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());
when(schemaIdParser.schemaIdFrom(mimeType_1)).thenReturn(Optional.of(SCHEMA_ID_1));
when(schemaIdParser.schemaIdFrom(mimeType_2)).thenReturn(Optional.empty());
when(schemaIdParser.schemaIdFrom(mimeType_3)).thenReturn(Optional.of(SCHEMA_ID_2));
final List<MediaTypeToSchemaId> mediaTypeToSchemaIds = mediaTypeToSchemaIdParser.parseFrom(restRamlWithQueryApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(POST).withMediaTypeWithDefaultSchema(mimeType_1).withMediaTypeWithDefaultSchema(mimeType_2).withMediaTypeWithDefaultSchema(mimeType_3))).build());
assertThat(mediaTypeToSchemaIds, hasItems(new MediaTypeToSchemaId(MEDIA_TYPE_1, SCHEMA_ID_1), new MediaTypeToSchemaId(MEDIA_TYPE_3, SCHEMA_ID_2)));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MediaTypeToSchemaIdParserTest method shouldNotProduceListOfMediaTypeForUnsuportedActionType.
@Test
public void shouldNotProduceListOfMediaTypeForUnsuportedActionType() 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(HEAD).withResponseTypes(mimeType_1, mimeType_5))).build());
assertThat(mediaTypeToSchemaIds.size(), is(0));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class RamlMimeTypeListToEventListConverterTest method shouldReturnAnEmptyListIfAnyOfTheMimeTypesAreAPlainApplicationJsonMimeType.
@Test
public void shouldReturnAnEmptyListIfAnyOfTheMimeTypesAreAPlainApplicationJsonMimeType() 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("application/json");
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(0));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MimeTypeBuilder method build.
public MimeType build() {
final MimeType mimeType = new MimeType(type);
mimeType.setFormParameters(formParameters);
return mimeType;
}
Aggregations