Search in sources :

Example 31 with MimeType

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"));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 32 with MimeType

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)));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 33 with MimeType

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));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 34 with MimeType

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));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 35 with MimeType

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;
}
Also used : MimeType(org.raml.model.MimeType)

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