Search in sources :

Example 1 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventPageResourceTest method shouldCheckAccessRights.

@Test
public void shouldCheckAccessRights() throws Exception {
    final String streamId = randomUUID().toString();
    final ResteasyHttpHeaders requestHeaders = new ResteasyHttpHeaders(new MultivaluedHashMap<>());
    resource.headers = requestHeaders;
    resource.events(streamId, "3", FORWARD.toString(), 1, new ResteasyUriInfo("", "", ""));
    verify(accessControlChecker).checkAccessControl(requestHeaders);
}
Also used : ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ResteasyHttpHeaders(org.jboss.resteasy.specimpl.ResteasyHttpHeaders) Test(org.junit.Test)

Example 2 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo 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 ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo 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 ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForNewerEvents.

@Test
public void shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForNewerEvents() throws Exception {
    final UUID streamId3 = randomUUID();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final EventStreamEntry eventStreamEntry1 = new EventStreamEntry(streamId3.toString(), 3L);
    eventStreams.add(eventStreamEntry1);
    when(service.eventStreamExists(4L)).thenReturn(true);
    when(service.eventStreamExists(2L)).thenReturn(false);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.eventStreams(position, FORWARD, 2)).thenReturn(eventStreams);
    final URL streamId3SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + streamId3 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId3.toString(), 2, uriInfo)).thenReturn(streamId3SelfUrl);
    final URL nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/4/FORWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(4L), FORWARD, 2, uriInfo)).thenReturn(nextUrl);
    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 + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final Page<EventStreamPageEntry> pageEvents = eventStreamPageService.pageOfEventStream("3", FORWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> pageEventsData = pageEvents.getData();
    final PagingLinks pagingLinks = pageEvents.getPagingLinks();
    assertThat(pageEventsData, hasSize(1));
    assertThat(pageEventsData.get(0).getSelf(), is(streamId3SelfUrl.toString()));
    assertThat(pageEventsData.get(0).getSequenceNumber(), is(3L));
    assertThat(pagingLinks.getPrevious(), is(Optional.empty()));
    assertThat(pagingLinks.getNext().get(), is(nextUrl));
    assertThat(pagingLinks.getHead(), is(headURL));
    assertThat(pagingLinks.getFirst(), is(firstURL));
}
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) ArrayList(java.util.ArrayList) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) URL(java.net.URL) Test(org.junit.Test)

Example 5 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventStreamPageServiceTest method shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents.

@Test
public void shouldReturnEventsWhenLessRecordsThanPageSizeWhenLookingForOlderEvents() throws Exception {
    final UUID streamId3 = randomUUID();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create("http://server:123/context/"), create("event-streams/"));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final EventStreamEntry eventsStream1 = new EventStreamEntry(streamId3.toString(), 3L);
    eventStreams.add(eventsStream1);
    when(service.eventStreamExists(4L)).thenReturn(false);
    when(service.eventStreamExists(2L)).thenReturn(true);
    final Position position = position(3L);
    when(positionFactory.createPosition("3")).thenReturn(position);
    when(service.eventStreams(position, BACKWARD, 2L)).thenReturn(eventStreams);
    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 + "/1/FORWARD/2");
    when(urlLinkFactory.createFirstEventStreamsUrlLink(2, uriInfo)).thenReturn(firstURL);
    final URL streamId3SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId3 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId3.toString(), 2, uriInfo)).thenReturn(streamId3SelfUrl);
    final URL previousUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/2/BACKWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(2L), BACKWARD, 2, uriInfo)).thenReturn(previousUrl);
    final Page<EventStreamPageEntry> feedActual = eventStreamPageService.pageOfEventStream("3", BACKWARD, PAGE_SIZE, uriInfo);
    final List<EventStreamPageEntry> feed = feedActual.getData();
    final PagingLinks paging = feedActual.getPagingLinks();
    assertThat(feed, hasSize(1));
    assertThat(feed.get(0).getSelf(), is(streamId3SelfUrl.toString()));
    assertThat(feed.get(0).getSequenceNumber(), is(3L));
    assertThat(paging.getNext(), is(Optional.empty()));
    assertThat(paging.getPrevious().get(), is(previousUrl));
    assertThat(paging.getHead(), is(headURL));
    assertThat(paging.getFirst(), is(firstURL));
}
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) ArrayList(java.util.ArrayList) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)24 Test (org.junit.Test)23 URL (java.net.URL)20 UUID (java.util.UUID)14 UUID.randomUUID (java.util.UUID.randomUUID)14 ArrayList (java.util.ArrayList)12 EventEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry)10 Position (uk.gov.justice.services.eventsourcing.source.api.service.core.Position)10 EventStreamEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry)7 UriInfo (javax.ws.rs.core.UriInfo)6 UtcClock (uk.gov.justice.services.common.util.UtcClock)6 Page (uk.gov.justice.services.eventsourcing.source.api.service.Page)6 Direction (uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)4 EventStreamPageEntry (uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry)3 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ResteasyHttpHeaders (org.jboss.resteasy.specimpl.ResteasyHttpHeaders)2 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)1 Swagger (io.swagger.models.Swagger)1 URI (java.net.URI)1