List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:ch.silviowangler.dox.web.DocumentControllerTest.java
@Test public void editDocumentWithParams2() throws DocumentNotFoundException { final DocumentReference documentReference = newDocumentReference("hello.txt").withDocumentClass("test") .withIndex("name", "Wangler").build(); when(documentService.findDocumentReference(1L)).thenReturn(documentReference); when(documentService.updateIndices(documentReference)).thenReturn(documentReference); MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("firstname", "Silvio"); final ModelAndView modelAndView = controller.editDocument(1L, request); assertThat(modelAndView.getViewName(), is("import.successful")); assertThat(modelAndView.getModel().size(), is(1)); assertThat(modelAndView.getModel().containsKey("doc"), is(true)); final DocumentReference doc = (DocumentReference) modelAndView.getModel().get("doc"); assertThat(doc, is(documentReference)); assertThat(doc.getIndices().get(new TranslatableKey("name")).getValue().toString(), is("Wangler")); InOrder order = inOrder(documentService); order.verify(documentService).findDocumentReference(1L); order.verify(documentService, never()).updateIndices(documentReference); order.verifyNoMoreInteractions();//from w w w . ja va2 s . c o m }
From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java
@Test public void testIllegalArgumentException() { RestErrorHandler errorHandler = new RestErrorHandler(); HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); Exception e = new IllegalArgumentException("Descriptive Error Message"); ModelAndView errorResponse = errorHandler.createApiErrorResponse(e, request, response); // The default error status code for IllegalArgumentException is 400 Assert.assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST.value()); Assert.assertNotNull(errorResponse); Assert.assertNotNull(errorResponse.getModel().get("ErrorDetails")); // Response payload with default error code and the // IllegalArgumentException's message assertRestApiErrorResponse(errorResponse, "FAILED", "Descriptive Error Message"); }
From source file:org.openmrs.web.controller.OptionsFormControllerTest.java
@Test public void shouldRejectEmptyNotificationAddress() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("POST", ""); request.setParameter("notification", "email"); request.setParameter("notificationAddress", ""); HttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) modelAndView.getModel() .get("org.springframework.validation.BindingResult.opts"); Assert.assertTrue(bindingResult.hasErrors()); }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.SharedBuildNumberController.java
protected ModelAndView editBuildNumber(HttpServletRequest request, HttpServletResponse response) throws IOException { Integer id = this.getId(request); if (id != null) { SharedBuildNumber form = this.configurationService.getSharedBuildNumber(id); if (form != null) { ModelAndView modelAndView = new ModelAndView(this.editJspPagePath); modelAndView.getModel().put(SharedBuildNumberController.PREFIX, BuildNumberPropertiesProvider.PARAMETER_PREFIX); modelAndView.getModel().put(SharedBuildNumberController.FORM, form); return modelAndView; }/*from w w w.j av a2 s . co m*/ } SharedBuildNumberController.logger.info("Edit requested for non-existent shared build number."); WebUtil.notFound(request, response, "The shared build number you are trying to edit does not exist.", SharedBuildNumberController.logger); return null; }
From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java
/** * Test new./*from w w w . j a v a 2 s . c o m*/ * * @throws Exception * the exception */ @Test public void testNew() throws Exception { final MockHttpServletRequest request = this.newGet("/caseform"); request.setRemoteUser("admin"); final HttpServletResponse response = new MockHttpServletResponse(); final ModelAndView mv = this.form.showForm(this.filters, request, response); Assert.assertNotNull(mv); Assert.assertEquals("caseform", mv.getViewName()); Assert.assertEquals(new AlphaCase(), mv.getModel().get("case")); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormController.java
/** * Handles requests for a new {@code RadiologyOrder} for a specific patient. * /*w w w. ja va 2 s . c om*/ * @param patient the existing patient which should be associated with a new radiology order * returned in the model and view * @return model and view containing new radiology order * @should populate model and view with new radiology order prefilled with given patient */ @RequestMapping(method = RequestMethod.GET, params = "patientId") protected ModelAndView getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient( @RequestParam("patientId") Patient patient) { final ModelAndView modelAndView = getRadiologyOrderFormWithNewRadiologyOrder(); Order order = (Order) modelAndView.getModel().get("radiologyOrder"); order.setPatient(patient); modelAndView.addObject("patientId", patient.getPatientId()); return modelAndView; }
From source file:ru.org.linux.topic.TopicModificationController.java
@RequestMapping(value = "/mtn.jsp", method = RequestMethod.GET) public ModelAndView moveTopicForm(ServletRequest request, @RequestParam int msgid) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("Not authorized"); }/*www . j av a 2s . co m*/ ModelAndView mv = new ModelAndView("mtn"); Topic message = messageDao.getById(msgid); Section section = sectionService.getSection(message.getSectionId()); mv.getModel().put("message", message); mv.getModel().put("groups", groupDao.getGroups(section)); return mv; }
From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java
/** * Test edit./*from w ww. ja v a 2s . c o m*/ * * @throws Exception * the exception */ @Test public void testEdit() throws Exception { MockHttpServletRequest request = this.newGet("/caseform"); request.setParameter("caseId", CaseFormControllerTest.caseId); request.setRemoteUser("admin"); final ModelAndView mv = this.form.showForm(this.filters, request, new MockHttpServletResponse()); Assert.assertEquals("caseform", mv.getViewName()); final AlphaCase aCase = (AlphaCase) mv.getModel().get("case"); AlphaCase dbCase = this.caseManager.get(CaseFormControllerTest.caseId); Assert.assertEquals(dbCase, aCase); Assert.assertEquals(dbCase.getAlphaCards(), mv.getModel().get("cards")); Assert.assertEquals(dbCase.getListOfParticipants(), mv.getModel().get("participants")); request = this.newPost("/caseform"); request.setRemoteUser("admin"); aCase.setName("test case with a new name"); final BindingResult errors = new DataBinder(aCase).getBindingResult(); final String view = this.form.saveCase(aCase, errors, request, new MockHttpServletResponse()); Assert.assertEquals("redirect:/caseform?caseId=" + aCase.getCaseId(), view); Assert.assertFalse(errors.hasErrors()); Assert.assertNotNull(request.getSession().getAttribute("successMessages")); final Locale locale = request.getLocale(); final ArrayList<Object> msgs = (ArrayList<Object>) request.getSession().getAttribute("successMessages"); Assert.assertTrue(msgs.contains(this.form.getText("case.updated", locale))); dbCase = this.caseManager.get(CaseFormControllerTest.caseId); /* FIXME: something is broken (return structure is an empty thing) */ // Assert.assertEquals(dbCase, aCase); }
From source file:ch.silviowangler.dox.web.DocumentControllerTest.java
@Test public void editDocumentWhenThrowsException() throws Exception { when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L)); final ModelAndView modelAndView = controller.editDocument(1L, new MockHttpServletRequest()); assertThat(modelAndView.getViewName(), is("modification.doc.failed")); assertThat(modelAndView.getModel().isEmpty(), is(true)); }
From source file:com.zb.app.web.controller.line.LineController.java
/** * //from w w w .jav a 2 s .c o m * * @param id * @param model * @return */ @RequestMapping(value = "/line/linedate.htm") public ModelAndView linedate(String id, ModelAndView model) { TravelLineQuery query = new TravelLineQuery(); query.setlGroupNumber(id); TravelLineDO trdo = lineService.find(query); model.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false"); model.addObject("line", trdo); model.setViewName("/line/linedate"); return model; }