Search in sources :

Example 6 with GuiFragmentRequestBody

use of org.entando.entando.web.guifragment.model.GuiFragmentRequestBody 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 7 with GuiFragmentRequestBody

use of org.entando.entando.web.guifragment.model.GuiFragmentRequestBody 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)

Aggregations

GuiFragmentRequestBody (org.entando.entando.web.guifragment.model.GuiFragmentRequestBody)7 Test (org.junit.Test)6 MapBindingResult (org.springframework.validation.MapBindingResult)5 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestServerError (org.entando.entando.aps.system.exception.RestServerError)1 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)1 GuiFragmentValidator (org.entando.entando.web.guifragment.validator.GuiFragmentValidator)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1