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:com.hp.autonomy.frontend.find.core.web.ControllerUtilsTest.java

@Test
public void buildErrorModelAndView() {
    final ErrorModelAndViewInfo errorModelAndViewInfo = new ErrorModelAndViewInfo.Builder()
            .setRequest(new MockHttpServletRequest()).setMainMessageCode("some.code")
            .setSubMessageCode("some.code").setSubMessageArguments(new Object[] {})
            .setStatusCode(HttpStatus.SC_FAILED_DEPENDENCY).setContactSupport(true)
            .setButtonHref(URI.create("http://some-address")).build();
    final ModelAndView modelAndView = controllerUtils.buildErrorModelAndView(errorModelAndViewInfo);
    assertNotNull(modelAndView.getModel().get(ErrorAttributes.MAIN_MESSAGE.value()));
    assertNotNull(modelAndView.getModel().get(ErrorAttributes.CONTACT_SUPPORT.value()));
    assertNotNull(modelAndView.getModel().get(ErrorAttributes.BUTTON_HREF.value()));
}

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

@Test
public void testSvnHandle() throws Exception {
    final RepositoryService serviceMock = mock(RepositoryService.class);

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

    final ShowLocksController ctrl = new ShowLocksController();
    ctrl.setRepositoryService(serviceMock);

    final Map<String, DirEntryLock> result = new HashMap<String, DirEntryLock>();
    result.put("/", new DirEntryLock("id", "path", "owner", "comment", new Date(), new Date()));

    when(serviceMock.getLocks(null, command.getPath(), true)).thenReturn(result);

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

    assertEquals(1, model.size());//from   w  w  w  .j  av  a 2 s.c  om
    final Collection locks = (Collection) model.get("currentLocks");
    assertEquals(1, locks.size());
}

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

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

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

    final ShowRevisionInfoController ctrl = new ShowRevisionInfoController();
    ctrl.setRepositoryService(mockService);

    expect(mockService.getLogEntry(null, command.getName(), command.getRevisionNumber()))
            .andStubReturn(TestUtils.getLogEntryStub());
    replay(mockService);//from   www  .j a  v  a  2  s .  c o  m

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

    assertEquals(1, model.size());
    final LogEntry revision = (LogEntry) model.get("revisionInfo");
    assertEquals(123, revision.getRevision());
}

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

@Test
public void testSvnHandle() throws Exception {
    final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    fileTypeMap.afterPropertiesSet();//from  w  ww  . j  a  v a  2  s .c om

    final MultipleEntriesCommand command = new MultipleEntriesCommand();
    final ShowThumbnailsController ctrl = new ShowThumbnailsController(fileTypeMap);

    final String[] pathEntries = new String[] { "file1.gif@123", "file2.jpg@123", "file.abc@123" };

    command.setEntries(PathRevision.parse(pathEntries));

    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.CONTENT_DISPOSITION_INLINE);

    final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, req, null, null);

    final Map model = modelAndView.getModel();
    final List entries = (List) model.get("thumbnailentries");

    assertEquals(2, entries.size());

    final PathRevision entry0 = (PathRevision) entries.get(0);
    assertEquals("file1.gif", entry0.getPath());
    assertEquals(123, entry0.getRevision().getNumber());
}

From source file:com.gantzgulch.sharing.controller.UsersControllerTest.java

@Test
public void getUsers() {
    ModelAndView modelAndView = controller.doGet();

    assertThat(modelAndView, notNullValue());

    List<User> users = Cast.cast(modelAndView.getModel().get("users"));
    assertThat(users, notNullValue());/*  w w  w  .  j  a  va2 s.co  m*/
    assertThat(users, UserMatcher.containsUsername("admin"));
    assertThat(users, UserMatcher.containsId("0"));
    assertThat(users, not(UserMatcher.containsUsername("unknown")));
}

From source file:org.openmrs.web.controller.person.AddPersonControllerTest.java

