Search in sources :

Example 11 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project stdlib by petergeneric.

the class WebQueryTest method testParseQueryStringToWebQuery.

@Test
public void testParseQueryStringToWebQuery() {
    WebQuery expected = new WebQuery().logSQL(true).eq("id", "123").offset(0).limit(200);
    WebQuery actual = new WebQuery().decode(new ResteasyUriInfo(URI.create("http://example.com?_log_sql=true&id=123")));
    assertEquals(expected.encode().toString(), actual.encode().toString());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Test(org.junit.Test)

Example 12 with ResteasyUriInfo

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

the class EventStreamPageResourceTest method shouldCheckAccessRights.

@Test
public void shouldCheckAccessRights() throws Exception {
    final ResteasyHttpHeaders requestHeaders = new ResteasyHttpHeaders(new MultivaluedHashMap<>());
    resource.headers = requestHeaders;
    resource.events("3", FORWARD.toString(), PAGE_SIZE, 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 13 with ResteasyUriInfo

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

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

the class EventStreamPageServiceTest method shouldReturnLinkForNextPageIfOnLast.

@Test
public void shouldReturnLinkForNextPageIfOnLast() throws Exception {
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo(create(BASE_URL), create(EVENT_STREAM_PATH));
    final List<EventStreamEntry> eventStreams = new ArrayList<>();
    final String streamId2 = randomUUID().toString();
    final EventStreamEntry event1 = new EventStreamEntry(streamId2, 2L);
    final String streamId1 = randomUUID().toString();
    final EventStreamEntry event2 = new EventStreamEntry(streamId1, 1L);
    eventStreams.add(event2);
    eventStreams.add(event1);
    when(service.eventStreamExists(3L)).thenReturn(true);
    when(positionFactory.createPosition(FIRST)).thenReturn(first());
    when(service.eventStreams(first(), FORWARD, 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 streamId2SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId2, 2, uriInfo)).thenReturn(streamId2SelfUrl);
    final URL streamId1SelfUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/" + streamId2 + "/HEAD/BACKWARD/2");
    when(urlLinkFactory.createEventStreamSelfUrlLink(streamId1, 2, uriInfo)).thenReturn(streamId1SelfUrl);
    final URL nextUrl = new URL(BASE_URL + EVENT_STREAM_PATH + "/3/FORWARD/2");
    when(urlLinkFactory.createEventStreamUrlLink(position(3L), FORWARD, 2, uriInfo)).thenReturn(nextUrl);
    final Page<EventStreamPageEntry> feed = eventStreamPageService.pageOfEventStream(FIRST, FORWARD, PAGE_SIZE, uriInfo);
    assertTrue(feed.getPagingLinks().getNext().get().toString().equals("http://server:123/context/event-streams/" + 3 + "/" + FORWARD + "/" + 2L));
    assertTrue(feed.getPagingLinks().getPrevious().equals(Optional.empty()));
    assertThat(feed.getPagingLinks().getHead().toString(), is("http://server:123/context/event-streams/HEAD/BACKWARD/2"));
    assertThat(feed.getPagingLinks().getFirst().toString(), is("http://server:123/context/event-streams/1/FORWARD/2"));
}
Also used : EventStreamEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.junit.Test)

Example 15 with ResteasyUriInfo

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

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