List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:fi.okm.mpass.idp.authn.impl.AbstractSpringSocialOAuth2IdentityTest.java
@Test(expectedExceptions = SocialUserAuthenticationException.class) public void testAccessGrantNoState() throws Exception { identity = new AbstractSpringSocialOAuth2Identity() { };//from www .j a v a2 s.co m final MockHttpServletRequest httpRequest = new MockHttpServletRequest(); httpRequest.addParameter("code", "mockCode"); Assert.assertNull(identity.getAccessGrant(httpRequest)); }
From source file:fi.okm.mpass.idp.authn.impl.AbstractSpringSocialOAuth2IdentityTest.java
@Test(expectedExceptions = SocialUserAuthenticationException.class) public void testAccessGrantInvalidState() throws Exception { identity = new AbstractSpringSocialOAuth2Identity() { };//w w w . j a v a 2 s.c o m final MockHttpServletRequest httpRequest = new MockHttpServletRequest(); httpRequest.addParameter("code", "mockCode"); httpRequest.addParameter("state", "mockState"); Assert.assertNull(identity.getAccessGrant(httpRequest)); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonResource1_8Test.java
/** * @see {@link https://issues.openmrs.org/browse/RESTWS-426} * @throws Exception/*from w w w . ja va2s . c o m*/ */ @Test public void testCorrectResourceForPatient() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("q", "Che"); RequestContext context = RestUtil.getRequestContext(request, new MockHttpServletResponse()); SimpleObject simple = getResource().search(context); List<SimpleObject> results = (List<SimpleObject>) simple.get("results"); assertFalse("A non-empty list is expected.", results.isEmpty()); for (SimpleObject result : results) { String selfLink = findSelfLink(result); assertFalse("Resource should be person, but is " + selfLink, selfLink.contains("/patient/")); } }
From source file:it.geosolutions.httpproxy.service.ProxyServiceDefaultTest.java
/** * Test IProxyService execute as HTTP GET *///w ww. ja v a 2s . c om @Test public void testExecuteGet() { try { // Generate mocked request and response MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/proxy/"); mockRequest.addParameter("url", TEST_URL); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); // Call proxy execute proxy.execute(mockRequest, mockResponse); // Assert the response assertNotNull(mockResponse); assertEquals(mockResponse.getStatus(), HttpStatus.SC_OK); assertNotNull(mockResponse.getOutputStream()); assertNotNull(mockResponse.getContentType()); assertTrue(mockResponse.getContentType().contains("application/vnd.ogc.wms_xml")); LOGGER.info("Success proxy GET in '" + TEST_URL + "'"); LOGGER.info("************************ Response ************************"); LOGGER.info(mockResponse.getContentAsString()); LOGGER.info("********************** EoF Response **********************"); } catch (Exception e) { fail("Exception executing proxy-->\t" + e.getLocalizedMessage()); } }
From source file:org.hdiv.web.servlet.config.MvcNamespaceTests.java
@Test public void testCustomValidator() throws Exception { XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext); reader.loadBeanDefinitions(//from w ww. j a v a 2 s .c o m new ClassPathResource("/org/hdiv/web/context/WEB-INF/editable-custom-validator.xml", getClass())); assertEquals(5, appContext.getBeanDefinitionCount()); appContext.refresh(); AnnotationMethodHandlerAdapter adapter = appContext.getBean(AnnotationMethodHandlerAdapter.class); assertNotNull(adapter); TestController handler = new TestController(); // default web binding initializer behavior test MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("date", "2009-10-31"); MockHttpServletResponse response = new MockHttpServletResponse(); adapter.handle(request, response, handler); appContext.getBean(EditableParameterValidator.class).validate(null, null); assertFalse(handler.recordedValidationError); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.DrugControllerTest.java
@Test public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception { MockHttpServletRequest httpReq = new MockHttpServletRequest(); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); Object result = controller.retrieve(ResourceTestConstants.DRUG_UUID, httpReq); Assert.assertNotNull(result);//from w ww. j av a 2 s .c o m Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.LocationAttributeController1_9Test.java
@Test public void shouldVoidAttribute() throws Exception { LocationAttribute locationAttribute = service.getLocationAttributeByUuid(getUuid()); Assert.assertFalse(locationAttribute.isVoided()); MockHttpServletRequest request = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); request.addParameter("reason", "unit test"); handle(request);/*w ww .j a v a2s. co m*/ locationAttribute = service.getLocationAttributeByUuid(getUuid()); Assert.assertTrue(locationAttribute.isVoided()); Assert.assertEquals("unit test", locationAttribute.getVoidReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0.ConceptAttributeController2_0Test.java
@Test public void shouldVoidAttribute() throws Exception { ConceptAttribute conceptAttribute = service.getConceptAttributeByUuid(getUuid()); Assert.assertFalse(conceptAttribute.isVoided()); MockHttpServletRequest request = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); request.addParameter("reason", "unit test"); handle(request);//from w w w . j a v a 2 s. c o m conceptAttribute = service.getConceptAttributeByUuid(getUuid()); Assert.assertTrue(conceptAttribute.isVoided()); Assert.assertEquals("unit test", conceptAttribute.getVoidReason()); }
From source file:com.gisgraphy.test.GisgraphyTestHelper.java
public static MockHttpServletRequest createMockHttpServletRequestForReverseGeocoding() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(GisgraphyServlet.FORMAT_PARAMETER, "XML"); request.addParameter(GeolocQuery.LAT_PARAMETER, "1.0"); request.addParameter(GeolocQuery.LONG_PARAMETER, "2.0"); return request; }
From source file:org.araneaframework.tests.WidgetTest.java
/** * Testing reading from valid request.// ww w . j a va2s.c o m */ public void testFormRequestHandling() throws Exception { FormWidget testForm = makeUsualForm(); Widget currentWidget = testForm; MockHttpServletRequest validRequest = new MockHttpServletRequest(); validRequest.addParameter("testForm.__present", "true"); validRequest.addParameter("testForm.myCheckBox", "true"); 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"); MockUiLibUtil.emulateHandleRequest(currentWidget, "testForm", validRequest); currentWidget._getWidget().process(); assertTrue(((StringArrayRequestControl.ViewModel) testForm.getControlByFullName("myCheckBox")._getViewable() .getViewModel()).getSimpleValue().equals("true")); assertTrue(((StringArrayRequestControl.ViewModel) testForm.getControlByFullName("myLongText")._getViewable() .getViewModel()).getSimpleValue().equals("108")); assertTrue(((StringArrayRequestControl.ViewModel) testForm.getControlByFullName("hierarchyTest.myTextarea") ._getViewable().getViewModel()).getSimpleValue().equals("blah")); assertTrue(((StringArrayRequestControl.ViewModel) testForm.getControlByFullName("hierarchyTest.mySelect") ._getViewable().getViewModel()).getSimpleValue().equals("2")); }