use of org.jboss.resteasy.spi.ResteasyUriInfo 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));
}
use of org.jboss.resteasy.spi.ResteasyUriInfo 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));
}
use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.
the class EventStreamPageServiceTest method shouldReturnLinkForPreviousPageIfOnHead.
@Test
public void shouldReturnLinkForPreviousPageIfOnHead() throws Exception {
final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
final List<EventStreamEntry> eventStreams = new ArrayList<>();
String streamId2 = randomUUID().toString();
final EventStreamEntry event2 = new EventStreamEntry(streamId2, 2L);
String streamId3 = randomUUID().toString();
final EventStreamEntry event3 = new EventStreamEntry(streamId3, 3L);
eventStreams.add(event3);
eventStreams.add(event2);
when(service.eventStreamExists(1L)).thenReturn(true);
when(positionFactory.createPosition(HEAD)).thenReturn(head());
when(service.eventStreams(head(), 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, 2, uriInfo)).thenReturn(streamId3SelfUrl);
final URL streamId2SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
when(urlLinkFactory.createEventStreamSelfUrlLink(streamId2, 2, uriInfo)).thenReturn(streamId2SelfUrl);
final URL previousUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/1/BACKWARD/2");
when(urlLinkFactory.createEventStreamUrlLink(position(1L), BACKWARD, 2, uriInfo)).thenReturn(previousUrl);
final Page<EventStreamPageEntry> pageOfEventStream = eventStreamPageService.pageOfEventStream(HEAD, BACKWARD, PAGE_SIZE, uriInfo);
assertTrue(pageOfEventStream.getPagingLinks().getNext().equals(Optional.empty()));
PagingLinks pagingLinks = pageOfEventStream.getPagingLinks();
assertTrue(pagingLinks.getPrevious().get().toString().equals(previousUrl.toString()));
assertThat(pagingLinks.getHead(), is(headURL));
assertThat(pagingLinks.getFirst(), is(firstURL));
}
use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.
the class EventsPageServiceTest method shouldReturnLinkForPage2IfOnLast.
@Test
public void shouldReturnLinkForPage2IfOnLast() throws Exception {
final UUID streamId = randomUUID();
final List<EventEntry> events = new ArrayList<>();
final EventEntry event1 = new EventEntry(randomUUID(), streamId, 1L, "Test Name1", createObjectBuilder().add("field1", "value1").build(), new UtcClock().now().toString());
final EventEntry event2 = new EventEntry(randomUUID(), streamId, 2L, "Test Name2", createObjectBuilder().add("field2", "value2").build(), new UtcClock().now().toString());
events.add(event2);
events.add(event1);
when(service.eventExists(streamId, 3L)).thenReturn(true);
when(positionFactory.createPosition("1")).thenReturn(first());
when(service.events(streamId, first(), FORWARD, 2L)).thenReturn(events);
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 nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + streamId + "/3/FORWARD/2");
when(urlLinkFactory.createEventsUrlLink(position(3L), FORWARD, 2, uriInfo)).thenReturn(nextUrl);
final Page<EventEntry> feed = eventsPageService.pageEvents(streamId, FIRST, FORWARD, 2, uriInfo);
final PagingLinks pagingLinks = feed.getPagingLinks();
assertThat(pagingLinks.getNext().get(), is(nextUrl));
assertThat(pagingLinks.getPrevious(), is(empty()));
assertThat(pagingLinks.getHead(), is(headURL));
assertThat(pagingLinks.getFirst(), is(firstURL));
}
use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.
the class EventsPageServiceTest method shouldReturnResultWhenSameNumberOfRecordsAsPageSizeWhenLookingForOlderEvents.
@Test
public void shouldReturnResultWhenSameNumberOfRecordsAsPageSizeWhenLookingForOlderEvents() throws Exception {
final UUID streamId = randomUUID();
final List<EventEntry> events = new ArrayList<>();
final JsonObject payloadEvent4 = createObjectBuilder().add("field4", "value4").build();
final JsonObject payloadEvent3 = createObjectBuilder().add("field3", "value3").build();
final EventEntry event4 = new EventEntry(randomUUID(), streamId, 4L, "Test Name4", payloadEvent4, new UtcClock().now().toString());
final EventEntry event3 = new EventEntry(randomUUID(), streamId, 3L, "Test Name3", payloadEvent3, new UtcClock().now().toString());
events.add(event4);
events.add(event3);
when(service.eventExists(streamId, 5L)).thenReturn(false);
when(service.eventExists(streamId, 2L)).thenReturn(true);
final Position position = position(4L);
when(positionFactory.createPosition("4")).thenReturn(position);
when(service.events(streamId, position, BACKWARD, 2)).thenReturn(events);
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 Page<EventEntry> feedActual = eventsPageService.pageEvents(streamId, "4", BACKWARD, 2, uriInfo);
final List<EventEntry> feed = feedActual.getData();
final PagingLinks pagingLinks = feedActual.getPagingLinks();
assertThat(feed, hasSize(2));
assertThat(feed.get(0).getStreamId(), is(streamId.toString()));
assertThat(feed.get(0).getPosition(), is(4L));
assertThat(feed.get(0).getPayload(), is(payloadEvent4));
assertThat(feed.get(1).getStreamId(), is(streamId.toString()));
assertThat(feed.get(1).getPosition(), is(3L));
assertThat(feed.get(1).getPayload(), is(payloadEvent3));
assertThat(pagingLinks.getNext(), is(empty()));
assertThat(pagingLinks.getPrevious().get(), is(previousUrl));
assertThat(pagingLinks.getHead(), is(headURL));
assertThat(pagingLinks.getFirst(), is(firstURL));
}
Aggregations