@Test public void testValidateTimeDate() { clear(); loadValidTestElements(VALID_TIME_DATES); loadValidTestElements(VALID_EXPRESSIONS); loadInvalidTestElements(TimerSettingsValueValidator.TimeDateInvalid, INVALID_TIME_DATES); loadInvalidTestElements(TimerSettingsValueValidator.TimeDateInvalid, INVALID_EXPRESSIONS); testElements.add(new TestElement(null, false, TimerSettingsValueValidator.NoValueHasBeenProvided)); testElements.forEach(testElement -> { value.setTimeDate(testElement.getValue()); testElement.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; }