List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:com.comcast.video.dawg.show.ViewControllerTest.java
@Test(dataProvider = "testStbSimplifiedViewData") public void testStbECPView(String remoteType, String actualRemote, String mobileParam, String ua, boolean isMobile, String traceUrl, boolean traceAvailable) throws IOException { MetaStb stb = TestUtils.createGenericMetaStb(); stb.setRemoteType(remoteType);/* w ww. j a v a 2 s.c o m*/ stb.setSerialHost(traceUrl); MockMetaStbCache cache = new MockMetaStbCache(); cache.cache.put(TestUtils.ID, stb); RemoteManager remoteMan = new RemoteManager(); remoteMan.load(); ViewController controller = new ViewController(); Wiring.autowire(controller, cache); Wiring.autowire(controller, remoteMan); ModelAndView mav = controller.stbSimplifiedView(TestUtils.ID, mobileParam, null, null, ua); Assert.assertEquals(mav.getModel().get(ViewConstants.MOBILE), isMobile); Assert.assertEquals(mav.getModel().get(ViewConstants.TRACE_AVAILABLE), traceAvailable); Remote remote = (Remote) mav.getModel().get(ViewConstants.REMOTE); Assert.assertEquals(remote.getName(), actualRemote); }
From source file:org.mifos.ui.core.controller.RedirectionControllerTest.java
public void testHandleRequest() throws ServletException, IOException { String expectedPageToRedirectTo = "foopage"; RedirectionController controller = new RedirectionController(); controller.setViewToRedirectTo(expectedPageToRedirectTo); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse); Assert.assertEquals(expectedPageToRedirectTo, modelAndView.getViewName()); Assert.assertNotNull(modelAndView.getModel()); Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model"); Object response = modelMap.get("response"); Assert.assertNotNull(response);/*w ww . ja v a2 s. c om*/ Assert.assertEquals(MockHttpServletResponse.class, response.getClass()); }
From source file:org.sventon.web.ctrl.template.DirEntryTrayControllerTest.java
private Map executeTest() throws Exception { expect(mockService.getEntryInfo(null, command.getPath(), command.getPegRevision().getNumber())) .andStubReturn(entry);/*from w ww. j a v a 2 s .co m*/ replay(mockService); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, context, request, null, null); verify(mockService); return modelAndView.getModel(); }
From source file:nl.surfnet.coin.selfservice.control.HomeControllerTest.java
@Test public void testIdp() throws Exception { Collection<SabPerson> maintainers = Collections.emptyList(); when(sabClient.getPersonsInRoleForOrganization(institutionIdentityProvider.getInstitutionId(), "SURFconextbeheerder")).thenReturn(maintainers); Collection<SabPerson> responsibles = Collections.emptyList(); when(sabClient.getPersonsInRoleForOrganization(institutionIdentityProvider.getInstitutionId(), "SURFconextverantwoordelijke")).thenReturn(responsibles); ModelAndView modelAndView = controller.idp(request); assertEquals("idp", modelAndView.getViewName()); assertTrue(modelAndView.getModel().containsKey("roleAssignments")); }
From source file:ru.org.linux.user.WhoisController.java
@RequestMapping(value = "/people/{nick}/profile", method = { RequestMethod.GET, RequestMethod.HEAD }, params = "wipe") public ModelAndView wipe(@PathVariable String nick, ServletRequest request) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("not moderator"); }//from www. j a va2 s . c o m User user = userDao.getUser(nick); user.checkAnonymous(); user.checkBlocked(); if (!user.isBlockable()) { throw new AccessViolationException("? ? "); } ModelAndView mv = new ModelAndView("wipe-user"); mv.getModel().put("user", user); mv.getModel().put("userStat", userDao.getUserStatisticsClass(user, true)); return mv; }
From source file:gov.nih.nci.cabig.caaers.tools.spring.tabbedflow.AutomaticSaveAjaxableFormController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { if (isAjaxRequest(request)) { synchronized (this) { ModelAndView superModelAndView = super.handleRequestInternal(request, response); ModelAndView modelAndView = getAjaxModelAndView(request); modelAndView.getModel().putAll(superModelAndView.getModel()); if (isAjaxResponseFreeText(modelAndView)) { respondAjaxFreeText(modelAndView, response); return null; }//from ww w. j a v a 2 s .c o m return modelAndView; } } return super.handleRequestInternal(request, response); }
From source file:com.carlos.projects.billing.ui.controllers.DocumentsControllerTest.java
@Test public void shouldListAllTheDocuments() throws Exception { // Given/* ww w .j a va2 s. c om*/ controller.setViewName(DOCUMENTS_VIEW_NAME); List<Document> documents = new ArrayList<Document>(); documents.add(new Document()); when(documentDAO.findAll("Document")).thenReturn(documents); // When ModelAndView modelAndView = controller.handleRequestInternal(request, response); // Then assertThat("Not all the documents are listed", (List<Document>) modelAndView.getModel().get("documents"), is(documents)); }
From source file:com.jeanchampemont.notedown.utils.PrettyTimeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView != null) { PrettyTime prettyTime = new PrettyTime(); prettyTime.setLocale(RequestContextUtils.getLocale(request)); modelAndView.getModel().put("prettyTime", prettyTime); }/* w ww . j av a2 s .c om*/ }
From source file:com.acc.storefront.interceptors.beforeview.SeoRobotsFollowBeforeViewHandler.java
@Override public void beforeView(final HttpServletRequest request, final HttpServletResponse response, final ModelAndView modelAndView) { // Check to see if the controller has specified a Index/Follow directive for robots if (modelAndView != null && !modelAndView.getModel().containsKey("metaRobots")) { // Build a default directive String robotsValue = "no-index,no-follow"; if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) { if (request.isSecure()) { robotsValue = "no-index,follow"; }//from w w w . j a va 2 s . co m //Since no model attribute metaRobots can be set for JSON response, then configure that servlet path in the xml. //If its a regular response and this setting has to be overriden then set model attribute metaRobots else if (CollectionUtils.contains(getRobotIndexForJSONMapping().keySet().iterator(), request.getServletPath())) { robotsValue = getRobotIndexForJSONMapping().get(request.getServletPath()); } else { robotsValue = "index,follow"; } } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) { robotsValue = "no-index,no-follow"; } modelAndView.addObject("metaRobots", robotsValue); } if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) { final MetaElementData metaElement = new MetaElementData(); metaElement.setName("robots"); metaElement.setContent((String) modelAndView.getModel().get("metaRobots")); ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement); } }
From source file:fm.last.citrine.web.AdminControllerTest.java
@Test public void testList() throws Exception { List<Task> runningTasks = new ArrayList<Task>(); Task task = new Task(); runningTasks.add(task);/*ww w .j a v a 2 s . c o m*/ when(mockTaskManager.getCurrentlyRunningTasks()).thenReturn(runningTasks); when(mockSchedulerManager.getStatus()).thenReturn(SchedulerStatus.STARTED); ModelAndView modelAndView = adminController.list(mockRequest, mockResponse); assertEquals("admin", modelAndView.getViewName()); Map<String, Object> model = modelAndView.getModel(); assertEquals(4, model.size()); assertEquals(runningTasks, model.get("currentTasks")); assertEquals(SchedulerStatus.STARTED, model.get("schedulerStatus")); }