List of usage examples for org.springframework.mock.web MockHttpServletRequest setMethod
public void setMethod(@Nullable String method)
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//* ww w . j av a2s .c om*/ @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.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *///from w w w. ja v a 2 s. com @Test @Verifies(value = "should set the local preferred name", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldSetTheLocalPreferredName() throws Exception { ConceptService cs = Context.getConceptService(); Concept concept = cs.getConcept(5497); //sanity check, the current preferred Name should be different from what will get set in the form Assert.assertNotSame("CD3+CD4+ABS CNT", concept.getPreferredName(britishEn).getName()); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "5497"); mockRequest.setParameter("preferredNamesByLocale[en_GB]", "CD3+CD4+ABS CNT"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Assert.assertEquals("CD3+CD4+ABS CNT", concept.getPreferredName(britishEn).getName()); //preferred name should be the new one that has been set from the form Assert.assertEquals(true, concept.getPreferredName(britishEn).isLocalePreferred()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This tests removing a concept set/* w w w . ja v a 2s . c o m*/ * * @throws Exception */ @Test public void shouldRemoveConceptSet() throws Exception { ConceptService cs = Context.getConceptService(); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "23"); mockRequest.setParameter("namesByLocale[en_GB].name", "FOOD CONSTRUCT"); mockRequest.setParameter("concept.datatype", "4"); mockRequest.setParameter("concept.class", "10"); mockRequest.setParameter("concept.conceptSets", "18 19"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept concept = cs.getConcept(23); assertNotNull(concept); assertEquals(2, concept.getConceptSets().size()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This tests removing an answer/*from w w w. j a v a 2 s. c om*/ * * @throws Exception */ @Test public void shouldRemoveConceptAnswer() throws Exception { ConceptService cs = Context.getConceptService(); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "21"); mockRequest.setParameter("namesByLocale[en_GB].name", "FOOD ASSISTANCE FOR ENTIRE FAMILY"); mockRequest.setParameter("concept.datatype", "2"); mockRequest.setParameter("concept.class", "7"); mockRequest.setParameter("concept.answers", "7 8"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept concept = cs.getConcept(21); assertNotNull(concept); assertEquals(2, concept.getAnswers(false).size()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This test makes sure that all answers are deleted if the user changes this concept's datatype * to something other than "Coded"/*from w ww . j a va 2 s . co m*/ * * @throws Exception */ @Test public void shouldRemoveConceptAnswersIfDatatypeChangedFromCoded() throws Exception { ConceptService cs = Context.getConceptService(); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "4"); // this must be a concept id that is not used in an observation in order to be changed mockRequest.setParameter("namesByLocale[en_GB].name", "CIVIL STATUS"); mockRequest.setParameter("concept.datatype", "1"); // set it to something other than "Coded" mockRequest.setParameter("concept.class", "10"); mockRequest.setParameter("concept.answers", "5 6"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept concept = cs.getConcept(4); assertNotNull(concept); assertEquals(0, concept.getAnswers(false).size()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w w w . j av a 2 s . c o m*/ @Test @Verifies(value = "should void a synonym marked as preferred when it is removed", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldVoidASynonymMarkedAsPreferredWhenItIsRemoved() throws Exception { ConceptService cs = Context.getConceptService(); Concept concept = cs.getConcept(5497); //mark one of the synonyms as preferred ConceptName preferredName = new ConceptName("pref name", britishEn); preferredName.setLocalePreferred(true); concept.addName(preferredName); cs.saveConcept(concept); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "5497"); //remove the synonym that is marked as preferred mockRequest.setParameter("synonymsByLocale[en_GB][0].voided", "true"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Assert.assertEquals(true, preferredName.isVoided()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * This test makes sure that ConceptComplex objects can be edited * /*from www . j a v a 2 s. co m*/ * @throws Exception */ @Test public void shouldEditConceptComplex() throws Exception { executeDataSet("org/openmrs/api/include/ObsServiceTest-complex.xml"); ConceptService cs = Context.getConceptService(); ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", "8473"); mockRequest.setParameter("namesByLocale[en_GB].name", "A complex concept"); mockRequest.setParameter("descriptionsByLocale[en_GB].description", "some description"); mockRequest.setParameter("concept.datatype", "13"); mockRequest.setParameter("concept.class", "5"); mockRequest.setParameter("handlerKey", "TextHandler"); // switching it from an ImageHandler to a TextHandler ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept concept = cs.getConcept(8473); assertEquals(ConceptComplex.class, concept.getClass()); ConceptComplex complex = (ConceptComplex) concept; assertEquals("TextHandler", complex.getHandler()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @see ConceptFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *///from w ww . j ava 2 s.c o m @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()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @verifies should add new concept attributes * @throws Exception/*w ww.j av a 2s . c om*/ */ @Test public void shouldSaveConceptAttribute() throws Exception { executeDataSet(CONCEPT_ATTRIBUTES_XML); ConceptService cs = Context.getConceptService(); ConceptAttributeType conceptAttributeType = cs.getConceptAttributeType(1); final Integer conceptId = 5089; ConceptFormController conceptFormController = (ConceptFormController) applicationContext .getBean("conceptForm"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("POST"); mockRequest.setParameter("action", ""); mockRequest.setParameter("conceptId", conceptId.toString()); mockRequest.setParameter("attribute." + conceptAttributeType.getId() + ".new[1]", "2014-03-12"); ModelAndView mav = conceptFormController.handleRequest(mockRequest, new MockHttpServletResponse()); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Concept actualConcept = cs.getConcept(conceptId); assertNotNull(actualConcept); final Collection<ConceptAttribute> attributes = actualConcept.getAttributes(); assertEquals(1, attributes.size()); final ConceptAttribute conceptAttribute = attributes.iterator().next(); assertEquals("2014-03-12", conceptAttribute.getValueReference()); }
From source file:org.openmrs.web.controller.ConceptFormControllerTest.java
/** * @verifies should add new concept attributes on creating concept * @throws Exception/*from w w 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()); }