Search in sources :

Example 1 with Subscription

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

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);
}
Also used : Resource(org.raml.model.Resource) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 3 with Subscription

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));
}
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 Subscription

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));
}
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 Subscription

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);
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) 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)

Aggregations

Subscription (uk.gov.justice.subscription.domain.Subscription)24 Test (org.junit.Test)19 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)14 Event (uk.gov.justice.subscription.domain.Event)12 Resource (org.raml.model.Resource)6 TypeSpec (com.squareup.javapoet.TypeSpec)5 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 Eventsource (uk.gov.justice.subscription.domain.Eventsource)4 Action (org.raml.model.Action)3 MimeType (org.raml.model.MimeType)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)3 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SubscriptionName (uk.gov.justice.services.core.cdi.SubscriptionName)2 EventSource (uk.gov.justice.services.eventsourcing.source.core.EventSource)2 Location (uk.gov.justice.subscription.domain.Location)2 File (java.io.File)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1