@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()); }
@Test public void validateRightFragment() throws Exception { when(this.guiFragmentManager.getGuiFragment("not_existing")).thenReturn(null); GuiFragmentRequestBody request = new GuiFragmentRequestBody("not_existing", "<h1>code</h1>"); MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment"); validator.validate(request, bindingResult); Assert.assertFalse(bindingResult.hasErrors()); Assert.assertEquals(0, bindingResult.getErrorCount()); }
@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()); }
@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()); }
@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()); }