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