/**
 * @see AddPersonController#formBackingObject(HttpServletRequest)
 * @verifies catch pass for a valid birthdate
 *//*from   w  ww  .  ja  va  2  s.com*/
@Test
public void formBackingObject_shouldCatchPassForAValidBirthdate() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    HttpServletResponse response = new MockHttpServletResponse();

    request.setParameter("addName", "Gayan Perera");
    request.setParameter("addBirthdate", "03/07/1990");
    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);
    assertTrue(mav.getModel().isEmpty());
}

From source file:org.mifos.ui.loan.controller.AppInfoControllerTest.java

@SuppressWarnings("PMD.SignatureDeclareThrowsException") // Exception is thrown by AppInfoController.handleRequest
public void testHandleRequestView() throws Exception {
    applicationInformationDto = new ApplicationInformationDto();
    String expectedSvnRevision = "123456";
    applicationInformationDto.setSvnRevision(expectedSvnRevision);
    String expectedBuildId = "fooId";
    applicationInformationDto.setBuildId(expectedBuildId);
    String expectedBuildTag = "bar-baz-tag-1";
    applicationInformationDto.setBuildTag(expectedBuildTag);
    AppInfoController controller = new AppInfoController();
    controller.setAppInfo(applicationInformationDto);
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setMethod("GET");
    mockRequest.setRequestURI("/appInfo.ftl");
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse);

    Assert.assertNotNull(modelAndView.getModel());
    Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model");
    Assert.assertNotNull(modelMap);//from   w w w  .j  a  v a 2 s. co m
    ApplicationInformationDto actualApplicationInformationDto = (ApplicationInformationDto) modelMap
            .get("appInfo");
    Assert.assertNotNull(actualApplicationInformationDto);
    Assert.assertEquals(actualApplicationInformationDto.getSvnRevision(), expectedSvnRevision);
    Assert.assertEquals(actualApplicationInformationDto.getBuildId(), expectedBuildId);
    Assert.assertEquals(actualApplicationInformationDto.getBuildTag(), expectedBuildTag);
}

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

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

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

    final LogEntry svnLogEntry = TestUtils.getLogEntryStub(command.getRevisionNumber());
    final GetLogMessageController ctrl = new GetLogMessageController();
    ctrl.setRepositoryService(mockService);

    expect(mockService.getLogEntry(null, command.getName(), command.getRevisionNumber()))
            .andStubReturn(svnLogEntry);
    replay(mockService);/*from   w  w w  . j  a  v a  2 s . co  m*/

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

    assertEquals(1, model.size());
    final LogMessageSearchItem logEntry = (LogMessageSearchItem) model.get("logEntry");
    assertEquals(logEntry.getMessage(), logEntry.getMessage());
    assertEquals(command.getRevisionNumber(), logEntry.getRevision());
}

From source file:com.benfante.minimark.controllers.HomeControllerTest.java

public void testWelcome() throws Exception {
    resetRequestAndResponse();//from  w  w w  .  ja  va 2 s. co  m
    req.setMethod("GET");
    req.setRequestURI("/home/welcome.html");
    req = new MockHttpServletRequest("GET", "/home/welcome.html");
    ModelAndView mv = methodHandler.handle(req, res, controller);
    assertEquals("welcome", mv.getViewName());
    assertNotNull(mv.getModel().get("assessments"));
}

From source file:com.exxonmobile.ace.hybris.storefront.servlets.btg.ContentPageVisitedBtgInterceptor.java

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final ModelAndView modelAndView) {
    if (modelAndView != null) {
        final AbstractPageModel page = (AbstractPageModel) modelAndView.getModel()
                .get(AbstractPageController.CMS_PAGE_MODEL);
        if (page != null && page.getPk() != null) {
            try {
                eventService.publishEvent(
                        new ContentPageVisitedBTGRuleDataEvent(page.getPk().getLongValueAsString()));
            } catch (final Exception e) {
                LOG.error("Could not publish event", e);
            }//from   w  w w  . j  a  va  2 s. c o  m
        }
    }
}