Search in sources :

Example 1 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class SchemaIdParserTest method shouldThrowExceptionIfJsonSchemaHasBlankSchemaId.

@Test
public void shouldThrowExceptionIfJsonSchemaHasBlankSchemaId() throws Exception {
    final MimeType mimeType = new MimeType();
    mimeType.setType(MEDIA_TYPE);
    mimeType.setSchema(format(VALID_JSON_SCHEMA, ""));
    expectedException.expect(SchemaParsingException.class);
    expectedException.expectMessage(is("Schema for media type: " + MEDIA_TYPE + " has a blank schema id"));
    schemaIdParser.schemaIdFrom(mimeType);
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 2 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class HttpActionBuilder method withHttpActionResponseAndEmptyBody.

public HttpActionBuilder withHttpActionResponseAndEmptyBody() {
    final Map<String, MimeType> respBody = new HashMap<>();
    final Response response = new Response();
    response.setBody(respBody);
    responses.add(response);
    return this;
}
Also used : Response(org.raml.model.Response) HashMap(java.util.HashMap) MimeType(org.raml.model.MimeType)

Example 3 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class MimeTypeToEventConverterTest method shouldConvertARamlMimeTypeToAUri.

@Test
public void shouldConvertARamlMimeTypeToAUri() throws Exception {
    final String eventName = "something-happened";
    final String schemaUri = "http://justice.gov.uk/test/schema.json";
    final String mimeTypeString = "application/vnd.context.events.something-happened+json";
    final MimeType mimeType = mock(MimeType.class);
    when(mimeType.getType()).thenReturn(mimeTypeString);
    when(eventNameExtractor.extractEventName(mimeType.getType())).thenReturn(eventName);
    when(schemaIdParser.schemaIdFrom(mimeType)).thenReturn(of(schemaUri));
    final Event event = mimeTypeToEventConverter.asEvent(mimeType);
    assertThat(event.getName(), is(eventName));
    assertThat(event.getSchemaUri(), is(schemaUri));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 4 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class RamlResourceToSubscriptionConverterTest method shouldConvertARamlResourceToASubscription.

@Test
public void shouldConvertARamlResourceToASubscription() throws Exception {
    final String resourceUri = "resourceUri";
    final String subscriptionName = "subscriptionName";
    final String eventSourceName = "eventSourceName";
    final String jmsUri = "jmsUri";
    final Resource resource = mock(Resource.class, RETURNS_DEEP_STUBS.get());
    final Event event_1 = mock(Event.class);
    final Event event_2 = mock(Event.class);
    final Collection<MimeType> mimeTypes = asList(mock(MimeType.class), mock(MimeType.class));
    when(resource.getUri()).thenReturn(resourceUri);
    when(subscriptionNamesGenerator.createSubscriptionNameFrom(resourceUri)).thenReturn(subscriptionName);
    when(resource.getAction(POST).getBody().values()).thenReturn(mimeTypes);
    when(ramlMimeTypeListToEventListConverter.toEvents(mimeTypes)).thenReturn(asList(event_1, event_2));
    when(subscriptionNamesGenerator.createEventSourceNameFrom(resourceUri)).thenReturn(eventSourceName);
    when(jmsUriGenerator.createJmsUriFrom(resourceUri)).thenReturn(jmsUri);
    final Subscription subscription = ramlResourceToSubscriptionConverter.asSubscription(resource);
    assertThat(subscription.getName(), is(subscriptionName));
    final List<Event> events = subscription.getEvents();
    assertThat(events.size(), is(2));
    assertThat(events.get(0), is(event_1));
    assertThat(events.get(1), is(event_2));
    final Eventsource eventsource = subscription.getEventsource();
    assertThat(eventsource.getName(), is(eventSourceName));
    final Location location = eventsource.getLocation();
    assertThat(location.getJmsUri(), is(jmsUri));
    assertThat(location.getRestUri(), is(nullValue()));
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) Resource(org.raml.model.Resource) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) MimeType(org.raml.model.MimeType) Location(uk.gov.justice.subscription.domain.Location) Test(org.junit.Test)

Example 5 with MimeType

use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.

the class Names method buildResourceMethodNameFromVerbUriAndMimeType.

public static String buildResourceMethodNameFromVerbUriAndMimeType(final Action action, final ActionMimeTypeDefinition actionMimeTypeDefinition) {
    final String type = action.getType().toString().toLowerCase();
    final String uri = action.getResource().getUri();
    final String mediaType = nameFrom(new MimeType(actionMimeTypeDefinition.getNameType().getType()));
    return type + buildJavaFriendlyName(uri + mediaType);
}
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