Search in sources :

Example 6 with Resource

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"));
}
Also used : Resource(org.raml.model.Resource) RestResourceBaseUri(uk.gov.justice.services.generators.commons.helper.RestResourceBaseUri) Test(org.junit.Test)

Example 7 with Resource

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"));
}
Also used : Action(org.raml.model.Action) ActionType(org.raml.model.ActionType) HashMap(java.util.HashMap) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) Resource(org.raml.model.Resource) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) MimeType(org.raml.model.MimeType) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 8 with Resource

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;
}
Also used : HttpActionBuilder.defaultPostAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPostAction) HttpActionBuilder.defaultGetAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultGetAction) HttpActionBuilder.defaultPutAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPutAction) HttpActionBuilder.defaultPatchAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPatchAction) HttpActionBuilder.defaultDeleteAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultDeleteAction) Action(org.raml.model.Action) ActionType(org.raml.model.ActionType) HashMap(java.util.HashMap) Resource(org.raml.model.Resource)

Example 9 with 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;
}
Also used : HashMap(java.util.HashMap) Raml(org.raml.model.Raml) Resource(org.raml.model.Resource) ResourceBuilder.defaultGetResource(uk.gov.justice.services.generators.test.utils.builder.ResourceBuilder.defaultGetResource) ResourceBuilder.defaultPostResource(uk.gov.justice.services.generators.test.utils.builder.ResourceBuilder.defaultPostResource)

Example 10 with Resource

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"));
}
Also used : Resource(org.raml.model.Resource) RestResourceBaseUri(uk.gov.justice.services.generators.commons.helper.RestResourceBaseUri) Test(org.junit.Test)

Aggregations

Resource (org.raml.model.Resource)10 Test (org.junit.Test)8 Subscription (uk.gov.justice.subscription.domain.Subscription)6 Action (org.raml.model.Action)4 HashMap (java.util.HashMap)3 ActionType (org.raml.model.ActionType)2 MimeType (org.raml.model.MimeType)2 Raml (org.raml.model.Raml)2 RestResourceBaseUri (uk.gov.justice.services.generators.commons.helper.RestResourceBaseUri)2 Event (uk.gov.justice.subscription.domain.Event)2 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)2 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 HttpActionBuilder.defaultDeleteAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultDeleteAction)1 HttpActionBuilder.defaultGetAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultGetAction)1 HttpActionBuilder.defaultPatchAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPatchAction)1 HttpActionBuilder.defaultPostAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPostAction)1 HttpActionBuilder.defaultPutAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPutAction)1 ResourceBuilder.defaultGetResource (uk.gov.justice.services.generators.test.utils.builder.ResourceBuilder.defaultGetResource)1 ResourceBuilder.defaultPostResource (uk.gov.justice.services.generators.test.utils.builder.ResourceBuilder.defaultPostResource)1