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

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

Introduction

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

Prototype

@Nullable
public String getViewName() 

Source Link

Document

Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.

Usage

From source file:com.cisco.ca.cstg.pdi.controllers.license.LicenseControllerTest.java

@Test
public void licenseUpload_nullCheck() throws Exception {
    MockMultipartFile file = new MockMultipartFile("data", null, "text/plain", "some xml".getBytes());
    ModelAndView mv = licenseController.licenseUpload(file);
    assertEquals("license/license", mv.getViewName());
    assertNotNull(mv.getModel());// ww  w  . j a v a  2  s  .  co m
    String expected = "No File Uploaded. Please select a file and upload.";
    assertEquals(expected, mv.getModel().get("errorMessage"));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}

From source file:se.vgregion.pubsub.admin.controller.AdminControllerTest.java

@Test
public void index() throws Exception {
    List<PushSubscriber> subscribers = Arrays.asList(mock(PushSubscriber.class), mock(PushSubscriber.class));
    List<PolledPublisher> publishers = Arrays.asList(mock(PolledPublisher.class), mock(PolledPublisher.class));
    when(adminService.getAllPushSubscribers()).thenReturn(subscribers);
    when(adminService.getAllPolledPublishers()).thenReturn(publishers);

    ModelAndView mav = controller.index();

    Assert.assertEquals("admin/index", mav.getViewName());
    Assert.assertEquals(subscribers, mav.getModel().get("pushSubscribers"));
    Assert.assertEquals(publishers, mav.getModel().get("polledPublishers"));
}

From source file:org.focusns.web.widget.interceptor.PluginWidgetInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    //// ww w .j a  v a  2s . c o  m
    if (modelAndView == null) {
        return;
    }
    //
    String viewName = modelAndView.getViewName();
    if (viewName != null && viewName.startsWith("plugin:")) {
        //
        viewName = viewName.substring("plugin:".length());
        Resource resource = resourceLoader.getResource("/WEB-INF/plugins");
        File[] pluginDirs = resource.getFile().listFiles();
        for (File pluginDir : pluginDirs) {
            File targetFile = new File(pluginDir, "/META-INF/widgets/" + viewName + ".jsp");
            if (targetFile.exists()) {
                viewName = pluginDir.getName() + "/META-INF/widgets/" + viewName;
            }
        }
        //
        modelAndView.setViewName(viewName);
    }
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE
            + "=" + STATE, map.get("callbackUrl"));
}

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  ww  .  j  av  a  2s.c  o m*/
    return response(form, modelAndView.getViewName(), modelAndView.getModelMap(), response, request);
}

From source file:org.slc.sli.dashboard.unit.controller.ErrorControllerTest.java

@Test
public void testHandleError() throws Exception {

    ModelMap model = new ModelMap();

    String errorType = "default";
    ModelAndView modelAndView = errorController.handleError(errorType, model, request, response);

    assertEquals(Constants.OVERALL_CONTAINER_PAGE, modelAndView.getViewName());
    String errorHeading = (String) modelAndView.getModel().get(Constants.ATTR_ERROR_HEADING);
    String errorContent = (String) modelAndView.getModel().get(Constants.ATTR_ERROR_CONTENT);
    String errorPage = (String) modelAndView.getModel().get(Constants.PAGE_TO_INCLUDE);
    assertEquals(errorPage, ErrorController.TEMPLATE_FILE);
    assertNotNull(errorHeading);//from w ww .j a  v  a2s .  co m
    assertEquals(ErrorDescriptor.DEFAULT.getHeading(), errorHeading);
    assertNotNull(errorContent);
    assertEquals(ErrorDescriptor.DEFAULT.getContent(), errorContent);

}

From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java

@Test
public void testHandleRequestInternalConfigured() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final SubmitConfigurationsController controller = new SubmitConfigurationsController();
    application.setConfigured(true);/*from  w  w w  .  ja va 2  s .c  om*/
    controller.setApplication(application);
    final ModelAndView modelAndView = controller.handleRequestInternal(request, response);
    assertEquals("error/configurationError", modelAndView.getViewName());
}

From source file:com.thoughtworks.go.server.web.ZipArtifactFolderViewFactoryTest.java

@Test
public void shouldViewCachedZipArtifactIfAlreadyCreated() throws Exception {
    folderViewFactory = new ZipArtifactFolderViewFactory(cacheAlreadyCreated());

    ModelAndView modelAndView = folderViewFactory.createView(JOB_IDENTIFIER,
            new ArtifactFolder(JOB_IDENTIFIER, folder, "dir"));
    assertThat(modelAndView.getViewName(), is("fileView"));
    File targetFile = (File) modelAndView.getModel().get("targetFile");
    assertThat(targetFile, is(cacheZipFile));
}

From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java

@Test
public void testHandleRequestInternalNoAddedRepository() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final SubmitConfigurationsController controller = new SubmitConfigurationsController();
    application.setConfigured(false);/*from   w  w w  . java 2 s.c o m*/
    controller.setApplication(application);

    final ModelAndView modelAndView = controller.handleRequestInternal(request, response);
    assertEquals("error/configurationError", modelAndView.getViewName());
}