@Test public void testFindNotifications() throws Exception { new Expectations() { { mockCtx.getConfig(); times = 3; result = mockNotifierConfig; mockNotifierConfig.getClassName(); times = 1; result = "Test"; mockNotifierConfig.getJarPath(); times = 1; result = "/tmp/test.jar"; mockProxyUtil.loadClassFromJar("/tmp/test.jar", "Test"); result = mockNotifier; } }; notificationService.register("test_notifier", mockCtx); QueryParam qp1 = new QueryParam("one", "1"); QueryParam qp2 = new QueryParam("two", "2"); QueryParam qp3 = new QueryParam("numRows", "5"); notificationService.findNotifications(Arrays.asList(qp1, qp2, qp3)); new Verifications() { { Criteria<Notification> criteria; mockNotificationStore.findEntities(criteria = withCapture()); assertEquals(criteria.clazz(), Notification.class); assertEquals(criteria.numRows(), 5); assertEquals(criteria.fieldRestrictions().size(), 2); assertEquals(criteria.fieldRestrictions().get(0).getValue(), "1"); assertEquals(criteria.fieldRestrictions().get(1).getValue(), "2"); } }; notificationService.findNotifications(Arrays.asList(qp1, qp2)); new Verifications() { { Criteria<Notification> criteria; mockNotificationStore.findEntities(criteria = withCapture()); assertEquals(criteria.clazz(), Notification.class); assertEquals(0, criteria.numRows()); assertEquals(criteria.fieldRestrictions().size(), 2); assertEquals(criteria.fieldRestrictions().get(0).getValue(), "1"); assertEquals(criteria.fieldRestrictions().get(1).getValue(), "2"); } }; }
@Override public List<Notification> findNotifications(List<QueryParam> queryParams) { LOG.debug("findNotifications with queryParams {}", queryParams); CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class); for (QueryParam qp : queryParams) { if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) { criteria.setNumRows(Integer.parseInt(qp.value)); } else if (qp.name.equals(QUERY_PARAM_START_TS)) { criteria.setStartTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_END_TS))) { criteria.setEndTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_DESC))) { criteria.setDescending(true); } else { criteria.addFieldRestriction(qp.name, qp.value); } } LOG.debug("Finding entities from notification store with criteria {}", criteria); return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList()); }
NotificationServiceImpl implements NotificationService { @Override public List<Notification> findNotifications(List<QueryParam> queryParams) { LOG.debug("findNotifications with queryParams {}", queryParams); CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class); for (QueryParam qp : queryParams) { if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) { criteria.setNumRows(Integer.parseInt(qp.value)); } else if (qp.name.equals(QUERY_PARAM_START_TS)) { criteria.setStartTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_END_TS))) { criteria.setEndTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_DESC))) { criteria.setDescending(true); } else { criteria.addFieldRestriction(qp.name, qp.value); } } LOG.debug("Finding entities from notification store with criteria {}", criteria); return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList()); } }
NotificationServiceImpl implements NotificationService { @Override public List<Notification> findNotifications(List<QueryParam> queryParams) { LOG.debug("findNotifications with queryParams {}", queryParams); CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class); for (QueryParam qp : queryParams) { if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) { criteria.setNumRows(Integer.parseInt(qp.value)); } else if (qp.name.equals(QUERY_PARAM_START_TS)) { criteria.setStartTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_END_TS))) { criteria.setEndTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_DESC))) { criteria.setDescending(true); } else { criteria.addFieldRestriction(qp.name, qp.value); } } LOG.debug("Finding entities from notification store with criteria {}", criteria); return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList()); } NotificationServiceImpl();  NotificationServiceImpl(NotificationStore store);  NotificationServiceImpl(Map<String, Object> config);  NotificationServiceImpl(Map<String, Object> config, NotificationStore store); }
NotificationServiceImpl implements NotificationService { @Override public List<Notification> findNotifications(List<QueryParam> queryParams) { LOG.debug("findNotifications with queryParams {}", queryParams); CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class); for (QueryParam qp : queryParams) { if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) { criteria.setNumRows(Integer.parseInt(qp.value)); } else if (qp.name.equals(QUERY_PARAM_START_TS)) { criteria.setStartTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_END_TS))) { criteria.setEndTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_DESC))) { criteria.setDescending(true); } else { criteria.addFieldRestriction(qp.name, qp.value); } } LOG.debug("Finding entities from notification store with criteria {}", criteria); return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList()); } NotificationServiceImpl();  NotificationServiceImpl(NotificationStore store);  NotificationServiceImpl(Map<String, Object> config);  NotificationServiceImpl(Map<String, Object> config, NotificationStore store); @Override Notifier register(String notifierName, NotificationContext ctx); @Override Notifier remove(String notifierName); @Override Future<?> notify(String notifierName, Notification notification); @Override Notification getNotification(String notificationId); @Override List<Notification> getNotifications(List<String> notificationIds); @Override List<Notification> findNotifications(List<QueryParam> queryParams); @Override StreamlineEvent getEvent(String eventId); @Override List<StreamlineEvent> getEvents(List<String> eventIds); @Override Notification updateNotificationStatus(String notificationId, Notification.Status status); @Override void close(); }
NotificationServiceImpl implements NotificationService { @Override public List<Notification> findNotifications(List<QueryParam> queryParams) { LOG.debug("findNotifications with queryParams {}", queryParams); CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class); for (QueryParam qp : queryParams) { if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) { criteria.setNumRows(Integer.parseInt(qp.value)); } else if (qp.name.equals(QUERY_PARAM_START_TS)) { criteria.setStartTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_END_TS))) { criteria.setEndTs(Long.parseLong(qp.value)); } else if (qp.name.equals((QUERY_PARAM_DESC))) { criteria.setDescending(true); } else { criteria.addFieldRestriction(qp.name, qp.value); } } LOG.debug("Finding entities from notification store with criteria {}", criteria); return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList()); } NotificationServiceImpl();  NotificationServiceImpl(NotificationStore store);  NotificationServiceImpl(Map<String, Object> config);  NotificationServiceImpl(Map<String, Object> config, NotificationStore store); @Override Notifier register(String notifierName, NotificationContext ctx); @Override Notifier remove(String notifierName); @Override Future<?> notify(String notifierName, Notification notification); @Override Notification getNotification(String notificationId); @Override List<Notification> getNotifications(List<String> notificationIds); @Override List<Notification> findNotifications(List<QueryParam> queryParams); @Override StreamlineEvent getEvent(String eventId); @Override List<StreamlineEvent> getEvents(List<String> eventIds); @Override Notification updateNotificationStatus(String notificationId, Notification.Status status); @Override void close();  }