Search in sources :

Example 1 with Resource

use of org.raml.model.Resource 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 2 with Resource

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

the class ResourcesListToSubscriptionListConverterTest method shouldReturnAnEmptyListOfSubscriptionsIfNoneOfTheActionsArePost.

@Test
public void shouldReturnAnEmptyListOfSubscriptionsIfNoneOfTheActionsArePost() throws Exception {
    final Resource resource_1 = mock(Resource.class);
    final Resource resource_2 = mock(Resource.class);
    final Resource resource_3 = mock(Resource.class);
    final Resource resource_4 = mock(Resource.class);
    final Resource resource_5 = mock(Resource.class);
    final Resource resource_6 = mock(Resource.class);
    when(resource_1.getAction(GET)).thenReturn(null);
    when(resource_2.getAction(DELETE)).thenReturn(null);
    when(resource_3.getAction(HEAD)).thenReturn(null);
    when(resource_4.getAction(OPTIONS)).thenReturn(null);
    when(resource_5.getAction(PATCH)).thenReturn(null);
    when(resource_6.getAction(TRACE)).thenReturn(null);
    final Collection<Resource> resources = asList(resource_1, resource_2, resource_3, resource_4, resource_5, resource_6);
    final List<Subscription> subscriptions = resourcesListToSubscriptionListConverter.getSubscriptions(resources);
    assertThat(subscriptions.size(), is(0));
    verifyZeroInteractions(ramlResourceToSubscriptionConverter);
}
Also used : Resource(org.raml.model.Resource) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 3 with Resource

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

the class ResourcesListToSubscriptionListConverterTest method shouldConvertAListOfResourcesToAListOfSubscriptions.

@Test
public void shouldConvertAListOfResourcesToAListOfSubscriptions() throws Exception {
    final Resource resource_1 = mock(Resource.class);
    final Resource resource_2 = mock(Resource.class);
    final Resource resource_3 = mock(Resource.class);
    final Action action_1 = mock(Action.class);
    final Action action_2 = mock(Action.class);
    final Action action_3 = mock(Action.class);
    final Subscription subscription_1 = mock(Subscription.class);
    final Subscription subscription_2 = mock(Subscription.class);
    final Subscription subscription_3 = mock(Subscription.class);
    when(resource_1.getAction(POST)).thenReturn(action_1);
    when(resource_2.getAction(POST)).thenReturn(action_2);
    when(resource_3.getAction(POST)).thenReturn(action_3);
    when(ramlResourceToSubscriptionConverter.asSubscription(resource_1)).thenReturn(subscription_1);
    when(ramlResourceToSubscriptionConverter.asSubscription(resource_2)).thenReturn(subscription_2);
    when(ramlResourceToSubscriptionConverter.asSubscription(resource_3)).thenReturn(subscription_3);
    final Collection<Resource> resources = asList(resource_1, resource_2, resource_3);
    final List<Subscription> subscriptions = resourcesListToSubscriptionListConverter.getSubscriptions(resources);
    assertThat(subscriptions.size(), is(3));
    assertThat(subscriptions, hasItem(subscription_1));
    assertThat(subscriptions, hasItem(subscription_2));
    assertThat(subscriptions, hasItem(subscription_3));
}
Also used : Action(org.raml.model.Action) Resource(org.raml.model.Resource) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 4 with Resource

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

the class ResourcesListToSubscriptionListConverterTest method shouldOnlyConvertResourcesThatHaveAnActionOfPost.

@Test
public void shouldOnlyConvertResourcesThatHaveAnActionOfPost() throws Exception {
    final Resource resource_1 = mock(Resource.class);
    final Resource resource_2 = mock(Resource.class);
    final Resource resource_3 = mock(Resource.class);
    final Resource resource_4 = mock(Resource.class);
    final Resource resource_5 = mock(Resource.class);
    final Resource resource_6 = mock(Resource.class);
    final Resource resource_7 = mock(Resource.class);
    final Action action_1 = mock(Action.class);
    final Subscription subscription_1 = mock(Subscription.class);
    when(resource_1.getAction(POST)).thenReturn(action_1);
    when(resource_2.getAction(GET)).thenReturn(null);
    when(resource_3.getAction(DELETE)).thenReturn(null);
    when(resource_4.getAction(HEAD)).thenReturn(null);
    when(resource_5.getAction(OPTIONS)).thenReturn(null);
    when(resource_6.getAction(PATCH)).thenReturn(null);
    when(resource_7.getAction(TRACE)).thenReturn(null);
    when(ramlResourceToSubscriptionConverter.asSubscription(resource_1)).thenReturn(subscription_1);
    final Collection<Resource> resources = asList(resource_1, resource_2, resource_3, resource_4, resource_5, resource_6, resource_7);
    final List<Subscription> subscriptions = resourcesListToSubscriptionListConverter.getSubscriptions(resources);
    assertThat(subscriptions.size(), is(1));
    assertThat(subscriptions.get(0), is(subscription_1));
}
Also used : Action(org.raml.model.Action) Resource(org.raml.model.Resource) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 5 with Resource

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

the class RamlToJmsSubscriptionConverterTest method shouldCreateASchemaObjectFromARamlObject.

@SuppressWarnings("unchecked")
@Test
public void shouldCreateASchemaObjectFromARamlObject() throws Exception {
    final String componentName = "EVENT_LISTENER";
    final String contextName = "people";
    final String baseUri = "message://command/handler/message/people";
    final Raml raml = mock(Raml.class, RETURNS_DEEP_STUBS.get());
    final Resource resource_1 = mock(Resource.class);
    final Resource resource_2 = mock(Resource.class);
    final Resource resource_3 = mock(Resource.class);
    final Subscription subscription_1 = mock(Subscription.class);
    final Subscription subscription_2 = mock(Subscription.class);
    final Subscription subscription_3 = mock(Subscription.class);
    final List<Subscription> subscriptions = asList(subscription_1, subscription_2, subscription_3);
    when(raml.getBaseUri()).thenReturn(baseUri);
    when(subscriptionNamesGenerator.createContextNameFrom(baseUri)).thenReturn(contextName);
    when(raml.getResources().values()).thenReturn(asList(resource_1, resource_2, resource_3));
    when(resourcesListToSubscriptionListConverter.getSubscriptions(raml.getResources().values())).thenReturn(subscriptions);
    final SubscriptionDescriptorDef subscriptionDescriptorDef = ramlToJmsSubscriptionConverter.convert(raml, componentName);
    final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptorDef.getSubscriptionDescriptor();
    assertThat(subscriptionDescriptor.getSpecVersion(), is("1.0.0"));
    assertThat(subscriptionDescriptor.getService(), is(contextName));
    assertThat(subscriptionDescriptor.getServiceComponent(), is(componentName));
    assertThat(subscriptionDescriptor.getSubscriptions().size(), is(3));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_1));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_2));
    assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_3));
}
Also used : Raml(org.raml.model.Raml) Resource(org.raml.model.Resource) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) 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