use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class GuiFragmentValidatorTest method validateInvalidFragmentCode_1.
@Test
public void validateInvalidFragmentCode_1() throws Exception {
String code = "very_long";
for (int i = 0; i < 10; i++) {
code += code;
}
when(this.guiFragmentManager.getGuiFragment(code)).thenReturn(null);
GuiFragmentRequestBody request = new GuiFragmentRequestBody(code, "<h1>prova</h1>");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertTrue(bindingResult.hasErrors());
Assert.assertEquals(1, bindingResult.getErrorCount());
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class GuiFragmentValidatorTest method validateExistingFragment.
@Test
public void validateExistingFragment() throws Exception {
GuiFragment existing = new GuiFragment();
existing.setCode("existing");
when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "<h1>code</h1>");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertTrue(bindingResult.hasErrors());
Assert.assertEquals(1, bindingResult.getErrorCount());
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class MessageSourceServiceTest method getMessage_shouldReturnTheLastErrorCodeIfnoLocalizationIsFound.
/**
* MessageSourceServiceImpl.getMessage()should return last error code if no localization found
*
* @see MessageSourceServiceImpl#getMessage(MessageSourceResolvable resolvable, Locale locale)
*/
@Test
public void getMessage_shouldReturnTheLastErrorCodeIfnoLocalizationIsFound() {
MapBindingResult errors = new MapBindingResult(new HashMap<String, Object>(), "request");
errors.rejectValue("myField", "myErrorCode");
MessageSourceResolvable fieldError = errors.getFieldError("myField");
Assert.assertEquals(3, fieldError.getCodes().length);
Assert.assertEquals("myErrorCode.request.myField", fieldError.getCodes()[0]);
Assert.assertEquals("myErrorCode.myField", fieldError.getCodes()[1]);
Assert.assertEquals("myErrorCode", fieldError.getCodes()[2]);
Assert.assertEquals("myErrorCode", Context.getMessageSourceService().getMessage(fieldError, Context.getLocale()));
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class PersonNameValidatorTest method validate_shouldReportErrorsOnCorrectFieldNames.
/**
* @see PersonNameValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldReportErrorsOnCorrectFieldNames() {
PersonName personName = new PersonName("", "reb", "feb");
MapBindingResult errors = new MapBindingResult(new HashMap<String, Object>(), "personName");
validator.validate(personName, errors);
assertThat(errors, hasFieldErrors("givenName"));
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class PersonNameValidatorTest method validatePersonName_shouldReportErrorsWithNonStandardPrefixWhenCalledInHistoricWay.
/**
* @see PersonNameValidator#validatePersonName(PersonName, Errors, Boolean, Boolean)
*/
@Test
public void validatePersonName_shouldReportErrorsWithNonStandardPrefixWhenCalledInHistoricWay() {
PersonName personName = new PersonName("", "reb", "feb");
MapBindingResult errors = new MapBindingResult(new HashMap<String, Object>(), "personName");
validator.validatePersonName(personName, errors, true, false);
assertThat(errors, hasFieldErrors("names[0]." + "givenName"));
}
Aggregations