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