Search in sources :

Example 6 with Page

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));
}
Also used : ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) Direction(uk.gov.justice.services.eventsourcing.source.api.service.core.Direction) URL(java.net.URL) EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) JsonObjectBuilder(javax.json.JsonObjectBuilder) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 7 with Page

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);
}
Also used : EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) URL(java.net.URL) Test(org.junit.Test)

Example 8 with Page

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);
}
Also used : Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Page (uk.gov.justice.services.eventsourcing.source.api.service.Page)8 URL (java.net.URL)6 UriInfo (javax.ws.rs.core.UriInfo)6 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)6 Test (org.junit.Test)6 EventStreamPageEntry (uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry)3 EventEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry)3 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Direction (uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)2