List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:shiver.me.timbers.security.web.controller.HomeControllerTest.java
@Test public void Can_display_home_page() { final String username = "User Name"; final User user = mock(User.class); // Given/* www . j a v a 2s. co m*/ given(user.getUsername()).willReturn(username); // When final ModelAndView actual = new HomeController().display(user); // Then assertThat(actual.getViewName(), equalTo("home")); assertThat(actual.getModel().get("username").toString(), equalTo(username)); }
From source file:demo.oauth.server.controllers.ApplicationController.java
private ModelAndView handleInternalRedirect(ClientApp app) { ModelAndView modelAndView = new ModelAndView("newClientForm"); modelAndView.getModel().put("client", app); return modelAndView; }
From source file:org.slc.sli.dashboard.unit.controller.LayoutControllerTest.java
@SuppressWarnings("unchecked") @Test/*w w w .j av a2 s.c om*/ public void testHandleLos() throws Exception { try { ModelAndView mv = layoutController.handleLos(request); Assert.assertEquals(2, ((Map<String, Config>) mv.getModel().get(Constants.MM_KEY_VIEW_CONFIGS)).size()); } catch (Exception e) { Assert.fail("Should pass but getting " + e.getMessage()); } }
From source file:org.sventon.web.ctrl.template.BlameControllerTest.java
@Test public void testSvnHandle() throws Exception { final RepositoryService mockService = EasyMock.createMock(RepositoryService.class); final Colorer colorer = new Colorer() { public String getColorizedContent(String content, String fileExtension, String encoding) throws IOException { return content; }//from ww w . j a v a2 s . c o m }; final AnnotatedTextFile annotatedFile = new AnnotatedTextFile(); final UserRepositoryContext context = new UserRepositoryContext(); context.setCharset("UTF-8"); final BaseCommand command = new BaseCommand(); command.setPath("trunk/test"); command.setName(new RepositoryName("test")); command.setRevision(Revision.create(12)); final BlameController ctrl = new BlameController(colorer); ctrl.setRepositoryService(mockService); expect(mockService.blame(null, command.getPath(), command.getRevisionNumber(), context.getCharset(), colorer)).andStubReturn(annotatedFile); replay(mockService); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, context, null, null, null); final Map model = modelAndView.getModel(); verify(mockService); assertEquals(1, model.size()); assertEquals(annotatedFile, model.get("annotatedFile")); }
From source file:jetbrains.buildServer.clouds.azure.asm.web.ProfileController.java
@Override protected ModelAndView doGet(@NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) { ModelAndView mv = new ModelAndView(myJspPath); mv.getModel().put("refreshablePath", myHtmlPath); mv.getModel().put("resPath", myResourcePath); return mv;/* ww w .j a v a 2s . c om*/ }
From source file:org.sventon.web.ctrl.template.SearchLogsControllerTest.java
@Test public void testSvnHandle() throws Exception { final CacheGateway mockCache = EasyMock.createMock(CacheGateway.class); final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(SEARCH_STRING_PARAMETER, "abc"); request.addParameter(START_DIR_PARAMETER, "/trunk/"); final BaseCommand command = new BaseCommand(); command.setPath("trunk/test"); command.setName(new RepositoryName("test")); command.setRevision(Revision.create(12)); final SearchLogsController ctrl = new SearchLogsController(); ctrl.setCacheGateway(mockCache);//from www. j a v a 2 s. com final List<LogMessageSearchItem> result = new ArrayList<LogMessageSearchItem>(); result.add(new LogMessageSearchItem( TestUtils.createLogEntry(123, "jesper", new Date(), "Revision 123.", null))); expect(mockCache.find(command.getName(), "abc", "/trunk/")).andStubReturn(result); replay(mockCache); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, request, null, null); final Map model = modelAndView.getModel(); verify(mockCache); assertEquals(4, model.size()); assertEquals("abc", model.get(SEARCH_STRING_PARAMETER)); assertEquals("/trunk/", model.get(START_DIR_PARAMETER)); assertEquals(result, model.get("logEntries")); assertTrue((Boolean) model.get("isLogSearch")); }
From source file:InventoryControllerTests.java
@Test public void testHandleRequestView() throws Exception { InventoryController controller = new InventoryController(); SimpleProductManager spm = new SimpleProductManager(); spm.setProductDao(new InMemoryProductDao(new ArrayList<Product>())); controller.setProductManager(spm);/* w w w . j a v a2 s. co m*/ //controller.setProductManager(new SimpleProductManager()); ModelAndView modelAndView = controller.handleRequest(null, null); assertEquals("hello", modelAndView.getViewName()); assertNotNull(modelAndView.getModel()); Map modelMap = (Map) modelAndView.getModel().get("model"); String nowValue = (String) modelMap.get("now"); assertNotNull(nowValue); }
From source file:com.epam.cme.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"; } else { robotsValue = "index,follow"; }// w w w.j a v a 2s . c om } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) { robotsValue = "no-index,no-follow"; } modelAndView.addObject("metaRobots", robotsValue); } }
From source file:org.openmrs.web.controller.person.AddPersonControllerTest.java
/** * @see AddPersonController#formBackingObject(HttpServletRequest) * @verifies catch an invalid birthdate/*from w ww.j a v a 2 s . c o m*/ */ @Test public void formBackingObject_shouldCatchAnInvalidBirthdate() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", ""); HttpServletResponse response = new MockHttpServletResponse(); request.setParameter("addName", "Gayan Perera"); request.setParameter("addBirthdate", "03/07/199s"); request.setParameter("addGender", "M"); request.setParameter("personType", "patient"); request.setParameter("viewType", "edit"); AddPersonController controller = (AddPersonController) applicationContext.getBean("addPerson"); ModelAndView mav = controller.handleRequest(request, response); assertNotNull(mav); assertEquals("Person.birthdate.required", mav.getModel().get("errorMessage")); }
From source file:se.vgregion.urlservice.controllers.AdminGuiControllerTest.java
@Test public void index() throws IOException { UrlServiceService urlServiceService = mock(UrlServiceService.class); List<RedirectRule> rules = Arrays.asList(new RedirectRule(DOMAIN, PATTERN, URL.toString())); when(urlServiceService.findAllRedirectRules()).thenReturn(rules); controller.setUrlServiceService(urlServiceService); ModelAndView mav = controller.index(); Assert.assertEquals(rules, mav.getModel().get("redirectRules")); }