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

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

Introduction

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

Prototype

public Map<String, Object> getModel() 

Source Link

Document

Return the model map.

Usage

From source file:fm.last.citrine.web.DisplayTaskRunMessageControllerTest.java

@Test
public void testDisplaySysErrContaingHtml() throws Exception {
    String sysErr = "<b>sys err</b>";
    taskRun.setSysErr(sysErr);/*from   www  . j  av  a  2s . c  o  m*/
    mockRequest.addParameter(Constants.PARAM_TASK_RUN_ID, String.valueOf(taskRun.getId()));
    ModelAndView modelAndView = displayTaskRunMessageController.displaySysErr(mockRequest, mockResponse);
    Map<String, Object> model = modelAndView.getModel();
    String escapedSysErr = HtmlUtils.htmlEscape(sysErr);
    assertEquals(escapedSysErr, model.get("message"));
}

From source file:gov.nih.nci.cabig.caaers.tools.spring.tabbedflow.SimpleFormAjaxableController.java

protected void respondAjaxFreeText(ModelAndView modelAndView, HttpServletResponse response) throws Exception {
    PrintWriter pr = response.getWriter();
    pr.println(modelAndView.getModel().get(getFreeTextModelName()));
    pr.flush();/*from w  w w.j  a  v a 2 s. c o m*/
    pr.close();
}

From source file:com.qcadoo.mes.genealogies.GenealogyControllerTest.java

@Test
public void shouldPrepareViewForComponentPdf() throws Exception {
    // given/* w w w . j av a  2s . com*/
    GenealogyController genealogyController = new GenealogyController();

    // when
    ModelAndView mav = genealogyController.genealogyForComponentPdf("v13");

    // then
    assertEquals("genealogyForComponentView", mav.getViewName());
    assertEquals("v13", mav.getModel().get("value"));
}

From source file:org.openmrs.web.controller.observation.ObsFormControllerTest.java

/**
 * Tests that an "encounterId" parameter sets the obs.encounter attribute on an empty obs
 * //  w  ww .ja v  a 2  s  .co m
 * @throws Exception
 */
@Test
public void shouldGetObsFormWithEncounterFilledIn() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    request.setParameter("encounterId", "3");

    HttpServletResponse response = new MockHttpServletResponse();

    ObsFormController controller = new ObsFormController();

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

    // make sure there is an "encounterId" element on the obs
    Obs commandObs = (Obs) modelAndView.getModel().get("command");
    Assert.assertNotNull(commandObs.getEncounter());

}

From source file:com.lc.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(ThirdPartyConstants.SeoRobots.META_ROBOTS)) {
        // Build a default directive
        String robotsValue = ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW;

        if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) {
            if (request.isSecure()) {
                robotsValue = ThirdPartyConstants.SeoRobots.NOINDEX_FOLLOW;
            }// w  w  w.  ja v a  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 = ThirdPartyConstants.SeoRobots.INDEX_FOLLOW;
            }
        } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) {
            robotsValue = ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW;
        }

        modelAndView.addObject(ThirdPartyConstants.SeoRobots.META_ROBOTS, robotsValue);
    }

    if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) {
        final MetaElementData metaElement = new MetaElementData();
        metaElement.setName("robots");
        metaElement.setContent((String) modelAndView.getModel().get(ThirdPartyConstants.SeoRobots.META_ROBOTS));
        ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement);
    }
}

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void getAllAddsContactsToModel() {
    Contact contact = new Contact();
    List<Contact> contacts = asList(contact);
    when(contactRepository.getAll()).thenReturn(contacts);

    List<Resource<Contact>> resources = asList(new Resource<>(contact));
    when(contactResourceAssembler.toResources(contacts)).thenReturn(resources);

    ModelAndView actual = controller.getAll();

    assertEquals(resources, actual.getModel().get("contacts"));
}

From source file:com.bsg.pcms.sale.company.CompanyContractControllerTest.java

@Test
public void testSaleContractList() {
    try {/*  w w w. ja  v  a  2  s . com*/
        ModelAndView resView = _saleCompanyController.list();
        List<CompanyContractDTOEx> resultcode = (List<CompanyContractDTOEx>) resView.getModel()
                .get("saleContractList");
        assertNotNull(resultcode);
        assertThat(resultcode.size(), is(not(0)));

        for (CompanyContractDTOEx cdtex : resultcode) {
            for (CompanyContentsDTOEx ccd : cdtex.getContentsList()) {
                assertNotNull(ccd);
                logger.info("{}", ccd);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("{}", e.getMessage());
    }
}

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

@Test
public void shouldNotAddDocumentIdToModelIfItIsPresentInRequestButItIsNotNumeric() throws Exception {
    // Given// ww  w .j a  v  a  2s. co  m
    String documentId = "123a";
    when(request.getParameter("documentId")).thenReturn(documentId);

    // When
    ModelAndView modelAndView = controller.handleRequest(request, response);

    // Then
    assertThat("The document id is wrong", modelAndView.getModel().get("documentId"), is(nullValue()));
}

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void deleteFormAddsContactToModel() {
    Contact contact = new Contact();
    when(contactRepository.get(1)).thenReturn(contact);

    Resource<Contact> resource = new Resource<>(contact);
    when(contactResourceAssembler.toResource(contact)).thenReturn(resource);

    ModelAndView actual = controller.deleteForm(1);

    assertEquals(resource, actual.getModel().get("contact"));
}

From source file:org.sventon.web.ctrl.template.GoToControllerTest.java

@Test
public void testSvnHandle() throws Exception {
    final RepositoryService mockService = EasyMock.createMock(RepositoryService.class);
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();

    final BaseCommand command = new BaseCommand();
    command.setName(new RepositoryName("test"));
    command.setPath("/file.txt");
    command.setRevision(Revision.create(12));

    final GoToController ctrl = new GoToController();

    final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory();
    configDirectory.setCreateDirectories(false);
    final MockServletContext servletContext = new MockServletContext();
    servletContext.setContextPath("sventon-test");
    configDirectory.setServletContext(servletContext);
    final Application application = new Application(configDirectory);

    application.setConfigured(true);/*from w ww. ja v  a2s . co m*/
    ctrl.setServletContext(new MockServletContext());
    ctrl.setApplication(application);
    ctrl.setRepositoryService(mockService);
    ctrl.setAvailableCharsets(new AvailableCharsets("UTF-8"));

    // Test NodeKind.FILE
    expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber()))
            .andStubReturn(DirEntry.Kind.FILE);
    replay(mockService);

    ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, null);
    Map model = modelAndView.getModel();
    verify(mockService);

    assertEquals(1, model.size());
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("/repos/test/show/file.txt", view.getUrl());

    reset(mockService);
    command.setPath("/dir");

    // Test NodeKind.DIR
    expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber()))
            .andStubReturn(DirEntry.Kind.DIR);
    replay(mockService);

    modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, null);
    model = modelAndView.getModel();
    verify(mockService);

    assertEquals(1, model.size());
    view = (RedirectView) modelAndView.getView();
    assertEquals("/repos/test/list/dir/", view.getUrl());

    reset(mockService);

    // Test NodeKind.UNKNOWN
    expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber()))
            .andStubReturn(DirEntry.Kind.UNKNOWN);
    replay(mockService);

    final BindException errors = new BindException(command, "test");
    assertEquals(0, errors.getAllErrors().size());

    modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, errors);
    model = modelAndView.getModel();
    verify(mockService);

    assertEquals(10, model.size());
    assertEquals("goto", modelAndView.getViewName());
}