SubscriptionService { public void addSubscription(Subscription subscription, String alarmId) { validateSubscription(subscription); if (this.searchSubscription(subscription, alarmId) != null) { LOGGER.debug("Identical subscription found (alarm id: {}).", alarmId); throw new DuplicateSubscriptionException("Attempting to add a subscription that already exists on alarm " + alarmId); } seyrenRepository.addSubscription(subscription, alarmId); }  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 addSubscription() throws Exception { Subscription subToAdd = TestUtils.getDefaultSubscription(); String subId = "subTestId"; subToAdd.setId(subId); subToAdd.setTarget("test@anotherteam.org"); subToAdd.setSu(true); subscriptionService.addSubscription(subToAdd, TestUtils.DEFAULT_ALARM_ID); }
@Test public void addSubscriptionAlreadyExist() throws Exception { try { subscriptionService.addSubscription(TestUtils.getDefaultSubscription(), TestUtils.DEFAULT_ALARM_ID); fail("Adding duplicate exception with success"); } catch (DuplicateSubscriptionException ce) { assertEquals(ErrorCode.SUBSCRIPTION_DUPLICATE, ce.getErrorCode()); } }
@Test public void addSubscriptionFailWithNoTarget() throws Exception { Subscription subscription = TestUtils.getDefaultSubscription(); String subId = "subTestId"; subscription.setId(subId); subscription.setTarget(""); try { subscriptionService.addSubscription(subscription, TestUtils.DEFAULT_ALARM_ID); fail("Create a subscription with no target should throw an exception"); } catch (CerebroException ce) { assertEquals(ErrorCode.SUBSCRIPTION_INVALID, ce.getErrorCode()); } }
@Test public void addSubscriptionFailWithNoDayToSendAlert() throws Exception { Subscription subscription = TestUtils.getDefaultSubscription(); String subId = "subTestId"; subscription.setId(subId); subscription.setTarget("test@anotherteam.org"); subscription.setSu(true); subscription.setMo(false); subscription.setTu(false); subscription.setWe(false); subscription.setTh(false); subscription.setFr(false); subscription.setSa(false); subscription.setSu(false); try { subscriptionService.addSubscription(subscription, TestUtils.DEFAULT_ALARM_ID); fail("Create a subscription with no alerting day should throw an exception"); } catch (CerebroException ce) { assertEquals(ErrorCode.SUBSCRIPTION_INVALID, ce.getErrorCode()); } }