use of uk.gov.justice.subscription.domain.Subscription 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 uk.gov.justice.subscription.domain.Subscription 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 uk.gov.justice.subscription.domain.Subscription 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 uk.gov.justice.subscription.domain.Subscription 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 uk.gov.justice.subscription.domain.Subscription in project microservice_framework by CJSCommonPlatform.
the class RamlResourceToSubscriptionConverter method asSubscription.
public Subscription asSubscription(final Resource resource) {
final String resourceUri = resource.getUri();
final String subscriptionName = subscriptionNamesGenerator.createSubscriptionNameFrom(resourceUri);
final Collection<MimeType> mimeTypes = resource.getAction(POST).getBody().values();
final List<Event> events = ramlMimeTypeListToEventListConverter.toEvents(mimeTypes);
final String eventSourceName = subscriptionNamesGenerator.createEventSourceNameFrom(resourceUri);
final String jmsUri = jmsUriGenerator.createJmsUriFrom(resourceUri);
final String restUri = null;
final Eventsource eventsource = new Eventsource(eventSourceName, new Location(jmsUri, restUri));
return new Subscription(subscriptionName, events, eventsource);
}
Aggregations