AlarmValidator { public void validateAlarm(final Alarm alarm) throws CerebroException { if (StringUtils.isEmpty(alarm.getName())) { throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm name is required."); } if (StringUtils.isEmpty(alarm.getTarget()) || StringUtils.startsWithIgnoreCase(alarm.getTarget(), "*")) { throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm target is required."); } if (StringUtils.isEmpty(alarm.getWarn())) { throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm warning threshold is required."); } if (StringUtils.isEmpty(alarm.getError())) { throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm error threshold is required."); } }  void validateAlarm(final Alarm alarm);  }
@Test public void validateAlarmWithNoWarnThresholdFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setWarn(null); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }
@Test public void validateAlarmWithNoErrorThresholdFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setError(null); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }
@Test public void validateAlarmWithOkPlateformWildcard() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setTarget("Zenith.VAS.VSA.VSA.LIL.PRD*.WAS.*.*.any.*.any.io.sla.any.vol.any.10min.count"); validator.validateAlarm(alarm); }
@Test public void validateAlarmWithNoNameFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setName(null); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }
@Test public void validateAlarmWithEmptyFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setName(""); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }
@Test public void validateAlarmWithNoTargetFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setTarget(null); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }
@Test public void validateAlarmWithEmptyTargetFails() throws Exception { Alarm alarm = TestUtils.getDefaultAlarm(); alarm.setTarget(""); try { validator.validateAlarm(alarm); } catch (CerebroException ce) { assertEquals(ErrorCode.ALARM_INVALID, ce.getErrorCode()); } }