List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:org.jasig.cas.services.web.ManageRegisteredServicesMultiActionControllerTests.java
public void testManage() { final RegisteredServiceImpl r = new RegisteredServiceImpl(); r.setId(1200);//from w w w .ja v a 2s. c o m r.setName("name"); r.setServiceId("test"); r.setEvaluationOrder(2); this.servicesManager.save(r); final ModelAndView modelAndView = this.controller.manage(new MockHttpServletRequest(), new MockHttpServletResponse()); assertNotNull(modelAndView); assertEquals("manageServiceView", modelAndView.getViewName()); final Collection c = (Collection) modelAndView.getModel().get("services"); assertTrue(c.contains(r)); }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.ViewControllerImpl.java
protected ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object command, BindException errors) throws Exception { Map request = HttpServletHelper.getInstance().createRequestMap(httpServletRequest); Map session = HttpServletHelper.getInstance().createSessionMap(httpServletRequest); Map application = HttpServletHelper.getInstance().createApplicationMap(httpServletRequest); if (controller instanceof CustomCommandController) { command = ((CustomCommandController) controller).formBackingObject(request, session, application); }//from w ww.j a va 2s. com if (command != null) { ServletRequestDataBinder binder = createBinder(httpServletRequest, command); binder.bind(httpServletRequest); } if (controller instanceof LoadObjectController) { command = ((LoadObjectController) controller).fillBackingObject(command, request, session, application); } ModelAndView returnedMv = controller.handleRequest(command, request, session, application, errors); if (returnedMv.getViewName() != null) { // should get from mappings String mappedView = (String) screenMappings.get(returnedMv.getViewName()); if (mappedView == null) { mappedView = returnedMv.getViewName(); } /* if (controller instanceof ContextAwareController){ ((ContextAwareController) controller).addContexts(getHelpManager().getActiveContexts(session), returnedMv.getModel(), mappedView); } else { getHelpManager().addContexts(session, mappedView); } getControllerFilterManager().processFilters(request, session, application, returnedMv, mappedView); */ returnedMv = new ModelAndView(mappedView, returnedMv.getModel()); } HttpServletHelper.getInstance().reloadApplicationMap(httpServletRequest, application); HttpServletHelper.getInstance().reloadSessionMap(httpServletRequest, session); HttpServletHelper.getInstance().reloadRequestMap(httpServletRequest, request); return returnedMv; }
From source file:org.wallride.web.support.DefaultModelAttributeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mv) throws Exception { if (mv == null) return;//from w w w.ja v a 2 s . co m if (mv.getView() instanceof RedirectView) return; if (mv.getViewName().startsWith("redirect:")) return; Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); mv.addObject("BLOG", blog); List<String> languages = new ArrayList<>(); if (blog != null) { for (BlogLanguage blogLanguage : blog.getLanguages()) { languages.add(blogLanguage.getLanguage()); } } String currentLanguage = LocaleContextHolder.getLocale().getLanguage(); mv.addObject("LANGUAGES", languages.toArray(new String[languages.size()])); mv.addObject("LANGUAGE_LINKS", buildLanguageLinks(currentLanguage, languages, request)); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); AuthorizedUser authorizedUser = null; if (authentication != null && authentication.getPrincipal() instanceof AuthorizedUser) { authorizedUser = (AuthorizedUser) authentication.getPrincipal(); } mv.addObject("USER", authorizedUser); mv.addObject("WEBSITE_TITLE", blog != null ? blog.getTitle(currentLanguage) : null); mv.addObject("WEBSITE_LINK", buildGuestLink()); mv.addObject("WEBSITE_PATH", buildGuestPath(currentLanguage, languages)); mv.addObject("ADMIN_LINK", buildAdminLink()); mv.addObject("ADMIN_PATH", buildAdminPath(currentLanguage)); }
From source file:com.all.backend.web.util.JsonResponseInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView != null && modelAndView.getViewName() != null && !modelAndView.getViewName().endsWith(".jsp")) { modelAndView.setView(JSON_VIEW); }/*w w w. j a v a 2 s.c o m*/ }
From source file:se.vgregion.pubsub.admin.controller.AdminControllerTest.java
@Test public void updatePushSubscriber() throws Exception { ModelAndView mav = controller.updatePushSubscriber(ID, TOPIC, CALLBACK, null, LEASE, TOKEN, SECRET, true, null);//ww w . j av a2s. c om Assert.assertEquals("redirect:../..", mav.getViewName()); Mockito.verify(adminService).updatePushSubscriber(ID, TOPIC, CALLBACK, null, LEASE, TOKEN, SECRET, true); }
From source file:ch.silviowangler.dox.web.DocumentControllerTest.java
@Test public void editWhenThrowsException() throws Exception { when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L)); final ModelAndView modelAndView = controller.editDocument(1L); assertThat(modelAndView.getViewName(), is("edit.doc")); assertThat(modelAndView.getModel().isEmpty(), is(true)); }
From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java
@Override public void logUserAction(HttpServletRequest request, UserAction action, ModelAndView model) { log.info(MessageFormat.format("[action={0}, view={1}, {2}]", action, model.getViewName(), printLogAffix(request)));/* w w w. j a v a2s . c om*/ }
From source file:org.openmrs.module.patientregistration.controller.workflow.PrimaryCareReceptionEncounterControllerTest.java
@Test @Ignore//from w ww . j av a2 s. c om public void showSelectPatient_shouldReturnPaymentGroups() throws Exception { Patient patient = Context.getPatientService().getPatient(6); String listOfObs = "[{CODED,2002,Medical certificate without diagnosis,1000,0;NUMERIC,0,50 Gourdes,1001,0;NON-CODED,0,12345,1002,0;}" + ", {CODED,2001,Standard outpatient visit,1000,0;NUMERIC,0,100 Gourdes,1001,0;NON-CODED,0,98765,1002,0;}]"; PrimaryCareReceptionEncounterController controller = new PrimaryCareReceptionEncounterController(); controller.setAdtService(Context.getService(AdtService.class)); controller.setEmrProperties(emrProperties); Calendar now = Calendar.getInstance(); String year = "" + now.get(Calendar.YEAR); String month = "" + (1 + now.get(Calendar.MONTH)); String day = "" + now.get(Calendar.DAY_OF_MONTH); ExtendedModelMap model = new ExtendedModelMap(); ModelAndView modelAndView = controller.processPayment(patient, listOfObs, false, year, month, day, false, null, null, session, model); String viewName = modelAndView.getViewName(); Assert.assertEquals("redirect:/module/patientregistration/workflow/patientDashboard.form?patientId=" + patient.getPatientId(), viewName); Visit activeVisit = Context.getService(AdtService.class) .getActiveVisit(patient, PatientRegistrationWebUtil.getRegistrationLocation(session)).getVisit(); assertNotNull(activeVisit); assertThat(activeVisit.getEncounters().size(), is(1)); assertThat(activeVisit.getEncounters().iterator().next().getEncounterType(), is(PatientRegistrationGlobalProperties.GLOBAL_PROPERTY_PRIMARY_CARE_RECEPTION_ENCOUNTER_TYPE())); model = new ExtendedModelMap(); modelAndView = controller.showSelectPatient(patient, null, null, null, session, model); List<List<POCObservation>> pocPaymentGroups = (List<List<POCObservation>>) model.get("pocPaymentGroups"); assertThat(pocPaymentGroups.size(), is(2)); // assertThat(pocPaymentGroups.iterator().next().iterator().next().getLabel(), contains() containsInAnyOrder("Medical certificate without diagnosis", "Standard outpatient visit")); if (pocPaymentGroups != null && pocPaymentGroups.size() > 0) { log.debug("printing pocPaymentGroups"); for (List<POCObservation> paymentGroup : pocPaymentGroups) { for (POCObservation pocObservation : paymentGroup) { log.debug("\tobsId=" + pocObservation.getObsId()); log.debug("\tconceptName=" + pocObservation.getConceptName()); log.debug("\tconceptId=" + pocObservation.getConceptId()); } } } }
From source file:ar.com.zauber.commons.spring.exceptions.StatusSimpleMappingExceptionHandlerTest.java
/** test */ public final void testFoo() { final Properties views = new Properties(); views.put(NotOwnerException.class.getName(), "notowner"); views.put(IllegalArgumentException.class.getName(), "arguments"); views.put(DataAccessResourceFailureException.class.getName(), "data"); final Properties status = new Properties(); status.put("arguments", "400"); status.put("notowner", "403"); status.put("data", "500"); final StatusSimpleMappingExceptionHandler h = new StatusSimpleMappingExceptionHandler(); h.setDefaultStatusCode(200);//from w w w .j a v a2s.co m h.setExceptionMappings(views); h.setStatusMappings(status); h.setDefaultErrorView("default"); MockHttpServletResponse response; ModelAndView v; response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new IOException("io!io!")); assertEquals("default", v.getViewName()); assertEquals(200, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new IllegalArgumentException("asdasd")); assertEquals("arguments", v.getViewName()); assertEquals(400, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new NotOwnerException()); assertEquals("notowner", v.getViewName()); assertEquals(403, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new DataAccessResourceFailureException("bla bla")); assertEquals("data", v.getViewName()); assertEquals(500, response.getStatus()); }
From source file:org.zilverline.web.TestSearchController.java
public void testOnSubmit() throws ServletException { SearchController searchC = (SearchController) applicationContext.getBean("searchController"); assertNotNull(searchC);/*from w w w . j a v a 2 s . c o m*/ CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); // get testdate collection DocumentCollection testdata = colMan.getCollectionByName("testdata"); assertNotNull(testdata); int numberOfDocs = 14; try { if (!testdata.isIndexValid() || testdata.getNumberOfDocs() != numberOfDocs) { testdata.index(true); } assertTrue(testdata.isIndexValid()); assertEquals(numberOfDocs, testdata.getNumberOfDocs()); } catch (IndexException e) { fail(e.getMessage()); } MockHttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); SearchForm sf = new SearchForm(); sf.setCollections(new CollectionTriple[] { new CollectionTriple(testdata, true) }); sf.setStartAt(-1); sf.setQuery("test"); ModelAndView mv = searchC.onSubmit(request, response, sf, new BindException(sf, "test")); assertEquals("returned correct view name", mv.getViewName(), "search"); assertTrue(mv.getModel().containsKey("results")); Result[] results = (Result[]) mv.getModel().get("results"); assertNotNull(results); assertEquals("11 results", 11, results.length); if (results.length > 0) { Result firstResult = results[0]; assertEquals(testdata.getName(), firstResult.getCollection()); } }