Search in sources :

Example 1 with EventStreamPageEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry 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 2 with EventStreamPageEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry 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 3 with EventStreamPageEntry

use of uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry 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)

Aggregations

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