Search in sources :

Example 6 with Position

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

the class EventsPageServiceTest 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-stĀ¬reams/" + streamId));
    final List<EventEntry> entries = emptyList();
    when(service.events(streamId, sequence, backward, 2)).thenReturn(entries);
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final Page<EventEntry> eventEntryPage = eventsPageService.pageEvents(streamId, "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 : Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) 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 7 with Position

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

the class EventsPageServiceTest method shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents.

@Test
public void shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents() throws Exception {
    final UUID streamId = randomUUID();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create("http://server:123/context/"), create("event-streams/" + streamId));
    final URL headURL = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createHeadEventsUrlLink(2, uriInfo)).thenReturn(headURL);
    final URL firstURL = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final URL previousUrl = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/2/BACKWARD/2");
    when(urlLinkFactory.createEventsUrlLink(position(2L), BACKWARD, 2, uriInfo)).thenReturn(previousUrl);
    final List<EventEntry> events = new ArrayList<>();
    final EventEntry event1 = new EventEntry(randomUUID(), streamId, 3L, "Test Name3", createObjectBuilder().add("field3", "value3").build(), new UtcClock().now().toString());
    events.add(event1);
    when(service.eventExists(streamId, 4L)).thenReturn(false);
    when(service.eventExists(streamId, 2L)).thenReturn(true);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.events(streamId, position, BACKWARD, 2L)).thenReturn(events);
    final Page<EventEntry> feedActual = eventsPageService.pageEvents(streamId, "3", BACKWARD, 2, uriInfo);
    final List<EventEntry> feed = feedActual.getData();
    final PagingLinks pagingLinks = feedActual.getPagingLinks();
    assertThat(feed, hasSize(1));
    assertThat(feed.get(0).getStreamId(), is(streamId.toString()));
    assertThat(feed.get(0).getPosition(), is(3L));
    assertThat(feed.get(0).getPayload(), is(notNullValue()));
    assertThat(pagingLinks.getPrevious().get(), is(previousUrl));
    assertThat(pagingLinks.getNext(), is(empty()));
    assertThat(pagingLinks.getHead(), is(headURL));
    assertThat(pagingLinks.getFirst(), is(firstURL));
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) 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 8 with Position

use of uk.gov.justice.services.eventsourcing.source.api.service.core.Position 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 9 with Position

use of uk.gov.justice.services.eventsourcing.source.api.service.core.Position 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)

Example 10 with Position

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

the class EventStreamPageServiceTest method shouldReturnFeedWhenSameNumberOfRecordsAsPageSizeWhenLookingForOlderEvents.

@Test
public void shouldReturnFeedWhenSameNumberOfRecordsAsPageSizeWhenLookingForOlderEvents() throws Exception {
    final UUID streamId3 = randomUUID();
    final UUID streamId4 = randomUUID();
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final EventStreamEntry event4 = new EventStreamEntry(streamId4.toString(), 4L);
    final EventStreamEntry event3 = new EventStreamEntry(streamId3.toString(), 3L);
    eventStreams.add(event4);
    eventStreams.add(event3);
    when(service.eventStreamExists(5L)).thenReturn(false);
    when(service.eventStreamExists(2L)).thenReturn(true);
    final Position position = position(4L);
    when(positionFactory.createPosition("4")).thenReturn(position);
    when(service.eventStreams(position, BACKWARD, 2L)).thenReturn(eventStreams);
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
    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 + "/" + streamId4 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId3.toString(), 2, uriInfo)).thenReturn(streamId3SelfUrl);
    final URL streamId4SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId4 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId4.toString(), 2, uriInfo)).thenReturn(streamId4SelfUrl);
    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("4", BACKWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> feed = feedActual.getData();
    final PagingLinks paging = feedActual.getPagingLinks();
    assertThat(feed, hasSize(2));
    assertThat(feed.get(0).getSelf(), is(streamId4SelfUrl.toString()));
    assertThat(feed.get(0).getSequenceNumber(), is(4L));
    assertThat(feed.get(1).getSelf(), is(streamId3SelfUrl.toString()));
    assertThat(feed.get(1).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)

Aggregations

URL (java.net.URL)11 UUID (java.util.UUID)11 Test (org.junit.Test)11 Position (uk.gov.justice.services.eventsourcing.source.api.service.core.Position)11 UUID.randomUUID (java.util.UUID.randomUUID)10 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)10 ArrayList (java.util.ArrayList)8 EventEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry)5 EventStreamEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry)5 UtcClock (uk.gov.justice.services.common.util.UtcClock)4 JsonObject (javax.json.JsonObject)2 Direction (uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)2 PathSegment (javax.ws.rs.core.PathSegment)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 UriInfo (javax.ws.rs.core.UriInfo)1