Search in sources :

Example 1 with EventStreamEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForNewerEvents.

@Test
public void shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForNewerEvents() throws Exception {
    final UUID streamId3 = randomUUID();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final EventStreamEntry eventStreamEntry1 = new EventStreamEntry(streamId3.toString(), 3L);
    eventStreams.add(eventStreamEntry1);
    when(service.eventStreamExists(4L)).thenReturn(true);
    when(service.eventStreamExists(2L)).thenReturn(false);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.eventStreams(position, FORWARD, 2)).thenReturn(eventStreams);
    final URL streamId3SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + streamId3 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId3.toString(), 2, uriInfo)).thenReturn(streamId3SelfUrl);
    final URL nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/4/FORWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(4L), FORWARD, 2, uriInfo)).thenReturn(nextUrl);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventStreamsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final Page<EventStreamPageEntry> pageEvents = eventStreamPageService.pageOfEventStream("3", FORWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> pageEventsData = pageEvents.getData();
    final PagingLinks pagingLinks = pageEvents.getPagingLinks();
    assertThat(pageEventsData, hasSize(1));
    assertThat(pageEventsData.get(0).getSelf(), is(streamId3SelfUrl.toString()));
    assertThat(pageEventsData.get(0).getSequenceNumber(), is(3L));
    assertThat(pagingLinks.getPrevious(), is(Optional.empty()));
    assertThat(pagingLinks.getNext().get(), is(nextUrl));
    assertThat(pagingLinks.getHead(), is(headURL));
    assertThat(pagingLinks.getFirst(), is(firstURL));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ArrayList(java.util.ArrayList) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) URL(java.net.URL) Test(org.junit.Test)

Example 2 with EventStreamEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents.

@Test
public void shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents() throws Exception {
    final UUID streamId3 = randomUUID();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create("http://server:123/context/"), create("event-streams/"));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final EventStreamEntry eventsStream1 = new EventStreamEntry(streamId3.toString(), 3L);
    eventStreams.add(eventsStream1);
    when(service.eventStreamExists(4L)).thenReturn(false);
    when(service.eventStreamExists(2L)).thenReturn(true);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.eventStreams(position, BACKWARD, 2L)).thenReturn(eventStreams);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventStreamsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final URL streamId3SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId3 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId3.toString(), 2, uriInfo)).thenReturn(streamId3SelfUrl);
    final URL previousUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/2/BACKWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(2L), BACKWARD, 2, uriInfo)).thenReturn(previousUrl);
    final Page<EventStreamPageEntry> feedActual = eventStreamPageService.pageOfEventStream("3", BACKWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> feed = feedActual.getData();
    final PagingLinks paging = feedActual.getPagingLinks();
    assertThat(feed, hasSize(1));
    assertThat(feed.get(0).getSelf(), is(streamId3SelfUrl.toString()));
    assertThat(feed.get(0).getSequenceNumber(), is(3L));
    assertThat(paging.getNext(), is(Optional.empty()));
    assertThat(paging.getPrevious().get(), is(previousUrl));
    assertThat(paging.getHead(), is(headURL));
    assertThat(paging.getFirst(), is(firstURL));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ArrayList(java.util.ArrayList) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) URL(java.net.URL) Test(org.junit.Test)

Example 3 with EventStreamEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnLinkForNextPageIfOnLast.

@Test
public void shouldReturnLinkForNextPageIfOnLast() throws Exception {
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final String streamId2 = randomUUID().toString();
    final EventStreamEntry event1 = new EventStreamEntry(streamId2, 2L);
    final String streamId1 = randomUUID().toString();
    final EventStreamEntry event2 = new EventStreamEntry(streamId1, 1L);
    eventStreams.add(event2);
    eventStreams.add(event1);
    when(service.eventStreamExists(3L)).thenReturn(true);
    when(positionFactory.createPosition(FIRST)).thenReturn(first());
    when(service.eventStreams(first(), FORWARD, 2L)).thenReturn(eventStreams);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventStreamsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final URL streamId2SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId2, 2, uriInfo)).thenReturn(streamId2SelfUrl);
    final URL streamId1SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId1, 2, uriInfo)).thenReturn(streamId1SelfUrl);
    final URL nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/3/FORWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(3L), FORWARD, 2, uriInfo)).thenReturn(nextUrl);
    final Page<EventStreamPageEntry> feed = eventStreamPageService.pageOfEventStream(FIRST, FORWARD, PAGE_SIZE, uriInfo);
    assertTrue(feed.getPagingLinks().getNext().get().toString().equals("http://server:123/context/event-streams/" + 3 + "/" + FORWARD + "/" + 2L));
    assertTrue(feed.getPagingLinks().getPrevious().equals(Optional.empty()));
    assertThat(feed.getPagingLinks().getHead().toString(), is("http://server:123/context/event-streams/HEAD/BACKWARD/2"));
    assertThat(feed.getPagingLinks().getFirst().toString(), is("http://server:123/context/event-streams/1/FORWARD/2"));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.junit.Test)

