Search in sources :

Example 1 with Page

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

the class EventPageResource method events.

@GET
@Produces("application/vnd.event-source.events+json")
public JsonValue events(@PathParam("streamId") final String streamId, @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.pageEvents(UUID.fromString(streamId), 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)

Example 2 with Page

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

the class EventStreamPageResourceTest method shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection.

@Test(expected = BadRequestException.class)
public void shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection() 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<EventStreamPageEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
    when(eventsStreamPageService.pageOfEventStream(FIRST, BACKWARD, PAGE_SIZE, uriInfo)).thenReturn(page);
    resource.events(FIRST, BACKWARD.toString(), PAGE_SIZE, uriInfo);
}
Also used : EventStreamPageEntry(uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry) 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 3 with Page

use of uk.gov.justice.services.eventsourcing.source.api.service.Page 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));
}
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) EventStreamPageEntry(uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry) 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 4 with Page

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

the class EventStreamPageResourceTest 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<EventStreamPageEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
    when(eventsStreamPageService.pageOfEventStream(HEAD, FORWARD, PAGE_SIZE, uriInfo)).thenReturn(page);
    resource.events(HEAD, FORWARD.toString(), PAGE_SIZE, uriInfo);
}
Also used : EventStreamPageEntry(uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry) 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 5 with Page

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

the class EventPageResourceTest method shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection.

@Test(expected = BadRequestException.class)
public void shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection() 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), FIRST, BACKWARD, 10, uriInfo)).thenReturn(page);
    resource.events(streamId, FIRST, BACKWARD.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)

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