Search in sources :

Example 36 with MapBindingResult

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());
}
Also used : GuiFragmentRequestBody(org.entando.entando.web.guifragment.model.GuiFragmentRequestBody) MapBindingResult(org.springframework.validation.MapBindingResult) Test(org.junit.Test)

Example 37 with MapBindingResult

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());
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) GuiFragmentRequestBody(org.entando.entando.web.guifragment.model.GuiFragmentRequestBody) MapBindingResult(org.springframework.validation.MapBindingResult) Test(org.junit.Test)

Example 38 with MapBindingResult

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);
}
Also used : MapBindingResult(org.springframework.validation.MapBindingResult) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 39 with MapBindingResult

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);
}
Also used : MapBindingResult(org.springframework.validation.MapBindingResult) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 40 with MapBindingResult

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());
}
Also used : MapBindingResult(org.springframework.validation.MapBindingResult) BindingResult(org.springframework.validation.BindingResult) ObjectError(org.springframework.validation.ObjectError) MapBindingResult(org.springframework.validation.MapBindingResult) Test(org.junit.Test)

Aggregations

MapBindingResult (org.springframework.validation.MapBindingResult)40 Test (org.junit.Test)22 ObjectError (org.springframework.validation.ObjectError)12 BindingResult (org.springframework.validation.BindingResult)11 HashMap (java.util.HashMap)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 Test (org.junit.jupiter.api.Test)6 Relationship (org.openmrs.Relationship)6 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)6 Method (java.lang.reflect.Method)5 GuiFragmentRequestBody (org.entando.entando.web.guifragment.model.GuiFragmentRequestBody)5 MethodParameter (org.springframework.core.MethodParameter)5 BindException (org.springframework.validation.BindException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ServletException (jakarta.servlet.ServletException)3 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 ResponseEntity (org.springframework.http.ResponseEntity)3 FieldError (org.springframework.validation.FieldError)3 WebExchangeBindException (org.springframework.web.bind.support.WebExchangeBindException)3