List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBeanTest.java
/** * Test of getModifyStyleSheet method, of class * fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBean. *//* w w w. j a v a 2 s .co m*/ public void testGetModifyStyleSheet() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.STYLESHEET_ID, Integer.toString(stylesheet.getId())); Utils.registerAdminUserWithRigth(request, new AdminUser(), StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); instance.init(request, StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); assertNotNull(instance.getModifyStyleSheet(request)); }
From source file:fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBeanTest.java
/** * Test of getCreateStyleSheet method, of class fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBean. *//*from www .ja va 2 s.c o m*/ public void testGetCreateStyleSheet() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.MODE_ID, "0"); Utils.registerAdminUserWithRigth(request, new AdminUser(), StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); instance.init(request, StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); String html = instance.getCreateStyleSheet(request); assertNotNull(html); }
From source file:org.openmrs.web.controller.encounter.EncounterTypeFormControllerTest.java
@Test public void shouldSaveEncounterTypeWhenEncounterTypesAreNotLocked() throws Exception { EncounterService es = Context.getEncounterService(); EncounterTypeFormController controller = (EncounterTypeFormController) applicationContext .getBean("encounterTypeForm"); controller.setApplicationContext(applicationContext); controller.setSuccessView("index.htm"); controller.setFormView("EncounterType.form"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin/encounters/encounterType.form?encounterTypeId=1"); request.setSession(new MockHttpSession(null)); HttpServletResponse response = new MockHttpServletResponse(); controller.handleRequest(request, response); request.setMethod("POST"); request.addParameter("action", "Save EncounterType"); ModelAndView mav = controller.handleRequest(request, response); Assert.assertSame(controller.getFormView(), mav.getViewName()); Assert.assertNotEquals("The save attempt should have passed!", "index.htm", mav.getViewName()); Assert.assertNotNull(es.getEncounterType(1)); }
From source file:fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBeanTest.java
/** * Test of doRemoveStyleSheet method, of class * fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBean. * /* w w w . j a va 2 s.co m*/ * @throws AccessDeniedException */ public void testDoRemoveStyleSheet() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.STYLESHEET_ID, Integer.toString(stylesheet.getId())); request.addParameter(Parameters.STYLE_ID, Integer.toString(style.getId())); request.addParameter(SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance().getToken(request, "jsp/admin/style/DoRemoveStyleSheet.jsp")); instance.doRemoveStyleSheet(request); assertNull(StyleSheetHome.findByPrimaryKey(stylesheet.getId())); }
From source file:fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBeanTest.java
/** * Test of getConfirmRemoveStyleSheet method, of class * fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBean. *///from w w w .jav a2s . co m public void testGetConfirmRemoveStyleSheet() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.STYLESHEET_ID, Integer.toString(stylesheet.getId())); request.addParameter(Parameters.STYLE_ID, Integer.toString(style.getId())); Utils.registerAdminUserWithRigth(request, new AdminUser(), StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); instance.init(request, StyleSheetJspBean.RIGHT_MANAGE_STYLESHEET); instance.getRemoveStyleSheet(request); AdminMessage message = AdminMessageService.getMessage(request); assertNotNull(message); assertTrue(message.getRequestParameters().containsKey(SecurityTokenService.PARAMETER_TOKEN)); }
From source file:fr.paris.lutece.portal.web.stylesheet.StyleSheetJspBeanTest.java
public void testDoRemoveStyleSheetNoToken() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.STYLESHEET_ID, Integer.toString(stylesheet.getId())); request.addParameter(Parameters.STYLE_ID, Integer.toString(style.getId())); try {// ww w . ja v a 2s . c o m instance.doRemoveStyleSheet(request); fail("Should have thrown"); } catch (AccessDeniedException e) { StyleSheet stored = StyleSheetHome.findByPrimaryKey(stylesheet.getId()); assertNotNull(stored); assertEquals(stylesheet.getId(), stored.getId()); } }
From source file:org.araneaframework.tests.FormTest.java
/** * Testing reading from request with a mandatory element missing. *//* w w w . j a v a2s .c om*/ public void testFormMandatoryMissingRequestReading() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest mandatoryMissingRequest = new MockHttpServletRequest(); mandatoryMissingRequest.addParameter("testForm.__present", "true"); mandatoryMissingRequest.addParameter("testForm.myCheckBox", "true"); mandatoryMissingRequest.addParameter("testForm.myLongText", "108"); mandatoryMissingRequest.addParameter("testForm.myDateTime.date", "11.10.2015"); mandatoryMissingRequest.addParameter("testForm.myDateTime.time", "01:01"); mandatoryMissingRequest.addParameter("testForm.hierarchyTest.mySelect", "2"); //Testing that mandatory items are processed right StandardServletInputData input = new StandardServletInputData(mandatoryMissingRequest); input.pushScope("testForm"); testForm._getWidget().update(input); assertTrue("Test form must not be valid after reading from request", !testForm.convertAndValidate()); }
From source file:org.araneaframework.tests.FormTest.java
/** * Testing reading from valid request.// www. j ava2s .c o m */ public void testFormValidRequestReading() throws Exception { FormWidget testForm = makeUsualForm(); FormWidget hierarchyTest = (FormWidget) testForm.getElement("hierarchyTest"); MockHttpServletRequest validRequest = new MockHttpServletRequest(); validRequest.addParameter("testForm.__present", "true"); validRequest.addParameter("testForm.myCheckBox", (String) null); validRequest.addParameter("testForm.myLongText", "108"); validRequest.addParameter("testForm.myDateTime.date", "11.10.2015"); validRequest.addParameter("testForm.myDateTime.time", "01:01"); validRequest.addParameter("testForm.hierarchyTest.myTextarea", "blah"); validRequest.addParameter("testForm.hierarchyTest.mySelect", "2"); //Trying to read from a valid request StandardServletInputData input = new StandardServletInputData(validRequest); input.pushScope("testForm"); testForm._getWidget().update(input); Date reqDate = (new SimpleDateFormat("dd.MM.yyyy hh:mm")).parse("11.10.2015 01:01"); //Checking that reading from request works assertTrue("Test form must be valid after reading from request", testForm.convertAndValidate()); assertTrue(((FormElement) testForm.getElement("myCheckBox")).getData().getValue().equals(Boolean.FALSE)); assertTrue(((FormElement) testForm.getElement("myLongText")).getData().getValue().equals(new Long(108))); assertTrue(((FormElement) testForm.getElement("myDateTime")).getData().getValue().equals(reqDate)); assertTrue(((FormElement) hierarchyTest.getElement("mySelect")).getData().getValue().equals(new Long(2))); assertTrue(((FormElement) hierarchyTest.getElement("myTextarea")).getData().getValue().equals("blah")); }
From source file:org.araneaframework.tests.FormTest.java
/** * Testing reading from request with a not mandatory element missing. *//*from w ww.ja v a 2 s. c o m*/ public void testFormNotMandatoryMissingRequestReading() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest notMandatoryMissingRequest = new MockHttpServletRequest(); notMandatoryMissingRequest.addParameter("testForm.__present", "true"); notMandatoryMissingRequest.addParameter("testForm.myCheckBox", (String) null); notMandatoryMissingRequest.addParameter("testForm.myLongText", "108"); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.myTextarea", "blah"); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.mySelect", "2"); StandardServletInputData input = new StandardServletInputData(notMandatoryMissingRequest); input.pushScope("testForm"); testForm._getWidget().update(input); assertTrue("Test form must be valid after reading from request", testForm.convertAndValidate()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsController1_8Test.java
/** * @see ObsController#purgeObs(String,WebRequest,HttpServletResponse) * @verifies purge a simple obs// w ww .j a v a2 s. c o m */ @Test public void purgeObs_shouldPurgeASimpleObs() throws Exception { Context.getObsService().getObsByUuid(getUuid()); Assert.assertNotNull(Context.getObsService().getObsByUuid(getUuid())); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("purge", ""); handle(req); Assert.assertNull(Context.getObsService().getObsByUuid(getUuid())); }