Example usage for org.springframework.web.servlet ModelAndView getModelMap

List of usage examples for org.springframework.web.servlet ModelAndView getModelMap

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getModelMap.

Prototype

public ModelMap getModelMap() 

Source Link

Document

Return the underlying ModelMap instance (never null ).

Usage

From source file:com.healthcit.cacure.web.controller.admin.UserListControllerTest.java

@SuppressWarnings("unchecked")
@Test// w w w.  jav a 2  s .c om
public void testDelete() {
    ModelAndView expected = createMockModelAndView(1l);
    ModelAndView actual = userListController.deleteUser(1l, true);
    Assert.assertNotNull(actual);
    Assert.assertEquals((((List<UserCredentials>) expected.getModelMap().get("users")).size()),
            ((List<UserCredentials>) expected.getModelMap().get("users")).size());
}

From source file:nl.surfnet.coin.selfservice.interceptor.MenuInterceptorTest.java

private Menu executeTestAndReturnMenu(Authority... authorities) throws Exception {
    setUpAuthorities(authorities);/*from ww  w.ja v a 2 s . c o m*/
    ModelAndView modelAndView = new ModelAndView();
    MockHttpServletRequest request = new MockHttpServletRequest();
    menuInterceptor.postHandle(request, null, null, modelAndView);

    ModelMap modelMap = modelAndView.getModelMap();

    Menu menu = (Menu) modelMap.get("menu");
    return menu;
}

From source file:com.comcast.video.dawg.show.ViewControllerTest.java

@Test(dataProvider = "testStbViewNoStbData")
public void testStbViewNoStb(boolean byExc) {
    MockMetaStbCache cache = new MockMetaStbCache();
    cache.throwExc = byExc;//from  w ww .ja  v  a2s . c o  m
    ViewController controller = new ViewController();
    Wiring.autowire(controller, cache);

    ModelAndView mav = controller.stbView(DEVICE_ID, null, null, null, null);
    Assert.assertEquals(mav.getViewName(), ViewConstants.NOSTB);
    Assert.assertEquals(mav.getModelMap().get(ViewConstants.DEVICE_ID), DEVICE_ID);
}

From source file:nl.eveoh.sakai.mytimetable.tool.ToolControllerTest.java

@Test
public void testModel() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");

    // Display two test events
    List<Event> testEvents = new ArrayList<Event>();
    testEvents.add(new Event());
    testEvents.add(new Event());

    Mockito.when(myTimetableService.getUpcomingEvents(Mockito.anyString())).thenReturn(testEvents);
    Mockito.when(configuration.getApplicationUri()).thenReturn("https://timetable.institution.ac.uk/");
    Mockito.when(configuration.getApplicationTarget()).thenReturn("_blank");

    ModelAndView modelAndView = toolController.handleRequest(request, response);

    Assert.assertTrue("Should contain events attribute.",
            modelAndView.getModelMap().containsAttribute("events"));
    Assert.assertTrue(modelAndView.getModelMap().containsAttribute("applicationUri"));
    Assert.assertTrue(modelAndView.getModelMap().containsAttribute("applicationTarget"));

    Assert.assertEquals("Should display 5 events.", 2,
            ((List<Event>) modelAndView.getModelMap().get("events")).size());
    Assert.assertEquals("https://timetable.institution.ac.uk/",
            modelAndView.getModelMap().get("applicationUri"));
    Assert.assertEquals("_blank", modelAndView.getModelMap().get("applicationTarget"));

    Assert.assertEquals(200, response.getStatus());
}

From source file:com.klm.workshop.controller.AuthController.java

/**
 * Lets anonymous clients sign in//from   w w w. j a  v  a2s.  c  o m
 * 
 * @param model Autowired model and view
 * @param error Login error cause
 * @return Sign in view with the sign in error, if set
 */
@RequestMapping(value = "/sign-in", method = RequestMethod.GET)
public ModelAndView getSignIn(ModelAndView model,
        @RequestParam(value = "error", required = false, defaultValue = "") String error) {
    model.setViewName("auth/sign_in");
    model.getModelMap().addAttribute("error", error);
    model.getModelMap().addAttribute("user", new User());
    return model;
}

From source file:abid.password.springmvc.controller.CreateUserController.java

@RequestMapping(method = RequestMethod.GET, value = { "/{tab}" })
public ModelAndView handleGetCreateUserTab(@PathVariable("tab") String tab) {
    TabPanel tabPanel = buildTabPanel(tab);
    if (!tabPanel.isValidTab(tab)) {
        return new ModelAndView("redirect:/app/create/");
    }/*from  w  ww. ja  va2s .  c  o  m*/

    ModelAndView model = new ModelAndView("createUser");
    model.getModelMap().put("tabPanel", tabPanel);
    model.getModelMap().put("timeParameter", TimeParameter.values());
    return model;
}

From source file:com.healthcit.cacure.web.controller.QuestionListControllerTest.java

@Test
public void testShowSkipQuestionList() {
    Long formId = 1l;/*from w w  w  .  j av  a 2 s.c  o  m*/
    EasyMock.expect(formManager.getForm(formId)).andReturn(createMockQuestionForm(formId, 1));
    EasyMock.replay(formManager);
    ModelAndView actual = questionListController.showSkipQuestionList(1l, 1l);

    ModelAndView expected = new ModelAndView("questionListSkip");
    ModelMap model = expected.getModelMap();
    model.addAttribute("form", createMockQuestionForm(formId, 1));
    Assert.assertNotNull(actual);
    Assert.assertNotNull(expected.getModelMap().get("form"));
    Assert.assertEquals(((QuestionnaireForm) expected.getModelMap().get("form")).getQuestions().size(),
            ((QuestionnaireForm) actual.getModelMap().get("form")).getQuestions().size());
}

From source file:com.healthcit.cacure.web.interceptor.BreadCrumbsSupportInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (handler instanceof BreadCrumbsSupporter && modelAndView != null) {
        BreadCrumbsSupporter controller = (BreadCrumbsSupporter) handler;
        controller.setBreadCrumb(modelAndView.getModelMap());
    }/*from  ww  w. java2 s  .  co m*/
}

From source file:com.carlos.projects.billing.ui.controllers.AddComponentsControllerTest.java

@Test
public void shouldAddFamilyNameToModel() throws Exception {
    //Given/*  w w  w  . j  a  va 2s  .  c  o m*/
    String familyName = "familyName";
    when(request.getParameter("familyName")).thenReturn(familyName);
    //When
    ModelAndView modelAndView = controller.handleRequestInternal(request, response);
    //Then
    assertThat("Family name value is wrong", (String) modelAndView.getModelMap().get("familyName"),
            is(familyName));
}

From source file:org.n52.sensorweb.series.policy.editor.ctrl.SimplePermissionEditorControllerTest.java

@Test
public void testListPermission() {
    ModelAndView mav = controller.listPermissions(null);
    Assert.assertThat(mav.getViewName(), is("listPermissionSets"));
    Assert.assertTrue(mav.getModel().containsKey("permissionSets"));

    Map<String, Object> modelMap = mav.getModelMap();
    List<PermissionSet> permissionSets = (List<PermissionSet>) modelMap.get("permissionSets");
    Assert.assertNotNull(permissionSets);
    Assert.assertThat(permissionSets, is(not(empty())));
}