Search in sources :

Example 1 with Direction

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));
}
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 2 with Direction

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

Example 3 with Direction

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()));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) Position(uk.gov.justice.services.eventsourcing.source.api.service.core.Position) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Direction(uk.gov.justice.services.eventsourcing.source.api.service.core.Direction) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Direction

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));
}
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 5 with Direction

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();
}
Also used : Direction(uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)

Aggregations

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