use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class RamlMediaTypeToSchemaIdGeneratorTest method createMimeTypeWith.
private MimeType createMimeTypeWith(final String type, final String schemaId) {
final MimeType mimeType = new MimeType();
mimeType.setType(type);
mimeType.setSchema(format(VALID_JSON_SCHEMA, schemaId));
return mimeType;
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class RamlMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet.
@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet() throws Exception {
final String schemaId = "http://justice.gov.uk/test/schema.json";
final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
new RamlMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).withResponseTypes(mimeType_1))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameMediaTypeToSchemaIdMapper");
final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
assertThat(mediaTypeToSchemaIdMap.size(), is(1));
assertThat(mediaTypeToSchemaIdMap.get(MEDIA_TYPE_1), is(schemaId));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class MimeTypeToEventConverterTest method shouldThrowASchemaParsingExceptionIfTheSchemaIdIsNotFound.
@Test
public void shouldThrowASchemaParsingExceptionIfTheSchemaIdIsNotFound() throws Exception {
final String eventName = "something-happened";
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(empty());
try {
mimeTypeToEventConverter.asEvent(mimeType);
fail();
} catch (final SchemaParsingException expected) {
assertThat(expected.getMessage(), is("Schema for media type: application/vnd.context.events.something-happened+json has no schema id"));
}
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class EventFilterCodeGeneratorTest method shouldGenerateCorrectEventFilterJavaCode.
@Test
public void shouldGenerateCorrectEventFilterJavaCode() throws Exception {
final String serviceName = "my-context";
final String componentName = "EVENT_LISTENER";
final String jmsUri = "jms:topic:my-context.handler.command";
final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
final SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
final HashMap<ActionType, Action> actions = new HashMap<>();
final Resource resource = new Resource();
resource.setActions(actions);
final Action action = mock(Action.class, RETURNS_DEEP_STUBS.get());
actions.put(POST, action);
final MimeType mimeType_1 = new MimeType("application/vnd.my-context.events.something-happened+json");
final MimeType mimeType_2 = new MimeType("application/vnd.my-context.events.something-else-happened+json");
final String basePackageName = "uk.gov.moj.base.package.name";
when(action.getBody().values()).thenReturn(asList(mimeType_1, mimeType_2));
final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
final TypeSpec typeSpec = eventFilterCodeGenerator.generate(subscription, classNameFactory);
assertThat(typeSpec.toString(), is("@javax.enterprise.context.ApplicationScoped\n" + "public class MyContextEventListenerMyContextHandlerCommandEventFilter extends uk.gov.justice.services.event.buffer.api.AbstractEventFilter {\n" + " public MyContextEventListenerMyContextHandlerCommandEventFilter() {\n" + " super(\"my-context.events.something-happened\",\"my-context.events.something-else-happened\");}\n" + "}\n"));
}
use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class SchemaIdParserTest method shouldReturnEmptyIfJsonSchemaHasNoSchemaId.
@Test
public void shouldReturnEmptyIfJsonSchemaHasNoSchemaId() throws Exception {
final MimeType mimeType = new MimeType();
mimeType.setType(MEDIA_TYPE);
mimeType.setSchema(NO_ID_JSON_SCHEMA);
assertThat(schemaIdParser.schemaIdFrom(mimeType), is(empty()));
}
Aggregations