use of uk.gov.justice.services.eventsourcing.source.api.service.core.Direction in project microservice_framework by CJSCommonPlatform.
the class EventStreamPageResourceTest method shouldReturnFeedReturnedByService.
@Test
public void shouldReturnFeedReturnedByService() throws Exception {
final UUID streamId = randomUUID();
final UriInfo uriInfo = new ResteasyUriInfo("" + "/" + streamId, "", "");
final URL fixedUrl = new URL("http://localhost:8080/rest/fixed");
final Page<EventStreamPageEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
final String position = FIRST;
when(eventsStreamPageService.pageOfEventStream(position, FORWARD, PAGE_SIZE, uriInfo)).thenReturn(page);
final JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
jsonObjectBuilder.add("key", "value");
when(converter.convert(page)).thenReturn(jsonObjectBuilder.build());
resource.events(FIRST, FORWARD.toString(), PAGE_SIZE, uriInfo);
final ArgumentCaptor<String> positionCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Integer> pageSizeCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<UriInfo> uriInfoCaptor = ArgumentCaptor.forClass(UriInfo.class);
final ArgumentCaptor<Direction> directionCaptor = ArgumentCaptor.forClass(Direction.class);
verify(eventsStreamPageService).pageOfEventStream(positionCaptor.capture(), directionCaptor.capture(), pageSizeCaptor.capture(), uriInfoCaptor.capture());
assertThat(positionCaptor.getValue(), is(position));
assertThat(pageSizeCaptor.getValue(), is(PAGE_SIZE));
assertThat(uriInfoCaptor.getValue(), is(uriInfo));
assertThat(directionCaptor.getValue(), is(FORWARD));
}
use of uk.gov.justice.services.eventsourcing.source.api.service.core.Direction 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()));
}
use of uk.gov.justice.services.eventsourcing.source.api.service.core.Direction 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()));
}
use of uk.gov.justice.services.eventsourcing.source.api.service.core.Direction in project microservice_framework by CJSCommonPlatform.
the class EventPageResourceTest method shouldReturnFeedReturnedByService.
@Test
public void shouldReturnFeedReturnedByService() throws Exception {
final UUID streamId = randomUUID();
final String position = "2";
final String positionValue = "2";
final int pageSize = 10;
final UriInfo uriInfo = new ResteasyUriInfo("" + "/" + streamId, "", "");
final URL fixedUrl = new URL("http://localhost:8080/rest/fixed");
final Page<EventEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
when(eventsPageService.pageEvents(streamId, position, FORWARD, pageSize, uriInfo)).thenReturn(page);
final JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
jsonObjectBuilder.add("key", "value");
when(converter.convert(page)).thenReturn(jsonObjectBuilder.build());
resource.events(streamId.toString(), positionValue, FORWARD.toString(), pageSize, uriInfo);
final ArgumentCaptor<UUID> uuidArgumentCaptor = ArgumentCaptor.forClass(UUID.class);
final ArgumentCaptor<String> positionCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Integer> pageSizeCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<UriInfo> uriInfoCaptor = ArgumentCaptor.forClass(UriInfo.class);
final ArgumentCaptor<Direction> directionCaptor = ArgumentCaptor.forClass(Direction.class);
verify(eventsPageService).pageEvents(uuidArgumentCaptor.capture(), positionCaptor.capture(), directionCaptor.capture(), pageSizeCaptor.capture(), uriInfoCaptor.capture());
assertThat(positionCaptor.getValue(), is(position));
assertThat(pageSizeCaptor.getValue(), is(pageSize));
assertThat(uriInfoCaptor.getValue(), is(uriInfo));
assertThat(directionCaptor.getValue(), is(FORWARD));
assertThat(uuidArgumentCaptor.getValue(), is(streamId));
}
use of uk.gov.justice.services.eventsourcing.source.api.service.core.Direction in project microservice_framework by CJSCommonPlatform.
the class UrlLinkFactory method urlDirection.
private String urlDirection(final Position position, final Direction direction) {
final Direction firstDirection = position.equals(first()) ? FORWARD : direction;
final Direction finalDirection = position.equals(head()) ? BACKWARD : firstDirection;
return finalDirection.toString();
}
Aggregations