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.DrugController1_8Test.java
@Test public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception { MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertNotNull(result);/*from w w w. ja v a 2s. c o m*/ Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.CohortController1_8Test.java
@Test public void getCohorts_shouldSearchForCohortsByName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "B13"); SimpleObject result = deserialize(handle(req)); List<Object> results = (List<Object>) result.get("results"); Assert.assertEquals(2, results.size()); Util.log("Found " + results.size() + " cohort(s)", results); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationTagController1_8Test.java
@Test public void shouldRetireLocationTag() throws Exception { LocationTag locationTag = service.getLocationTag(2); Assert.assertFalse(locationTag.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + locationTag.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "random reason"); handle(req);// w ww . j ava2 s.com LocationTag retiredLocationTag = service.getLocationTag(2); Assert.assertTrue(retiredLocationTag.isRetired()); Assert.assertEquals("random reason", retiredLocationTag.getRetireReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SystemSettingController1_9Test.java
@Test public void shouldSaveSystemSettingWithCustomDatatype() throws Exception { SimpleObject property = new SimpleObject(); property.add("property", "a.property.test"); property.add("description", "Testing post operation of global property"); property.add("datatypeClassname", "org.openmrs.customdatatype.datatype.BooleanDatatype"); property.add("value", "true"); String json = new ObjectMapper().writeValueAsString(property); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes());/*w ww. j ava 2 s. c o m*/ SimpleObject newlyCreatedSetting = deserialize(handle(req)); String uuid = (String) PropertyUtils.getProperty(newlyCreatedSetting, "uuid"); MockHttpServletRequest getReq = request(RequestMethod.GET, getURI() + "/" + uuid); getReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(getReq)); assertEquals("a.property.test", PropertyUtils.getProperty(result, "property")); assertEquals("Testing post operation of global property", PropertyUtils.getProperty(newlyCreatedSetting, "description")); assertEquals("true", PropertyUtils.getProperty(result, "value")); assertEquals("org.openmrs.customdatatype.datatype.BooleanDatatype", PropertyUtils.getProperty(result, "datatypeClassname")); assertNull(PropertyUtils.getProperty(result, "datatypeConfig")); }
From source file:org.jasig.cas.web.ServiceValidateControllerTests.java
@Test public void testInvalidServiceTicket() throws Exception { final String tId = getCentralAuthenticationService() .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword()); final String sId = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService()); getCentralAuthenticationService().destroyTicketGrantingTicket(tId); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", TestUtils.getService().getId()); request.addParameter("ticket", sId); assertEquals(CONST_FAILURE_VIEW, this.serviceValidateController .handleRequestInternal(request, new MockHttpServletResponse()).getViewName()); }
From source file:org.jasig.cas.web.ServiceValidateControllerTests.java
@Test public void testValidServiceTicketWithPgt() throws Exception { this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler()); final String tId = getCentralAuthenticationService() .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword()); final String sId = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", TestUtils.getService().getId()); request.addParameter("ticket", sId); request.addParameter("pgtUrl", "https://www.acs.rutgers.edu"); assertEquals(CONST_SUCCESS_VIEW, this.serviceValidateController .handleRequestInternal(request, new MockHttpServletResponse()).getViewName()); }
From source file:org.jasig.cas.web.ServiceValidateControllerTests.java
@Test public void testValidServiceTicketWithBadPgt() throws Exception { this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler()); final String tId = getCentralAuthenticationService() .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword()); final String sId = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", TestUtils.getService().getId()); request.addParameter("ticket", sId); request.addParameter("pgtUrl", "http://www.acs.rutgers.edu"); final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()); assertEquals(CONST_SUCCESS_VIEW, modelAndView.getViewName()); assertNull(modelAndView.getModel().get("pgtIou")); }
From source file:org.jasig.cas.web.ServiceValidateControllerTests.java
@Test public void testValidServiceTicketWithInvalidPgt() throws Exception { this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler()); final String tId = getCentralAuthenticationService() .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword()); final String sId = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", TestUtils.getService().getId()); request.addParameter("ticket", sId); request.addParameter("pgtUrl", "duh"); final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()); assertEquals(CONST_SUCCESS_VIEW, modelAndView.getViewName()); assertNull(modelAndView.getModel().get("pgtIou")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.DrugController1_8Test.java
@Test public void shouldPurgeADrug() throws Exception { Drug drug = service.getDrug(11);/* ww w. j av a 2s .c o m*/ MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + drug.getUuid()); req.addParameter("purge", ""); handle(req); Assert.assertNull(service.getDrug(11)); }
From source file:alpha.portal.webapp.controller.CardAssignFormControllerTest.java
/** * Test show form.//from w ww. jav a 2s .c o m */ @Test public void testShowForm() { final MockHttpServletRequest request = this.newGet("/cardassignform"); request.setRemoteUser("admin"); request.addParameter("card", ""); request.addParameter("case", ""); Model m = new ExtendedModelMap(); this.form.showForm(request, m); Assert.assertFalse(m.containsAttribute("users")); request.setParameter("card", "440e4816-e01b-74d4-a716-449955440092"); m = new ExtendedModelMap(); this.form.showForm(request, m); Assert.assertFalse(m.containsAttribute("users")); request.setParameter("case", "atjaerhe"); m = new ExtendedModelMap(); this.form.showForm(request, m); Assert.assertFalse(m.containsAttribute("users")); request.setParameter("case", "550e4713-e22b-11d4-a716-446655440000"); m = new ExtendedModelMap(); this.form.showForm(request, m); final List<UserExtension> l = new LinkedList<UserExtension>(); l.add(this.userExtensionManager.get(-5L)); l.add(this.userExtensionManager.get(-4L)); l.add(this.userExtensionManager.get(-2L)); // FIXME the sample-data.xml change concerning the contributorrole // values has broken this // ModelAndViewAssert.assertModelAttributeValue(new ModelAndView("", // m.asMap()), "users", l); }