List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldIncludeTheListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); Assert.assertEquals(0, location.getChildLocations().size()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location);/*from w ww .jav a 2 s . c o m*/ MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertEquals(1, ((Collection) PropertyUtils.getProperty(result, "childLocations")).size()); }
From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java
@Test public void testFailedAuthenticationWithNoService() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); request.addParameter("username", "test"); request.addParameter("password", "test2"); context.setExternalContext(//from www .ja v a 2 s . co m new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); context.getRequestScope().put("credentials", TestUtils.getCredentialsWithDifferentUsernameAndPassword()); context.getRequestScope().put("org.springframework.validation.BindException.credentials", new BindException(TestUtils.getCredentialsWithDifferentUsernameAndPassword(), "credentials")); // this.action.bind(context); // assertEquals("error", this.action.submit(context).getId()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldPurgeARetiredLocation() throws Exception { Location location = service.getLocation(3); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + location.getUuid()); req.addParameter("purge", ""); handle(req);//from w w w. j a v a 2 s. c o m Assert.assertNull(service.getLocation(3)); }
From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java
/** * If a user enters 5 requests, the 6th should fail even if that one has a valid username in it * * @throws Exception//from w w w.j av a2 s.c o m */ @Test public void shouldLockOutAfterFiveFailedInvalidUsernames() throws Exception { ForgotPasswordFormController controller = (ForgotPasswordFormController) applicationContext .getBean("forgotPasswordForm"); for (int x = 1; x <= 5; x++) { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "invaliduser"); controller.handleRequest(request, new MockHttpServletResponse()); } // those were the first five, now the sixth request (with a valid user) should fail MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "validuser"); controller.handleRequest(request, new MockHttpServletResponse()); Assert.assertNull(request.getAttribute("secretQuestion")); }
From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java
/** * If a user enters 5 requests, the 6th should fail even if that one has a valid username and a * secret answer associated with it/*www. ja v a2s . c o m*/ * * @throws Exception */ @Test public void shouldNotAcceptAfterFiveFailedInvalidUsernames() throws Exception { ForgotPasswordFormController controller = (ForgotPasswordFormController) applicationContext .getBean("forgotPasswordForm"); for (int x = 1; x <= 5; x++) { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "invaliduser"); controller.handleRequest(request, new MockHttpServletResponse()); } // those were the first five, now the sixth request (with a valid user) should fail MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "validuser"); request.addParameter("secretAnswer", "valid secret answer"); controller.handleRequest(request, new MockHttpServletResponse()); Assert.assertFalse(Context.isAuthenticated()); }
From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java
/** * If a user enters 5 requests with username+secret answer, the 6th should fail even if that one * has a valid answer in it//from w w w . j a va 2s . c o m * * @throws Exception */ @Test public void shouldLockOutAfterFiveFailedInvalidSecretAnswers() throws Exception { ForgotPasswordFormController controller = (ForgotPasswordFormController) applicationContext .getBean("forgotPasswordForm"); for (int x = 1; x <= 5; x++) { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "validuser"); request.addParameter("secretAnswer", "invalid secret answer"); controller.handleRequest(request, new MockHttpServletResponse()); } // those were the first five, now the sixth request (with a valid user) should fail MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.addParameter("uname", "validuser"); request.addParameter("secretAnswer", "valid secret answer"); controller.handleRequest(request, new MockHttpServletResponse()); Assert.assertFalse(Context.isAuthenticated()); }
From source file:org.araneaframework.tests.FormControlTest.java
/** * Tests that {@link TextControl} return <code>null</code> on empty request. * @throws Exception//from www. ja va2 s . c o m */ public void testTextboxOnEmptyRequest() throws Exception { MockHttpServletRequest emptyRequest = new MockHttpServletRequest(); emptyRequest.addParameter("myTextBox", ""); TextControl tb = new TextControl(); tb._getComponent().init(new MockEnviroment()); MockUiLibUtil.emulateHandleRequest(tb, "myTextBox", emptyRequest); tb.convertAndValidate(); assertNull("TextBox must return null on empty request.", tb.getRawValue()); tb._getComponent().destroy(); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldRetireALocation() throws Exception { Location location = service.getLocation(2); Assert.assertFalse(location.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + location.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "random reason"); handle(req);/*ww w . jav a 2 s. c o m*/ Location retiredLocation = service.getLocation(2); Assert.assertTrue(retiredLocation.isRetired()); Assert.assertEquals("random reason", retiredLocation.getRetireReason()); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#post(String, String, Integer, org.openmrs.api.LocationService, * org.openmrs.ui.framework.UiUtils, org.openmrs.ui.framework.page.PageRequest, * org.openmrs.module.appui.UiSessionContext) *//*from w ww .j av a 2 s.co m*/ @Test @Ignore @Verifies(value = "should redirect the user back to the redirectUrl if any", method = "post(String,String,UiUtils,PageRequest)") public void post_shouldRedirectTheUserBackToTheRedirectUrlIfAny() throws Exception { setupMocksForSuccessfulAuthentication(true); final String redirectUrl = TEST_CONTEXT_PATH + "/referenceapplication/patient.page"; MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(REQUEST_PARAMETER_NAME_REDIRECT_URL, redirectUrl); PageRequest pageRequest = createPageRequest(request, null); assertEquals("redirect:" + redirectUrl, new LoginPageController().post(USERNAME, PASSWORD, SESSION_LOCATION_ID, locationService, uiUtils, pageRequest, sessionContext)); }
From source file:org.openmrs.web.controller.form.FormFormControllerTest.java
@Test public void shouldNotDuplicateAFormWhenFormsAreLocked() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("POST", "/admin/forms/formEdit.form?duplicate=true&formId=1"); request.setSession(new MockHttpSession(null)); HttpServletResponse response = new MockHttpServletResponse(); controller.handleRequest(request, response); request.addParameter("name", "TRUNK"); request.addParameter("version", "1"); request.addParameter("action", "Form.Duplicate"); request.setContentType("application/x-www-form-urlencoded"); ModelAndView mav = controller.handleRequest(request, response); Assert.assertEquals("The duplicate attempt should have failed!", "index.htm", mav.getViewName()); Assert.assertNotEquals("formEdit.form", mav.getViewName()); Assert.assertSame(controller.getFormView(), mav.getViewName()); Assert.assertNotNull(formService.getForm(1)); }