DateDDMFormFieldValueValidator implements DDMFormFieldValueValidator { @Override public void validate(DDMFormField ddmFormField, Value value) throws DDMFormFieldValueValidationException { for (Locale availableLocale : value.getAvailableLocales()) { validateDateValue( ddmFormField, availableLocale, value.getString(availableLocale)); } }  @Override void validate(DDMFormField ddmFormField, Value value);  }
@Test public void testValidationWithEmptyNotRequiredDateShouldNotThrowException() throws DDMFormFieldValueValidationException { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Date", "Date", "date", "string", false, false, false); ddmForm.addDDMFormField(ddmFormField); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Date", new UnlocalizedValue("")); _dateDDMFormFieldValueValidator.validate( ddmFormField, ddmFormFieldValue.getValue()); }
@Test(expected = DDMFormFieldValueValidationException.class) public void testValidationWithEmptyRequiredDateShouldThrowException() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Date", "Date", "date", "string", false, false, true); ddmForm.addDDMFormField(ddmFormField); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Date", new UnlocalizedValue("")); _dateDDMFormFieldValueValidator.validate( ddmFormField, ddmFormFieldValue.getValue()); }
@Test(expected = DDMFormFieldValueValidationException.class) public void testValidationWithInvalidDateShouldThrowException() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Date", "Date", "date", "string", false, false, false); ddmForm.addDDMFormField(ddmFormField); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Date", new UnlocalizedValue("this-is-not-valid")); _dateDDMFormFieldValueValidator.validate( ddmFormField, ddmFormFieldValue.getValue()); }
@Test public void testValidationWithValidRequiredDateShouldNotThrowException() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Date", "Date", "date", "string", false, false, true); ddmForm.addDDMFormField(ddmFormField); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Date", new UnlocalizedValue("2018-04-18")); _dateDDMFormFieldValueValidator.validate( ddmFormField, ddmFormFieldValue.getValue()); }