AlarmService { public Alarm updateAlarm(final Alarm alarm) { LOGGER.debug("Update alarm to: " + alarm); validateUpdatable(alarm); try { seyrenRepository.updateAlarm(alarm); if(alarm.isEnabled()) { notificationHandler.sendAlarmHasBeenModified(alarm); } else{ notificationHandler.sendAlarmHasBeenDeactivated(alarm); } return this.searchAlarmByName(alarm.getName()); } catch (RuntimeException exception) { LOGGER.error("Error updating alarm", exception); throw new CerebroException(ErrorCode.CEREBRO_UNKNOWN_ERROR, "Error updating alarm", exception); } }  Alarm getAlarm(String id); Collection<Alarm> getAllAlarms(); Alarm subscribeToAAlarm(final Alarm alarm); Alarm searchAlarm(final Alarm alarm); Collection<Alarm> searchAlarmsBySubscriptionTarget(String subTarget); Alarm updateAlarm(final Alarm alarm);  }
@Test public void updateAlarm() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setTarget("totoSayHello"); Alarm updatedAlarm = alarmService.updateAlarm(alarm); assertNotNull(updatedAlarm); verify(seyrenRepository).updateAlarm(alarm); }
@Test public void updateNonexistentAlarmFail() throws Exception { Alarm updatedAlarm = TestUtils.getDefaultAlarm(); updatedAlarm.setId(TestUtils.NONEXISTING_ALARM_ID); try { alarmService.updateAlarm(updatedAlarm); fail("Update non existing alarm should throw an exception"); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_UNKNOWN, ce.getErrorCode()); } }
@Test public void updateAlarmSendModificationEmail(){ Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setEnabled(true); alarmService.updateAlarm(alarm); verify(notificationHandler).sendAlarmHasBeenModified(alarm); }
@Test public void disableAlarmSendDeactivationEmail(){ Alarm alarm = TestUtils.getDefaultAlarm(); alarmService.updateAlarm(alarm); verify(notificationHandler).sendAlarmHasBeenDeactivated(alarm); }