use of org.raml.model.Resource in project microservice_framework by CJSCommonPlatform.
the class GeneratorsTest method shouldReturnInterfaceNamePrefixedWithBaseUriPath.
@Test
public void shouldReturnInterfaceNamePrefixedWithBaseUriPath() throws Exception {
final Resource resource = resource("/bcd").withDefaultPostAction().build();
final String interfaceName = resourceInterfaceNameOf(resource, new RestResourceBaseUri("http://localhost:8080/warname/base/path"));
assertThat(interfaceName, is("BasePathBcdResource"));
}
use of org.raml.model.Resource 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.Resource in project microservice_framework by CJSCommonPlatform.
the class ResourceBuilder method build.
public Resource build() {
final Resource resource = new Resource();
resource.setParentUri(parentUri);
resource.setRelativeUri(relativeUri);
resource.setUriParameters(uriParameters);
final Map<ActionType, Action> actions = new HashMap<>();
for (final HttpActionBuilder httpActionBuilder : httpActionBuilders) {
final Action action = httpActionBuilder.build();
action.setResource(resource);
actions.put(action.getType(), action);
}
resource.setActions(actions);
return resource;
}
use of org.raml.model.Resource in project microservice_framework by CJSCommonPlatform.
the class RamlBuilder method build.
public Raml build() {
final Raml raml = new Raml();
raml.setBaseUri(baseUri);
raml.setVersion(version);
raml.setTitle(title);
final Map<String, Resource> resources = new HashMap<>();
for (final ResourceBuilder resourceBuilder : resourceBuilders) {
Resource resource = resourceBuilder.build();
resources.put(resource.getRelativeUri(), resource);
}
raml.setResources(resources);
return raml;
}
use of org.raml.model.Resource in project microservice_framework by CJSCommonPlatform.
the class GeneratorsTest method shouldReturnInterfaceNamePrefixedWithComponentName.
@Test
public void shouldReturnInterfaceNamePrefixedWithComponentName() throws Exception {
final Resource resource = resource("/abc").withDefaultPostAction().build();
final String interfaceName = resourceInterfaceNameOf(resource, new RestResourceBaseUri("http://localhost:8080/warname/command/api/rest/service"));
assertThat(interfaceName, is("CommandApiAbcResource"));
}
Aggregations