use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class GuiFragmentValidatorTest method validateInvalidFragmentCode_2.
@Test
public void validateInvalidFragmentCode_2() throws Exception {
String code = "wrong_characters_&_$_123";
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 validateExistingAndInvalidFragment.
@Test
public void validateExistingAndInvalidFragment() throws Exception {
GuiFragment existing = new GuiFragment();
existing.setCode("existing");
when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertTrue(bindingResult.hasErrors());
Assert.assertEquals(2, bindingResult.getErrorCount());
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class UserControllerUnitTest method selfDeleteReturnsError.
@Test(expected = ValidationGenericException.class)
public void selfDeleteReturnsError() throws ApsSystemException {
when(user.getUsername()).thenReturn("test");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "user");
new UserController().deleteUser(user, "test", bindingResult);
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class UserControllerUnitTest method deleteAdminReturnsError.
@Test(expected = ValidationGenericException.class)
public void deleteAdminReturnsError() throws ApsSystemException {
when(user.getUsername()).thenReturn("admin");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "user");
new UserController().deleteUser(user, "admin", bindingResult);
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class UserValidatorTest method createErrorSelfDeleteContainsErrorMessage.
@Test
public void createErrorSelfDeleteContainsErrorMessage() {
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "username");
BindingResult bindingSelfDeleteError = UserValidator.createSelfDeleteUserError(bindingResult);
assertEquals(1, bindingSelfDeleteError.getErrorCount());
List<ObjectError> errors = bindingSelfDeleteError.getAllErrors();
ObjectError error = errors.get(0);
assertEquals(UserValidator.ERRCODE_SELF_DELETE, error.getCode());
assertEquals("user.self.delete.error", error.getDefaultMessage());
}
Aggregations