NotificationsResource { @GET @Path("/notifications/") @Timed public Response listNotifications(@Context UriInfo uriInfo, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFICATION_USER); List<QueryParam> queryParams = new ArrayList<>(); MultivaluedMap<String, String> uriInfoParams = uriInfo.getQueryParameters(); Collection<Notification> notifications = null; if (!uriInfoParams.isEmpty()) { queryParams = WSUtils.buildQueryParameters(uriInfoParams); } else { LOG.info("Query params empty, will use default criteria to return notifications."); } notifications = notificationService.findNotifications(queryParams); if (notifications != null && !notifications.isEmpty()) { return WSUtils.respondEntities(notifications, OK); } throw EntityNotFoundException.byFilter(queryParams.toString()); } NotificationsResource(StreamlineAuthorizer authorizer, NotificationService service); @GET @Path("/notifications/{id}") @Timed Response getNotificationById(@PathParam("id") String id,
                                        @Context SecurityContext securityContext); @GET @Path("/notifications/") @Timed Response listNotifications(@Context UriInfo uriInfo, @Context SecurityContext securityContext); @PUT @Path("/notifications/{id}/{status}") @Timed Response updateNotificationStatus(@PathParam("id") String notificationId,
                                             @PathParam("status") Notification.Status status,
                                             @Context SecurityContext securityContext); @GET @Path("/events/{id}") @Timed Response getEventById(@PathParam("id") String id,
                                 @Context SecurityContext securityContext);  }
@Test public void testListNotifications() throws Exception { final MultivaluedMap<String, String> qp = new MultivaluedHashMap<String, String>() { { putSingle("status", "DELIVERED"); putSingle("notifierName", "console_notifier"); putSingle("startTs", "1444625166800"); putSingle("endTs", "1444625166810"); } }; new Expectations() { { mockUriInfo.getQueryParameters(); times = 1; result = qp; } }; try { resource.listNotifications(mockUriInfo, securityContext); fail("We don't mock the result so it should throw entity not found"); } catch (EntityNotFoundException e) { new Verifications() { { List<QueryParam> qps; mockNotificationService.findNotifications(qps = withCapture()); assertEquals(4, qps.size()); } }; } }