use of uk.gov.justice.services.eventsourcing.source.api.service.Page 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.Page in project microservice_framework by CJSCommonPlatform.
the class EventPageResourceTest method shouldReturnBadRequestWhenHeadEventsRequestedWithForwardDirection.
@Test(expected = BadRequestException.class)
public void shouldReturnBadRequestWhenHeadEventsRequestedWithForwardDirection() throws Exception {
final String streamId = randomUUID().toString();
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(UUID.fromString(streamId), HEAD, FORWARD, 10, uriInfo)).thenReturn(page);
resource.events(streamId, HEAD, FORWARD.toString(), 10, uriInfo);
}
use of uk.gov.justice.services.eventsourcing.source.api.service.Page in project microservice_framework by CJSCommonPlatform.
the class EventStreamPageResource method events.
@GET
@Produces("application/vnd.event-source.events+json")
public JsonValue events(@PathParam("position") final String position, @PathParam("direction") final String direction, @PathParam("pageSize") final int pageSize, @Context final UriInfo uriInfo) throws MalformedURLException {
validateRequest(position, direction);
accessController.checkAccessControl(headers);
final Page page = eventsPageService.pageOfEventStream(position, valueOf(direction), pageSize, uriInfo);
return converter.convert(page);
}
Aggregations