Search in sources :

Example 1 with Eventsource

use of uk.gov.justice.subscription.domain.Eventsource 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 Eventsource

use of uk.gov.justice.subscription.domain.Eventsource 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)

Example 3 with Eventsource

use of uk.gov.justice.subscription.domain.Eventsource in project microservice_framework by CJSCommonPlatform.

the class EventsourceBuilderTest method shouldBuildAnEventsource.

@Test
public void shouldBuildAnEventsource() throws Exception {
    final String name = "name";
    final Location location = mock(Location.class);
    final Eventsource eventsource = eventsource().withName(name).withLocation(location).build();
    assertThat(eventsource.getName(), is(name));
    assertThat(eventsource.getLocation(), is(location));
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) Location(uk.gov.justice.subscription.domain.Location) Test(org.junit.Test)

Example 4 with Eventsource

use of uk.gov.justice.subscription.domain.Eventsource in project microservice_framework by CJSCommonPlatform.

the class SubscriptionBuilderTest method shouldBeAbleToAddEventsOneAtATime.

@Test
public void shouldBeAbleToAddEventsOneAtATime() throws Exception {
    final String name = "name";
    final Event event_1 = mock(Event.class);
    final Event event_2 = mock(Event.class);
    final Eventsource eventsource = mock(Eventsource.class);
    final Subscription subscription = subscription().withName(name).withEvent(event_1).withEvent(event_2).withEventsource(eventsource).build();
    assertThat(subscription.getName(), is(name));
    assertThat(subscription.getEventsource(), is(eventsource));
    assertThat(subscription.getEvents(), hasItem(event_1));
    assertThat(subscription.getEvents(), hasItem(event_2));
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Example 5 with Eventsource

use of uk.gov.justice.subscription.domain.Eventsource in project microservice_framework by CJSCommonPlatform.

the class SubscriptionBuilderTest method shouldBuildASubscription.

@Test
public void shouldBuildASubscription() throws Exception {
    final String name = "name";
    final Event event_1 = mock(Event.class);
    final Event event_2 = mock(Event.class);
    final Eventsource eventsource = mock(Eventsource.class);
    final Subscription subscription = subscription().withName(name).withEvents(asList(event_1, event_2)).withEventsource(eventsource).build();
    assertThat(subscription.getName(), is(name));
    assertThat(subscription.getEventsource(), is(eventsource));
    assertThat(subscription.getEvents(), hasItem(event_1));
    assertThat(subscription.getEvents(), hasItem(event_2));
}
Also used : Eventsource(uk.gov.justice.subscription.domain.Eventsource) Event(uk.gov.justice.subscription.domain.Event) Subscription(uk.gov.justice.subscription.domain.Subscription) Test(org.junit.Test)

Aggregations

Eventsource (uk.gov.justice.subscription.domain.Eventsource)5 Test (org.junit.Test)4 Event (uk.gov.justice.subscription.domain.Event)4 Subscription (uk.gov.justice.subscription.domain.Subscription)4 Location (uk.gov.justice.subscription.domain.Location)3 MimeType (org.raml.model.MimeType)2 Resource (org.raml.model.Resource)1