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());
}
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);
}
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);
}
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"));
}
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()));
}
Aggregations