List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * Test adding a concept with a preferred name, short name, description and synonyms. * /*from ww w . ja v a 2 s . com*/ * @throws Exception */ @Test public void shouldAddConceptWithAllNamingSpecified() throws Exception { final String EXPECTED_PREFERRED_NAME = "no such concept"; final String EXPECTED_SHORT_NAME = "nonesuch"; final String EXPECTED_DESCRIPTION = "this is not really a concept"; final String EXPECTED_SYNONYM_A = "phantom"; final String EXPECTED_SYNONYM_B = "imaginary"; final String EXPECTED_SYNONYM_C = "mock"; AdministrationService as = Context.getAdministrationService(); GlobalProperty gp = as.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST); gp.setPropertyValue("en_GB, en_US"); as.saveGlobalProperty(gp); ConceptService cs = Context.getConceptService(); // make sure the concept doesn't already exist Concept conceptToAdd = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNull(conceptToAdd); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("synonymsByLocale[en_GB][0].name", EXPECTED_SYNONYM_A); mockRequest.setParameter("synonymsByLocale[en_GB][1].name", EXPECTED_SYNONYM_B); mockRequest.setParameter("synonymsByLocale[en_GB][2].name", EXPECTED_SYNONYM_C); mockRequest.setParameter("shortNamesByLocale[en_GB].name", EXPECTED_SHORT_NAME); mockRequest.setParameter("descriptionsByLocale[en_GB].description", EXPECTED_DESCRIPTION); mockRequest.setParameter("namesByLocale[en_GB].name", EXPECTED_PREFERRED_NAME); mockRequest.setParameter("concept.datatype", "1"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, response); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept actualConcept = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNotNull(actualConcept); Collection<ConceptName> actualNames = actualConcept.getNames(); assertEquals(5, actualNames.size()); assertEquals(EXPECTED_PREFERRED_NAME, actualConcept.getFullySpecifiedName(britishEn).getName()); assertNotNull(actualConcept.getShortNameInLocale(britishEn)); assertEquals(EXPECTED_SHORT_NAME, actualConcept.getShortNameInLocale(britishEn).getName()); assertNotNull(actualConcept.getDescription(britishEn)); assertEquals(EXPECTED_DESCRIPTION, actualConcept.getDescription(britishEn).getDescription()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This test concept form being submitted with only one name supplied * /*from w w w . j av a 2 s.com*/ * @throws Exception */ @Test public void shouldAddConceptWithOnlyNameSpecified() throws Exception { final String EXPECTED_PREFERRED_NAME = "no such concept"; ConceptService cs = Context.getConceptService(); // make sure the concept doesn't already exist Concept conceptToAdd = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNull(conceptToAdd); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("namesByLocale[en_GB].name", EXPECTED_PREFERRED_NAME); mockRequest.setParameter("descriptionsByLocale[en_GB].description", "some description"); mockRequest.setParameter("concept.datatype", "1"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept actualConcept = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNotNull(actualConcept); assertEquals(EXPECTED_PREFERRED_NAME, actualConcept.getFullySpecifiedName(britishEn).getName()); Collection<ConceptName> actualNames = actualConcept.getNames(); assertEquals(1, actualNames.size()); assertNull(actualConcept.getShortNameInLocale(britishEn)); assertNotNull(actualConcept.getDescription(britishEn)); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @verifies should add new concept attributes on creating concept * @throws Exception/*from ww w .j a v a 2 s . co m*/ */ @Test public void shouldSaveConceptAttributeOnCreatingConcept() throws Exception { executeDataSet(CONCEPT_ATTRIBUTES_XML); final String EXPECTED_PREFERRED_NAME = "concept with attribute"; ConceptService cs = Context.getConceptService(); // make sure the concept doesn't already exist Concept conceptToAdd = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNull(conceptToAdd); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("namesByLocale[en_GB].name", EXPECTED_PREFERRED_NAME); mockRequest.setParameter("descriptionsByLocale[en_GB].description", "some description"); mockRequest.setParameter("concept.datatype", "1"); mockRequest.setParameter("attribute.1.new[0]", "2011-04-25"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept actualConcept = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNotNull(actualConcept); final Collection<ConceptAttribute> attributes = actualConcept.getAttributes(); assertEquals(1, attributes.size()); final ConceptAttribute conceptAttribute = attributes.iterator().next(); assertEquals("2011-04-25", conceptAttribute.getValueReference()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This tests a concept form being submitted with also a short name supplied * // w w w. ja va 2s .c o m * @throws Exception */ @Test public void shouldAddConceptWithNameAndShortNameSpecified() throws Exception { final String EXPECTED_PREFERRED_NAME = "no such concept"; final String EXPECTED_SHORT_NAME = "nonesuch"; ConceptService cs = Context.getConceptService(); // make sure the concept doesn't already exist Concept conceptToAdd = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNull(conceptToAdd); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("shortNamesByLocale[en_GB].name", EXPECTED_SHORT_NAME); mockRequest.setParameter("namesByLocale[en_GB].name", EXPECTED_PREFERRED_NAME); mockRequest.setParameter("descriptionsByLocale[en_GB].description", "some description"); mockRequest.setParameter("concept.datatype", "1"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept actualConcept = cs.getConceptByName(EXPECTED_PREFERRED_NAME); assertNotNull(actualConcept); Collection<ConceptName> actualNames = actualConcept.getNames(); assertEquals(2, actualNames.size()); assertEquals(EXPECTED_PREFERRED_NAME, actualConcept.getFullySpecifiedName(britishEn).getName()); assertEquals(1, actualConcept.getShortNames().size()); assertNotNull(actualConcept.getShortNameInLocale(britishEn)); assertEquals(EXPECTED_SHORT_NAME, actualConcept.getShortNameInLocale(britishEn).getName()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w ww. j a va2 s. c o m*/ @Test @Verifies(value = "should copy numeric values into numeric concepts", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldCopyNumericValuesIntoNumericConcepts() throws Exception { final Double EXPECTED_LOW_ABSOLUTE = 100.0; final Double EXPECTED_LOW_CRITICAL = 103.0; final Double EXPECTED_LOW_NORMAL = 105.0; final Double EXPECTED_HI_NORMAL = 110.0; final Double EXPECTED_HI_CRITICAL = 117.0; final Double EXPECTED_HI_ABSOLUTE = 120.0; ConceptService cs = Context.getConceptService(); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("namesByLocale[en_GB].name", "WEIGHT (KG)"); mockRequest.setParameter("conceptId", "5089"); mockRequest.setParameter("concept.datatype", "1"); mockRequest.setParameter("lowAbsolute", EXPECTED_LOW_ABSOLUTE.toString()); mockRequest.setParameter("lowCritical", EXPECTED_LOW_CRITICAL.toString()); mockRequest.setParameter("lowNormal", EXPECTED_LOW_NORMAL.toString()); mockRequest.setParameter("hiNormal", EXPECTED_HI_NORMAL.toString()); mockRequest.setParameter("hiCritical", EXPECTED_HI_CRITICAL.toString()); mockRequest.setParameter("hiAbsolute", EXPECTED_HI_ABSOLUTE.toString()); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); ConceptNumeric concept = (ConceptNumeric) cs.getConcept(5089); Assert.assertEquals(EXPECTED_LOW_NORMAL, concept.getLowNormal()); Assert.assertEquals(EXPECTED_HI_NORMAL, concept.getHiNormal()); Assert.assertEquals(EXPECTED_LOW_ABSOLUTE, concept.getLowAbsolute()); Assert.assertEquals(EXPECTED_HI_ABSOLUTE, concept.getHiAbsolute()); Assert.assertEquals(EXPECTED_LOW_CRITICAL, concept.getLowCritical()); Assert.assertEquals(EXPECTED_HI_CRITICAL, concept.getHiCritical()); }
From source file:ch.ralscha.extdirectspring.controller.RouterController.java
@RequestMapping(value = "/router", method = RequestMethod.POST, params = "extAction") public String router(HttpServletRequest request, HttpServletResponse response, @RequestParam("extAction") String extAction, @RequestParam("extMethod") String extMethod) throws IOException { ExtDirectResponse directResponse = new ExtDirectResponse(request); MethodInfo methodInfo = this.methodInfoCache.get(extAction, extMethod); boolean streamResponse; if (methodInfo != null && methodInfo.getForwardPath() != null) { return methodInfo.getForwardPath(); } else if (methodInfo != null && methodInfo.getHandlerMethod() != null) { streamResponse = this.configurationService.getConfiguration().isStreamResponse() || methodInfo.isStreamResponse(); HandlerMethod handlerMethod = methodInfo.getHandlerMethod(); try {/*from w w w . j av a 2s. c o m*/ ModelAndView modelAndView; if (this.configurationService.getConfiguration().isSynchronizeOnSession() || methodInfo.isSynchronizeOnSession()) { HttpSession session = request.getSession(false); if (session != null) { Object mutex = WebUtils.getSessionMutex(session); synchronized (mutex) { modelAndView = this.handlerAdapter.handle(request, response, handlerMethod); } } else { modelAndView = this.handlerAdapter.handle(request, response, handlerMethod); } } else { modelAndView = this.handlerAdapter.handle(request, response, handlerMethod); } Map<String, Object> model = modelAndView.getModel(); if (model.containsKey("extDirectFormPostResult")) { ExtDirectFormPostResult formPostResult = (ExtDirectFormPostResult) model .get("extDirectFormPostResult"); directResponse.setResult(formPostResult.getResult()); directResponse.setJsonView(getJsonView(formPostResult, methodInfo.getJsonView())); } else if (model.containsKey("edFormPostResult")) { EdFormPostResult formPostResult = (EdFormPostResult) model.get("edFormPostResult"); directResponse.setResult(formPostResult.result()); directResponse.setJsonView(getJsonView(formPostResult, methodInfo.getJsonView())); } } catch (Exception e) { log.error("Error calling method: " + extMethod, e.getCause() != null ? e.getCause() : e); directResponse.setResult(handleException(methodInfo, directResponse, e, request)); } } else { streamResponse = this.configurationService.getConfiguration().isStreamResponse(); log.error("Error invoking method '" + extAction + "." + extMethod + "'. Method or Bean not found"); handleMethodNotFoundError(directResponse, extAction, extMethod); } writeJsonResponse(response, directResponse, null, streamResponse, ExtDirectSpringUtil.isMultipart(request)); return null; }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w ww. j a v a2s . co m*/ @Test @Verifies(value = "should return a concept with a null id if no match is found", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldReturnAConceptWithANullIdIfNoMatchIsFound() throws Exception { ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("GET"); mockRequest.setParameter("conceptId", "57432223"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); ConceptFormBackingObject formBackingObject = (ConceptFormBackingObject) mav.getModel().get("command"); assertNotNull(formBackingObject.getConcept()); assertNull(formBackingObject.getConcept().getConceptId()); }
From source file:org.guanxi.sp.engine.service.shibboleth.AuthConsumerServiceThread.java
/** * This chunky method actually performs the meat of the AA conversation. The conversation can * be split into 4 parts, each of which is relayed to the user through an update to the progress * bar:/*from w w w . ja v a 2s . com*/ * * 1) Preparing the request to the Attribute Authority * 2) Send the request to and read the response of the Attribute Authority * 3) Preparing the request to the Guard which contains the meat of the response from the Attribute Authority * 4) Sending the request to the Guard and confirming that it was accepted * * Once this has been completed the user is redirected to the Guard Podder URL which will set the * cookie associated with the Guard that indicates that the user has logged in. */ @SuppressWarnings("unchecked") public void run() { ModelAndView mAndV; String aaResponse, guardResponse; EnvelopeDocument aaSoapRequest, guardSoapRequest; mAndV = new ModelAndView(); // done getting configuration information, lets make the connection to the AA setStatus(preparingAARequest); aaSoapRequest = prepareAARequest(idpProviderId, idpNameIdentifier, entityID); logger.debug("Request to AA:\n" + aaSoapRequest); setStatus(readingAAResponse); try { aaResponse = processAAConnection(aaURL, entityID, keystoreFile, keystorePassword, truststoreFile, truststorePassword, aaSoapRequest); // no close, so no finally logger.debug("Response from AA:\n" + aaResponse); } catch (Exception e) { logger.error("AA connection error", e); mAndV.setViewName(parent.getErrorView()); mAndV.getModel().put(parent.getErrorViewDisplayVar(), e.getMessage()); mAndV.getModel().put(parent.getErrorViewSimpleVar(), "There was a problem connecting to the Attribute Authority. " + "Check that the Attribute Authority Server Certificate is " + "correct and that the Attribute Authority accepts the client" + "certificate of this Service Provider."); setStatus(mAndV); setCompleted(true); return; } // done with the connection to the AA, lets talk to the Guard setStatus(preparingGuardRequest); try { guardSoapRequest = prepareGuardRequest(samlResponse, guardSession, aaURL, aaResponse); } catch (XmlException e) { // this is caused by parsing the AA response, and so is a problem with the attribute authority not the guard logger.error("AA SAML Response parse error", e); logger.error("SOAP response:"); logger.error("------------------------------------"); logger.error(aaResponse); logger.error("------------------------------------"); mAndV.setViewName(parent.getErrorView()); mAndV.getModel().put(parent.getErrorViewDisplayVar(), e.getMessage()); mAndV.getModel().put(parent.getErrorViewSimpleVar(), "There was a problem parsing the response from the Attribute " + "Authority. Check that the Attribute Authority URL is correct."); setStatus(mAndV); setCompleted(true); return; } setStatus(readingGuardResponse); try { guardResponse = processGuardConnection(acsURL, entityID, keystoreFile, keystorePassword, truststoreFile, truststorePassword, guardSoapRequest, guardSession); } catch (Exception e) { logger.error("Guard ACS connection error", e); mAndV.setViewName(parent.getErrorView()); mAndV.getModel().put(parent.getErrorViewDisplayVar(), e.getMessage()); mAndV.getModel().put(parent.getErrorViewSimpleVar(), "There was a problem communicating with the Guard. Check " + "that the Guard is running."); setStatus(mAndV); setCompleted(true); return; } // Done talking to the guard. Redirect to the Podder mAndV.setViewName(parent.getPodderView()); mAndV.getModel().put("podderURL", podderURL + "?id=" + guardSession); setStatus(mAndV); setCompleted(true); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * Checks that the conceptId query param gets a concept from the database * //w w w . jav a 2s.co m * @throws Exception */ @Test public void shouldGetConcept() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", ""); request.setParameter("conceptId", "3"); HttpServletResponse response = new MockHttpServletResponse(); ConceptFormController controller = (ConceptFormController) applicationContext.getBean("conceptForm"); ModelAndView modelAndView = controller.handleRequest(request, response); // make sure there is an "conceptId" filled in on the concept ConceptFormBackingObject command = (ConceptFormBackingObject) modelAndView.getModel().get("command"); Assert.assertNotNull(command.getConcept().getConceptId()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w w w . ja v a2 s. c om*/ @Test @Verifies(value = "should display numeric values from table", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldDisplayNumericValuesFromTable() throws Exception { final Double EXPECTED_LOW_ABSOLUTE = 0.0; final Double EXPECTED_LOW_CRITICAL = 99.0; final Double EXPECTED_LOW_NORMAL = 445.0; final Double EXPECTED_HI_NORMAL = 1497.0; final Double EXPECTED_HI_CRITICAL = 1800.0; final Double EXPECTED_HI_ABSOLUTE = 2500.0; ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("GET"); mockRequest.setParameter("conceptId", "5497"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); ConceptFormBackingObject formBackingObject = (ConceptFormBackingObject) mav.getModel().get("command"); Assert.assertEquals(EXPECTED_LOW_NORMAL, formBackingObject.getLowNormal()); Assert.assertEquals(EXPECTED_HI_NORMAL, formBackingObject.getHiNormal()); Assert.assertEquals(EXPECTED_LOW_ABSOLUTE, formBackingObject.getLowAbsolute()); Assert.assertEquals(EXPECTED_HI_ABSOLUTE, formBackingObject.getHiAbsolute()); Assert.assertEquals(EXPECTED_LOW_CRITICAL, formBackingObject.getLowCritical()); Assert.assertEquals(EXPECTED_HI_CRITICAL, formBackingObject.getHiCritical()); }