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.LoginControllerTest.java

@Test
public void testShowForms() {
    ModelAndView expected = new ModelAndView("login", "userCredentials", new UserCredentials());
    ModelAndView actual = loginController.showForm();
    Assert.assertNotNull(actual);//  w w  w.j a v a 2 s .c  o m
    Assert.assertEquals(expected.getViewName(), actual.getViewName());
    Assert.assertNotNull(actual.getModelMap().get("userCredentials"));
}

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

@SuppressWarnings("unchecked")
@Test//from  w w  w . j av a  2s  .  c o m
public void testShowModuleList() {
    EasyMock.expect(moduleManager.getAllModules()).andReturn(createMockModules());
    EasyMock.replay(moduleManager);
    ModelAndView expected = createMockModelAndView();
    ModelAndView actual = moduleListController.showModuleList();
    List<Module> expectedModules = (List<Module>) expected.getModelMap().get("modules");
    List<Module> actualModules = (List<Module>) actual.getModelMap().get("modules");
    Assert.assertNotNull(actual);
    Assert.assertEquals(expectedModules.size(), actualModules.size());
}

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

private ModelAndView createMockModelAndView(long moduleId) {
    ModelAndView modelAndView = new ModelAndView("formList");
    ModelMap modelMap = modelAndView.getModelMap();
    modelMap.addAttribute("moduleId", moduleId);
    modelMap.addAttribute("moduleForms", createMockQuestionForms());
    return modelAndView;
}

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

@RequestMapping(method = RequestMethod.POST)
public ModelAndView importForm(@RequestParam("file") MultipartFile file,
        @RequestParam("moduleId") long moduleId, HttpServletRequest request, HttpServletResponse response) {
    try {//  www. jav a2  s.c om
        if (file != null) {
            Map<String, String> existingForms = new HashMap<String, String>();
            List<String> existingQuestions = new ArrayList<String>();
            InputStream is = file.getInputStream();
            JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model");
            Unmarshaller m = jc.createUnmarshaller();
            Cure cure = (Cure) m.unmarshal(is);
            dataImporter.importData(cure, moduleId, existingForms, existingQuestions);
            if (existingForms.size() > 0 || existingQuestions.size() > 0) {
                ModelAndView mav = new ModelAndView("formUploadStatus"); // initialize with view name
                ModelMap model = mav.getModelMap();
                model.addAttribute("existingForms", existingForms);
                model.addAttribute("existingQuestions", existingQuestions);
                return mav;
                /* there had been errors */
                //               return new ModelAndView("formUploadStatus", "existingForms", existingForms);
            }
        }
        return new ModelAndView("formUploadStatus", "status", "OK");

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return new ModelAndView("formUploadStatus", "status", "FAIL");
    }
}

From source file:com.ufukuzun.myth.dialect.bean.Myth.java

public <T> AjaxResponse response(AjaxRequest<T> form, ModelAndView modelAndView, HttpServletResponse response,
        HttpServletRequest request) {//from w  w w .j  a  v  a2 s .  c  o  m
    return response(form, modelAndView.getViewName(), modelAndView.getModelMap(), response, request);
}

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

@RequestMapping(method = RequestMethod.POST)
public ModelAndView importModule(@RequestParam("file") MultipartFile file, HttpServletRequest request,
        HttpServletResponse response) {/*from w  w w  . ja va2  s.c  o m*/
    try {
        if (file != null) {
            Map<String, String> existingForms = new HashMap<String, String>();
            Map<String, String> existingModules = new HashMap<String, String>();
            List<String> existingQuestions = new ArrayList<String>();

            InputStream is = file.getInputStream();
            JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model");
            Unmarshaller m = jc.createUnmarshaller();
            Cure cure = (Cure) m.unmarshal(is);
            dataImporter.importModule(cure, existingModules, existingForms, existingQuestions);
            if (existingModules.size() > 0 || existingForms.size() > 0 || existingQuestions.size() > 0) {
                ModelAndView mav = new ModelAndView("formUploadStatus"); // initialize with view name
                ModelMap model = mav.getModelMap();
                model.addAttribute("existingModules", existingModules);
                model.addAttribute("existingForms", existingForms);
                model.addAttribute("existingQuestions", existingQuestions);
                return mav;
                /* there had been errors */
                //               return new ModelAndView("formUploadStatus", "existingForms", existingForms);
            }
        }
        return new ModelAndView("formUploadStatus", "status", "OK");

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return new ModelAndView("formUploadStatus", "status", "FAIL");
    }

}

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

@Test
public void shouldHaveTheDocumentInTheModel() throws Exception {
    //Given//from   w w w .j av a  2s. c  o  m
    Document expectedDocument = new Document();
    expectedDocument.setId(documentId);
    when(documentDAO.getById(Document.class, 1L)).thenReturn(expectedDocument);
    //When
    ModelAndView modelAndView = documentController.handleRequestInternal(request, response);
    //Then
    assertThat("The document is not present on the model",
            (Document) modelAndView.getModelMap().get("document"), is(expectedDocument));
}

From source file:cherry.admin.secure.pwdtool.PwdtoolControllerTest.java

@Test
public void init000() {
    ModelAndView mav = pwdtoolController.init(null, null, null, null);
    assertNotNull(mav);//from  ww w  . j  a  va 2  s.c o  m
    assertEquals(PathDef.VIEW_PWDTOOL_INIT, mav.getViewName());
    assertNull(mav.getView());
    assertTrue(mav.getModelMap().isEmpty());
}

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

private ModelAndView createMockModelAndView(long id) {
    ModelAndView mav = new ModelAndView("questionList");
    ModelMap model = mav.getModelMap();
    model.addAttribute("form", createMockQuestionForm(id, 1));
    return mav;/*from   ww  w  . j  a v  a 2  s .c o  m*/
}

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

@SuppressWarnings("unchecked")
@Test//from   ww  w.j  a va2  s.  co  m
public void testShowForms() {
    List<UserCredentials> users = new ArrayList<UserCredentials>();
    users.add(createMockUserCredentials(1l));
    users.add(createMockUserCredentials(2l));
    EasyMock.expect(userManager.getAllUsers()).andReturn(users);
    EasyMock.replay(userManager);
    ModelAndView expected = createMockModelAndView(1l);
    ModelAndView actual = userListController.showUserList();
    Assert.assertNotNull(actual);
    Assert.assertEquals((((List<UserCredentials>) expected.getModelMap().get("users")).size()),
            ((List<UserCredentials>) expected.getModelMap().get("users")).size());
}