@Test public void testValidateISOTimeCycle() { clear(); loadValidTestElements(VALID_ISO_TIME_CYCLE_DURATIONS); loadValidTestElements(VALID_EXPRESSIONS); loadInvalidTestElements(TimerSettingsValueValidator.ISOTimeCycleInvalid, INVALID_ISO_TIME_CYCLE_DURATIONS); loadInvalidTestElements(TimerSettingsValueValidator.ISOTimeCycleInvalid, INVALID_EXPRESSIONS); testElements.forEach(testElement -> { value.setTimeCycleLanguage(TimerSettingsValueValidator.ISO); value.setTimeCycle(testElement.getValue()); testElement.setResult(validator.isValid(value, context)); }); testElements.add(new TestElement(null, false, TimerSettingsValueValidator.NoValueHasBeenProvided)); value.setTimeCycleLanguage(null); value.setTimeCycle(null); testElements.get(testElements.size() - 1).setResult(validator.isValid(value, context)); verifyTestResults(); }
@Override public boolean isValid(TimerSettingsValue timerSettings, ConstraintValidatorContext constraintValidatorContext) { String value; String errorMessage = null; if (timerSettings.getTimeDuration() != null) { value = timerSettings.getTimeDuration(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidDuration(value))) { errorMessage = TimeDurationInvalid; } } else if (ISO.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidRepeatableInterval(value) && !isValidRepeatableDateTimeInterval(value) && !isValidRepeatableStartEndInterval(value) && !isValidRepeatablePeriodEndInterval(value))) { errorMessage = ISOTimeCycleInvalid; } } else if (CRON.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidCronExpression(value))) { errorMessage = CronTimeCycleInvalid; } } else if (timerSettings.getTimeDate() != null) { value = timerSettings.getTimeDate(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidTimeDate(value))) { errorMessage = TimeDateInvalid; } } else { errorMessage = NoValueHasBeenProvided; } if (errorMessage != null) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errorMessage) .addConstraintViolation(); return false; } return true; }
TimerSettingsValueValidator implements ConstraintValidator<ValidTimerSettingsValue, TimerSettingsValue> { @Override public boolean isValid(TimerSettingsValue timerSettings, ConstraintValidatorContext constraintValidatorContext) { String value; String errorMessage = null; if (timerSettings.getTimeDuration() != null) { value = timerSettings.getTimeDuration(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidDuration(value))) { errorMessage = TimeDurationInvalid; } } else if (ISO.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidRepeatableInterval(value) && !isValidRepeatableDateTimeInterval(value) && !isValidRepeatableStartEndInterval(value) && !isValidRepeatablePeriodEndInterval(value))) { errorMessage = ISOTimeCycleInvalid; } } else if (CRON.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidCronExpression(value))) { errorMessage = CronTimeCycleInvalid; } } else if (timerSettings.getTimeDate() != null) { value = timerSettings.getTimeDate(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidTimeDate(value))) { errorMessage = TimeDateInvalid; } } else { errorMessage = NoValueHasBeenProvided; } if (errorMessage != null) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errorMessage) .addConstraintViolation(); return false; } return true; } }
TimerSettingsValueValidator implements ConstraintValidator<ValidTimerSettingsValue, TimerSettingsValue> { @Override public boolean isValid(TimerSettingsValue timerSettings, ConstraintValidatorContext constraintValidatorContext) { String value; String errorMessage = null; if (timerSettings.getTimeDuration() != null) { value = timerSettings.getTimeDuration(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidDuration(value))) { errorMessage = TimeDurationInvalid; } } else if (ISO.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidRepeatableInterval(value) && !isValidRepeatableDateTimeInterval(value) && !isValidRepeatableStartEndInterval(value) && !isValidRepeatablePeriodEndInterval(value))) { errorMessage = ISOTimeCycleInvalid; } } else if (CRON.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidCronExpression(value))) { errorMessage = CronTimeCycleInvalid; } } else if (timerSettings.getTimeDate() != null) { value = timerSettings.getTimeDate(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidTimeDate(value))) { errorMessage = TimeDateInvalid; } } else { errorMessage = NoValueHasBeenProvided; } if (errorMessage != null) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errorMessage) .addConstraintViolation(); return false; } return true; }  }
TimerSettingsValueValidator implements ConstraintValidator<ValidTimerSettingsValue, TimerSettingsValue> { @Override public boolean isValid(TimerSettingsValue timerSettings, ConstraintValidatorContext constraintValidatorContext) { String value; String errorMessage = null; if (timerSettings.getTimeDuration() != null) { value = timerSettings.getTimeDuration(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidDuration(value))) { errorMessage = TimeDurationInvalid; } } else if (ISO.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidRepeatableInterval(value) && !isValidRepeatableDateTimeInterval(value) && !isValidRepeatableStartEndInterval(value) && !isValidRepeatablePeriodEndInterval(value))) { errorMessage = ISOTimeCycleInvalid; } } else if (CRON.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidCronExpression(value))) { errorMessage = CronTimeCycleInvalid; } } else if (timerSettings.getTimeDate() != null) { value = timerSettings.getTimeDate(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidTimeDate(value))) { errorMessage = TimeDateInvalid; } } else { errorMessage = NoValueHasBeenProvided; } if (errorMessage != null) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errorMessage) .addConstraintViolation(); return false; } return true; }  void initialize(ValidTimerSettingsValue constraintAnnotation); @Override boolean isValid(TimerSettingsValue timerSettings,
                           ConstraintValidatorContext constraintValidatorContext); }
TimerSettingsValueValidator implements ConstraintValidator<ValidTimerSettingsValue, TimerSettingsValue> { @Override public boolean isValid(TimerSettingsValue timerSettings, ConstraintValidatorContext constraintValidatorContext) { String value; String errorMessage = null; if (timerSettings.getTimeDuration() != null) { value = timerSettings.getTimeDuration(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidDuration(value))) { errorMessage = TimeDurationInvalid; } } else if (ISO.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidRepeatableInterval(value) && !isValidRepeatableDateTimeInterval(value) && !isValidRepeatableStartEndInterval(value) && !isValidRepeatablePeriodEndInterval(value))) { errorMessage = ISOTimeCycleInvalid; } } else if (CRON.equals(timerSettings.getTimeCycleLanguage())) { value = timerSettings.getTimeCycle(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidCronExpression(value))) { errorMessage = CronTimeCycleInvalid; } } else if (timerSettings.getTimeDate() != null) { value = timerSettings.getTimeDate(); if ((looksLikeExpression(value) && !isValidExpression(value)) || (!looksLikeExpression(value) && !isValidTimeDate(value))) { errorMessage = TimeDateInvalid; } } else { errorMessage = NoValueHasBeenProvided; } if (errorMessage != null) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errorMessage) .addConstraintViolation(); return false; } return true; }  void initialize(ValidTimerSettingsValue constraintAnnotation); @Override boolean isValid(TimerSettingsValue timerSettings,
                           ConstraintValidatorContext constraintValidatorContext); static final String TimeDurationInvalid; static final String ISOTimeCycleInvalid; static final String CronTimeCycleInvalid; static final String TimeDateInvalid; static final String NoValueHasBeenProvided; static final String ISO; static final String CRON; static final String DATE_PATTERN; }