List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java
/** * Test of request: show customers started from firstname, result success. *///w ww .jav a 2 s . co m @Test public void testListCustomersByFirstNameSuccess() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ListCustomersController listCustomersController = new ListCustomersController( new CustomerRepositoryMockImpl()); request.setMethod("GET"); request.setRequestURI("/listcustomers"); request.setParameter("firstName", "first"); request.setParameter("lastName", ""); try { ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, listCustomersController); ModelAndViewAssert.assertViewName(mv, "listcustomers"); List<Customer> customers = (List<Customer>) mv.getModel().get("customers"); assertNotNull(customers); assertEquals(5, customers.size()); } catch (Exception ex) { fail(); } }
From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java
/** * Test of request: show customer by fistname, result success. *///from w w w. jav a 2 s .co m @Test public void testFindCustomerByFirstNameSuccess() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ListCustomersController listCustomersController = new ListCustomersController( new CustomerRepositoryMockImpl()); request.setMethod("GET"); request.setRequestURI("/listcustomers"); request.setParameter("firstName", "firstname1"); request.setParameter("lastName", ""); try { ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, listCustomersController); ModelAndViewAssert.assertViewName(mv, "listcustomers"); List<Customer> customers = (List<Customer>) mv.getModel().get("customers"); assertNotNull(customers); assertEquals(1, customers.size()); } catch (Exception ex) { fail(); } }
From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java
/** * Test of request: show customers by firstname, result failure. *///from w w w . j a va 2 s.c om @Test public void testListCustomersByFirstNameFailure() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ListCustomersController listCustomersController = new ListCustomersController( new CustomerRepositoryMockImpl()); request.setMethod("GET"); request.setRequestURI("/listcustomers"); request.setParameter("firstName", "last"); request.setParameter("lastName", ""); try { ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, listCustomersController); ModelAndViewAssert.assertViewName(mv, "listcustomers"); List<Customer> customers = (List<Customer>) mv.getModel().get("customers"); assertNotNull(customers); assertTrue(customers.isEmpty()); } catch (Exception ex) { fail(); } }
From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java
/** * Test of request: show customers started from firstname and lastname, * result success./*from w w w. j av a 2s .c o m*/ */ @Test public void testListCustomersByFirstLastNameSuccess() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ListCustomersController listCustomersController = new ListCustomersController( new CustomerRepositoryMockImpl()); request.setMethod("GET"); request.setRequestURI("/listcustomers"); request.setParameter("firstName", "first"); request.setParameter("lastName", "last"); try { ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, listCustomersController); ModelAndViewAssert.assertViewName(mv, "listcustomers"); List<Customer> customers = (List<Customer>) mv.getModel().get("customers"); assertNotNull(customers); assertEquals(5, customers.size()); } catch (Exception ex) { fail(); } }
From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java
/** * Test of request: show customers by firstname lastname, result failure. *//*from www . ja v a 2 s . c o m*/ @Test public void testListCustomersByFirstLastNameFailure() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ListCustomersController listCustomersController = new ListCustomersController( new CustomerRepositoryMockImpl()); request.setMethod("GET"); request.setRequestURI("/listcustomers"); request.setParameter("firstName", "fr"); request.setParameter("lastName", "last"); try { ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, listCustomersController); ModelAndViewAssert.assertViewName(mv, "listcustomers"); List<Customer> customers = (List<Customer>) mv.getModel().get("customers"); assertNotNull(customers); assertTrue(customers.isEmpty()); } catch (Exception ex) { fail(); } }
From source file:ch.silviowangler.dox.web.DocumentController.java
@RequestMapping(method = GET, value = "/document/edit/{id}") public ModelAndView editDocument(@PathVariable("id") Long id) { ModelAndView modelAndView = new ModelAndView("edit.doc", new HashMap<String, Object>()); try {/*from w w w .j a v a 2 s.c o m*/ final DocumentReference documentReference = documentService.findDocumentReference(id); final SortedSet<Attribute> attributes = documentService .findAttributes(documentReference.getDocumentClass()); modelAndView.getModel().put("doc", documentReference); modelAndView.getModel().put("attributes", attributes); } catch (DocumentNotFoundException | DocumentClassNotFoundException e) { logger.error("No such document", e); } return modelAndView; }
From source file:edu.duke.cabig.c3pr.web.admin.CreateNotificationController.java
protected void respondAjaxFreeText(ModelAndView modelAndView, HttpServletResponse response) throws Exception { PrintWriter pr = response.getWriter(); pr.println(modelAndView.getModel().get(getFreeTextModelName())); pr.flush();/*from w w w . j ava2 s. c om*/ }
From source file:alpha.portal.webapp.controller.ContributorRoleControllerTest.java
/** * V-Test (save, show, edit, delete).// w ww . ja va 2 s .co m * * @throws Exception * the exception */ @SuppressWarnings("unchecked") @Test public void testVTest() throws Exception { final String newCRName = "New Test Contributor Role"; final int numberOfRolesBeforeAdd = this.contributorRoleManager.getAll().size(); /** * Add */ MockHttpServletRequest request = this.newPost("/contributorRole"); request.setRemoteUser(this.testUserName); request.addParameter("save_new", "button.save"); request.addParameter("newContributorRole", newCRName); MockHttpServletResponse response = new MockHttpServletResponse(); this.ctrl.saveNew(request, response); Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage())); /** * Show */ request = this.newGet("/contributorRole"); request.setRemoteUser(this.testUserName); ModelAndView result = this.ctrl.showPage(request); Map<String, Object> resModel = result.getModel(); final Object contribListObj = resModel.get("contributorRolesList"); final List<ContributorRole> contribList = (List<ContributorRole>) contribListObj; Assert.assertEquals((numberOfRolesBeforeAdd + 1), contribList.size()); ContributorRole newCR = this.contributorRoleManager.getContributorRoleByName(newCRName); boolean contains = false; for (int c = 0; (c < contribList.size()) && (contains == false); c++) { if (contribList.get(c).getName().equals(newCRName)) { contains = true; } } Assert.assertTrue("New contrib.role in roles list", contains); /** * Edit-Page */ request = this.newGet("/contributorRole"); request.setRemoteUser(this.testUserName); request.addParameter("edit", newCR.getContributorRoleId().toString()); result = this.ctrl.showPage(request); resModel = result.getModel(); Assert.assertTrue(resModel.containsKey("showEditingForm")); Assert.assertTrue(resModel.containsKey("roleToEditId")); Assert.assertTrue(resModel.containsKey("roleToEdit")); Assert.assertFalse(resModel.containsKey("messageId")); Assert.assertEquals(newCR.getContributorRoleId().toString(), resModel.get("roleToEditId")); Assert.assertEquals(newCR.getName(), resModel.get("roleToEdit")); /** * Edit-Post */ request = this.newPost("/contributorRole"); request.setRemoteUser(this.testUserName); request.addParameter("save_edit", "button.save"); request.addParameter("newContributorRole", newCRName + " - Changed"); request.addParameter("oldContribRoleId", newCR.getContributorRoleId().toString()); response = new MockHttpServletResponse(); this.ctrl.saveEdit(request, response); Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage())); newCR = this.contributorRoleManager.get(newCR.getContributorRoleId()); Assert.assertEquals(newCRName + " - Changed", newCR.getName()); /** * Delete */ request = this.newPost("/contributorRole"); request.setRemoteUser(this.testUserName); request.addParameter("delete", newCR.getContributorRoleId().toString()); result = this.ctrl.showPage(request); resModel = result.getModel(); Assert.assertTrue(resModel.containsKey("contributorRolesList")); Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage())); boolean isException = false; try { newCR = this.contributorRoleManager.get(newCR.getContributorRoleId()); } catch (final ObjectRetrievalFailureException e) { isException = true; } Assert.assertTrue("role not deleted", isException); }
From source file:org.guanxi.sp.engine.service.saml2.DiscoveryProfileService.java
/** @see org.guanxi.sp.engine.service.generic.ProfileService#doProfile(javax.servlet.http.HttpServletRequest, String, String, org.guanxi.xal.saml2.metadata.GuardRoleDescriptorExtensions, String, org.guanxi.common.entity.EntityFarm) */ public ModelAndView doProfile(HttpServletRequest request, String guardID, String guardSessionID, GuardRoleDescriptorExtensions guardNativeMetadata, String entityID, EntityFarm farm) throws GuanxiException { ModelAndView mAndV = new ModelAndView(); mAndV.setViewName(viewName);// w w w .j a va 2s . c om try { String edsURL = edsBaseURL + "?entityID=" + URLEncoder.encode(guardID, "UTF-8"); edsURL += "&return=" + URLEncoder.encode(request.getRequestURL() + "?" + Guanxi.WAYF_PARAM_GUARD_ID + "=" + guardID + "&" + Guanxi.WAYF_PARAM_SESSION_ID + "=" + guardSessionID, "UTF-8"); edsURL += "&returnIDParam=" + URLEncoder.encode("edsEntityID", "UTF-8"); mAndV.getModel().put("edsURL", edsURL); } catch (UnsupportedEncodingException use) { logger.error("Could not encode EDS URL", use); mAndV.getModel().put("edsError", use.getMessage()); } return mAndV; }
From source file:com.tms.controller.customer.CustomerController.java
@RequestMapping("/binging") public ModelAndView bingingCompany(String id, HttpServletRequest request) { ModelAndView view = new ModelAndView(); User user = SessionUtils.getUser(request); Company company = companyService.findById(id); if (company == null) { view.getModel().put("message", "error"); return view; }//from w w w. j a va 2s . c o m user.setCompany(company); view.getModel().put("message", "success"); return view; }