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