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
public void testDoRemoveStyleSheetInvalidToken() 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") + "b"); try {//from w ww . ja va 2 s. 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.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#get(org.openmrs.ui.framework.page.PageModel, * org.openmrs.ui.framework.UiUtils, org.openmrs.ui.framework.page.PageRequest, String, * org.openmrs.api.LocationService, * org.openmrs.module.appframework.service.AppFrameworkService) *///from w w w . j a v a 2s . c om @Test @Verifies(value = "should set redirectUrl in the page model if any was specified in the request", method = "get(PageModel,UiUtils,PageRequest)") public void get_shouldSetRedirectUrlInThePageModelIfAnyWasSpecifiedInTheRequest() throws Exception { when(Context.isAuthenticated()).thenReturn(false); String redirectUrl = TEST_CONTEXT_PATH + "/referenceapplication/patient.page"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(TEST_CONTEXT_PATH); request.addParameter(REQUEST_PARAMETER_NAME_REDIRECT_URL, redirectUrl); PageModel pageModel = new PageModel(); new LoginPageController().get(pageModel, uiUtils, createPageRequest(request, null), null, null, appFrameworkService); assertEquals(redirectUrl, pageModel.get(REQUEST_PARAMETER_NAME_REDIRECT_URL)); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.PersonControllerTest.java
/** * @see PersonController#getPerson(String,WebRequest) * @verifies get a full representation of a person *//*from ww w . j a v a 2 s . c om*/ @Test public void getPerson_shouldGetAFullRepresentationOfAPerson() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); Object result = new PersonController().retrieve("5946f880-b197-400b-9caa-a3c661d23041", req); Util.log("Person fetched (full)", result); Assert.assertNotNull(result); Assert.assertEquals("5946f880-b197-400b-9caa-a3c661d23041", PropertyUtils.getProperty(result, "uuid")); Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo")); }
From source file:org.araneaframework.tests.FormConstraintTest.java
/** * Testing reading from request with a primitive constraint set. *//*from w ww . j av a 2 s . c o m*/ public void testFormPrimitiveConstraint() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("testForm.__present", "true"); request.addParameter("testForm.myCheckBox", "true"); request.addParameter("testForm.myLongText", "108"); request.addParameter("testForm.myDateTime", (String) null); //Testing primitive constraint testForm.getElement("myDateTime").setConstraint(new NotEmptyConstraint()); StandardServletInputData input = new StandardServletInputData(request); 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.FormConstraintTest.java
/** * Test reading from request with a grouped constraint set, date is invalid. *//*from w ww.j a v a 2s.co m*/ public void anotherTestFormInactiveGroupedConstraintInValidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("testForm.__present", "true"); request.addParameter("testForm.myCheckBox", "true"); request.addParameter("testForm.myLongText", "108"); request.addParameter("testForm.myDateTime.date", "11.10.20151278901"); request.addParameter("testForm.myDateTime.time", "01:01"); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); MockUiLibUtil.emulateHandleRequest(testForm, "testForm", request); assertFalse("Test form must be invalid after reading from request", testForm.convertAndValidate()); }
From source file:org.araneaframework.tests.FormConstraintTest.java
/** * Test reading from request with a grouped constraint set, date is invalid. *//* w w w. j a v a 2 s . c om*/ public void testFormInactiveGroupedConstraintInValidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("testForm.__present", "true"); request.addParameter("testForm.myCheckBox", "true"); request.addParameter("testForm.myLongText", "108"); request.addParameter("testForm.myDateTime.date", "11.10.20151"); request.addParameter("testForm.myDateTime.time", "01:01"); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); MockUiLibUtil.emulateHandleRequest(testForm, "testForm", request); assertFalse("Test form must be invalid after reading from request", testForm.convertAndValidate()); }
From source file:org.araneaframework.tests.FormTest.java
/** * Testing reading from request with a grouped constraint set. *///from w ww . jav a2 s .co m public void testFormInactiveGroupedConstraintValidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest notMandatoryMissingRequest = new MockHttpServletRequest(); notMandatoryMissingRequest.addParameter("testForm.__present", "true"); notMandatoryMissingRequest.addParameter("testForm.myCheckBox", "true"); notMandatoryMissingRequest.addParameter("testForm.myLongText", "108"); notMandatoryMissingRequest.addParameter("testForm.myDateTime.date", "11.10.2015"); notMandatoryMissingRequest.addParameter("testForm.myDateTime.time", "01:01"); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.myTextarea", "blah"); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.mySelect", "2"); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); 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.araneaframework.tests.FormConstraintTest.java
/** * Testing reading from request with a grouped constraint set. *///from www. ja v a 2 s. c o m public void testFormActiveGroupedConstraintInvalidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("testForm.__present", "true"); request.addParameter("testForm.myCheckBox", "true"); request.addParameter("testForm.myLongText", "108"); request.addParameter("testForm.myDateTime", (String) null); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); StandardServletInputData input = new StandardServletInputData(request); input.pushScope("testForm"); testForm._getWidget().update(input); groupHelper.setActiveGroup("active"); assertTrue("Test form must not be valid after reading from request", !testForm.convertAndValidate()); }
From source file:org.araneaframework.tests.FormConstraintTest.java
/** * Testing reading from request with a grouped constraint set. *//*from w ww . j a va2 s .c om*/ public void testFormInactiveGroupedConstraintValidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("testForm.__present", "true"); request.addParameter("testForm.myCheckBox", "true"); request.addParameter("testForm.myLongText", "108"); request.addParameter("testForm.myDateTime.date", "11.10.2015"); request.addParameter("testForm.myDateTime.time", "01:01"); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); StandardServletInputData input = new StandardServletInputData(request); input.pushScope("testForm"); testForm._getWidget().update(input); assertTrue("Test form must be valid after reading from request", testForm.convertAndValidate()); }
From source file:org.araneaframework.tests.FormTest.java
/** * Testing reading from request with a grouped constraint set. */// w w w. jav a 2 s . c om public void testFormActiveGroupedConstraintInvalidates() throws Exception { FormWidget testForm = makeUsualForm(); MockHttpServletRequest notMandatoryMissingRequest = new MockHttpServletRequest(); notMandatoryMissingRequest.addParameter("testForm.__present", "true"); notMandatoryMissingRequest.addParameter("testForm.myCheckBox", "true"); notMandatoryMissingRequest.addParameter("testForm.myLongText", "108"); notMandatoryMissingRequest.addParameter("testForm.myDateTime", (String) null); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.myTextarea", "blah"); notMandatoryMissingRequest.addParameter("testForm.hierarchyTest.mySelect", "2"); // create helper ConstraintGroupHelper groupHelper = new ConstraintGroupHelper(); testForm.getElement("myDateTime") .setConstraint(groupHelper.createGroupedConstraint(new NotEmptyConstraint(), "active")); StandardServletInputData input = new StandardServletInputData(notMandatoryMissingRequest); input.pushScope("testForm"); testForm._getWidget().update(input); groupHelper.setActiveGroup("active"); assertTrue("Test form must not be valid after reading from request", !testForm.convertAndValidate()); }