Example 4 with EventStreamEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnEmptyListWithPagingLinks.

@Test
public void shouldReturnEmptyListWithPagingLinks() throws Exception {
    final UUID streamId = randomUUID();
    final Position sequence = position(3L);
    final Direction backward = BACKWARD;
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create("http://server:123/context/"), create("event-streams/" + streamId));
    final List<EventStreamEntry> entries = emptyList();
    when(service.eventStreams(sequence, backward, 2)).thenReturn(entries);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventStreamsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final Page<EventStreamPageEntry> eventEntryPage = eventStreamPageService.pageOfEventStream("3", backward, 2, uriInfo);
    assertThat(eventEntryPage.getData(), is(entries));
    assertThat(eventEntryPage.getPagingLinks().getFirst(), is(firstURL));
    assertThat(eventEntryPage.getPagingLinks().getHead(), is(headURL));
    assertThat(eventEntryPage.getPagingLinks().getNext(), is(empty()));
    assertThat(eventEntryPage.getPagingLinks().getPrevious(), is(empty()));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Direction(uk.gov.justice.services.eventsourcing.source.api.service.core.Direction) URL(java.net.URL) Test(org.junit.Test)

Example 5 with EventStreamEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnFeedWhenSameNumberOfRecordsAsPageSizeWhenLookingForNewerEvents.

@Test
public void shouldReturnFeedWhenSameNumberOfRecordsAsPageSizeWhenLookingForNewerEvents() throws Exception {
    final UUID streamId1 = randomUUID();
    final UUID streamId2 = randomUUID();
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create("http://server:123/context/"), create("event-streams/"));
    final EventStreamEntry eventsStream1 = new EventStreamEntry(streamId1.toString(), 1L);
    final EventStreamEntry eventsStream2 = new EventStreamEntry(streamId2.toString(), 2L);
    eventStreams.add(eventsStream2);
    eventStreams.add(eventsStream1);
    when(service.eventStreamExists(3L)).thenReturn(true);
    when(service.eventStreamExists(0L)).thenReturn(false);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.eventStreams(position, FORWARD, 2L)).thenReturn(eventStreams);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventStreamsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final URL nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/3/FORWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position, FORWARD, 2, uriInfo)).thenReturn(nextUrl);
    final URL streamId2SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId2.toString(), 2, uriInfo)).thenReturn(streamId2SelfUrl);
    final URL streamId1SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId1 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId1.toString(), 2, uriInfo)).thenReturn(streamId1SelfUrl);
    final Page<EventStreamPageEntry> feedActual = eventStreamPageService.pageOfEventStream("3", FORWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> feed = feedActual.getData();
    final PagingLinks paging = feedActual.getPagingLinks();
    assertThat(feed, hasSize(2));
    assertThat(feed.get(0).getSelf(), is(streamId2SelfUrl.toString()));
    assertThat(feed.get(0).getSequenceNumber(), is(2L));
    assertThat(feed.get(1).getSelf(), is(streamId1SelfUrl.toString()));
    assertThat(feed.get(1).getSequenceNumber(), is(1L));
    assertThat(paging.getPrevious(), is(Optional.empty()));
    assertThat(paging.getNext().get(), is(nextUrl));
    assertThat(paging.getHead(), is(headURL));
    assertThat(paging.getFirst(), is(firstURL));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ArrayList(java.util.ArrayList) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URL (java.net.URL)8 EventStreamEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry)8 ArrayList (java.util.ArrayList)7 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)7 Test (org.junit.Test)7 UUID (java.util.UUID)5 UUID.randomUUID (java.util.UUID.randomUUID)5 Position (uk.gov.justice.services.eventsourcing.source.api.service.core.Position)5 Direction (uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)1