SubscriptionService { public Subscription getSubscription(String alarmId, String subscriptionId) { Alarm c = seyrenRepository.getAlarm(alarmId); Subscription ret = c.getSubscriptions().stream().filter(s -> s.getId().equals(subscriptionId)).findAny().orElse(null); if (ret == null) { LOGGER.debug("Subscription {} for alarm {} does not exist.", subscriptionId, alarmId); throw new CerebroException(ErrorCode.SUBSCRIPTION_UNKNOWN, "Subscription " + subscriptionId + " for alarm " + alarmId + " does not exist."); } return ret; }  Subscription getSubscription(String alarmId, String subscriptionId); void addSubscription(Subscription subscription, String alarmId); Subscription searchSubscription(Subscription subscription, String alarmId); void updateSubscription(Subscription subscription, String alarmId); SubscriptionService.DeletedSubscriptionStatus deleteSubscription(String alarmId, String subscriptionId);  }
@Test public void getSubscription() throws Exception { Subscription subscription = subscriptionService.getSubscription(TestUtils.DEFAULT_ALARM_ID, TestUtils.DEFAULT_SUBSCRIPTION_ID); assertNotNull(subscription); assertEquals(TestUtils.DEFAULT_SUBSCRIPTION_ID, subscription.getId()); assertEquals(TestUtils.DEFAULT_EMAIL, subscription.getTarget()); }
@Test public void getNonExistentSubscription() { Subscription subscription = null; try { subscription = subscriptionService.getSubscription(TestUtils.DEFAULT_ALARM_ID, "0000000000000"); fail("Update non existent subscription should throw an exception"); } catch (CerebroException e) { assertNull(subscription); assertEquals(ErrorCode.SUBSCRIPTION_UNKNOWN, e.getErrorCode()); } }
@Test public void getSubscriptionOnNonExistentAlarm() { try { subscriptionService.getSubscription(TestUtils.NONEXISTING_ALARM_ID, TestUtils.DEFAULT_SUBSCRIPTION_ID); fail("Subscribe to a non existing alarm should throw a Cerebro exception"); } catch (CerebroException e) { assertEquals(ErrorCode.ALARM_UNKNOWN, e.getErrorCode()); } }