Search in sources :

Example 16 with MimeType

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"));
}
Also used : HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) MappingBuilder(uk.gov.justice.services.generators.test.utils.builder.MappingBuilder) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 17 with MimeType

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

Example 18 with MimeType

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

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

Example 20 with MimeType

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));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) 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