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.resource.openmrs2_0.UserResource2_0Test.java
/** * Assert that a search with the given parameters returns an expected number of results. * // w w w .j a v a 2s . co m * @param userName The user name to search for. * @param roles The roles to search for. * @param expectedResultCount The expected result count for the given search parameters. * @throws ResponseException */ @SuppressWarnings("unchecked") private void assertSearch(final String userName, final Collection<String> roles, final int expectedResultCount) throws ResponseException { // input final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("q", userName); if (roles != null) { final String rolesAsCommaSeparatedString = StringUtils.join(roles, ","); request.addParameter(UserResource2_0.PARAMETER_ROLES, rolesAsCommaSeparatedString); } final RequestContext context = RestUtil.getRequestContext(request, new MockHttpServletResponse()); // search final SimpleObject simple = getResource().search(context); final List<SimpleObject> results = (List<SimpleObject>) simple.get("results"); // verify final String errorMessage = "Number of results does not match for: userName=" + userName + ", roles=" + roles + ", Results=" + results; Assert.assertEquals(errorMessage, expectedResultCount, results.size()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.PatientIdentifierController1_9Test.java
@Test public void shouldPurgeAPatientIdentifier() throws Exception { long initialIdCount = getAllCount(); assertNotNull(service.getPatientIdentifierByUuid(getUuid())); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("purge", ""); handle(req);/*from w w w.j av a2 s . co m*/ assertNull(service.getPatientIdentifierByUuid(getUuid())); assertEquals(--initialIdCount, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.ConceptReferenceTermController1_9Test.java
@Test public void shouldRetireAConceptReferenceTerm() throws Exception { assertEquals(false, service.getConceptReferenceTermByUuid(getUuid()).isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("!purge", ""); final String reason = "none"; req.addParameter("reason", reason); handle(req);// w w w . ja v a2s . com assertEquals(true, service.getConceptReferenceTermByUuid(getUuid()).isRetired()); assertEquals(reason, service.getConceptReferenceTermByUuid(getUuid()).getRetireReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.UserResource1_8Test.java
/** * Assert that a search with the given parameters returns an expected number of results. * @param userName The user name to search for. * @param roles The roles to search for. * @param expectedResultCount The expected result count for the given search parameters. * @throws ResponseException/*from w w w .j ava2 s .com*/ */ @SuppressWarnings("unchecked") private void assertSearch(final String userName, final Collection<String> roles, final int expectedResultCount) throws ResponseException { // input final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("q", userName); if (roles != null) { final String rolesAsCommaSeparatedString = StringUtils.join(roles, ","); request.addParameter(UserResource1_8.PARAMETER_ROLES, rolesAsCommaSeparatedString); } final RequestContext context = RestUtil.getRequestContext(request, new MockHttpServletResponse()); // search final SimpleObject simple = getResource().search(context); final List<SimpleObject> results = (List<SimpleObject>) simple.get("results"); // verify final String errorMessage = "Number of results does not match for: userName=" + userName + ", roles=" + roles + ", Results=" + results; Assert.assertEquals(errorMessage, expectedResultCount, results.size()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.PatientController1_8Test.java
@Test public void shouldSearchAndReturnAListOfPatientsMatchingTheQueryString() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "Horatio"); SimpleObject result = deserialize(handle(req)); assertEquals(1, Util.getResultsSize(result)); assertEquals(getUuid(), PropertyUtils.getProperty(Util.getResultsList(result).get(0), "uuid")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.PatientIdentifierController1_9Test.java
@Test public void shouldVoidAPatientIdentifier() throws Exception { assertEquals(false, service.getPatientIdentifierByUuid(getUuid()).isVoided()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("!purge", ""); final String reason = "none"; req.addParameter("reason", reason); handle(req);/*from w w w. jav a 2 s .c o m*/ assertEquals(true, service.getPatientIdentifierByUuid(getUuid()).isVoided()); assertEquals(reason, service.getPatientIdentifierByUuid(getUuid()).getVoidReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_10.OrderTypeController1_10Test.java
@Test public void shouldRetireAnOrderType() throws Exception { assertEquals(false, service.getOrderTypeByUuid(getUuid()).isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("!purge", ""); final String reason = "none"; req.addParameter("reason", reason); handle(req);//from w ww. ja v a 2s .c om assertEquals(true, service.getOrderTypeByUuid(getUuid()).isRetired()); assertEquals(reason, service.getOrderTypeByUuid(getUuid()).getRetireReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.CohortController1_8Test.java
@Test public void purgeCohort_shouldPurgeCohort() throws Exception { MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("purge", ""); handle(req);//w w w . j a v a 2 s. co m Assert.assertNull(service.getCohortByUuid(getUuid())); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ProblemController1_8Test.java
@Test public void voidProblem_shouldVoidAProblem() throws Exception { final int id = 2; Problem problem = patientService.getProblem(id); assertEquals(false, problem.isVoided()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + problem.getUuid()); req.addParameter("!purge", ""); final String reason = "none"; req.addParameter("reason", reason); handle(req);//from w w w . ja v a2 s . c o m problem = patientService.getProblem(id); assertEquals(true, problem.isVoided()); assertEquals(reason, problem.getVoidReason()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ProgramController1_8Test.java
@Test public void shouldRetireAProgram() throws Exception { Program program = service.getProgram(2); Assert.assertFalse(program.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + program.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "some good reason"); handle(req);//from w w w .ja va 2s.c om Program retiredProgram = service.getProgram(2); Assert.assertTrue(retiredProgram.isRetired()); Assert.assertEquals("some good reason", retiredProgram.getRetireReason()); }