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);
}
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;
}
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));
}
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()));
}
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);
}
Aggregations