Example usage for org.springframework.web.servlet.view RedirectView getUrl

List of usage examples for org.springframework.web.servlet.view RedirectView getUrl

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view RedirectView getUrl.

Prototype

@Nullable
public String getUrl() 

Source Link

Document

Return the URL of the resource that this view wraps.

Usage

From source file:org.unidle.controller.RedirectingConnectControllerTest.java

@Test
public void testConnectionStatusRedirect() throws Exception {
    final RedirectView result = subject.connectionStatusRedirect("provider id", null);

    assertThat(result.getUrl()).isEqualTo("/questions");
}

From source file:de.drv.dsrv.utility.spring.web.EnhancedRedirectInternalResourceViewResolver.java

protected View checkAndEnhanceRedirectView(final View view) {
    // Prfe, ob die ber die Basisklasse ermittelte View einen Redirect
    // reprsentiert
    if (view instanceof RedirectView) {
        // Fhre Typumwandlung durch und ermittle gespeicherte URL
        final RedirectView redirectView = (RedirectView) view;
        final String url = redirectView.getUrl();

        // Prfe, ob die gespeicherte URL den Prfix fr eine Pfadangabe
        // relativ zur Basis-URI des Servers ist
        if (url != null && url.startsWith(SERVER_REL_PREFIX)) {
            // Entferne Prfix
            redirectView.setUrl(url.substring(SERVER_REL_PREFIX.length()));

            // URL ist nicht reletiv zur Context Root
            redirectView.setContextRelative(false);
        }/*from  w  ww . java 2 s.  c  om*/
    }

    // Gebe View zurck
    return view;
}

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

@Test
public void testOK() throws Exception {
    // must be an OAuth 1.0 provider
    final TwitterProvider twitterProvider = new TwitterProvider();
    twitterProvider.setKey("OPEWaSoTuAe49K4dSoRvNw");
    twitterProvider.setSecret("aKmvleltXAmLKcnlMgzRjTsCnhV3QVMVDh153xJttCo");
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", MY_LOGIN_URL);
    mockRequest.setParameter(OAuthConstants.OAUTH_PROVIDER, twitterProvider.getType());
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuthConfiguration oAuthConfiguration = new OAuthConfiguration();
    oAuthConfiguration.setLoginUrl(MY_LOGIN_URL);
    final List<OAuthProvider> providers = new ArrayList<OAuthProvider>();
    providers.add(twitterProvider);//w w w .ja  va  2 s  .  c  o m
    oAuthConfiguration.setProviders(providers);
    // use OAuthAction to init oAuthConfiguration (as it's done in its class)
    final OAuthAction oAuthAction = new OAuthAction();
    oAuthAction.setConfiguration(oAuthConfiguration);
    final OAuth10LoginController oAuth10LoginController = new OAuth10LoginController();
    oAuth10LoginController.setConfiguration(oAuthConfiguration);
    final ModelAndView modelAndView = oAuth10LoginController.handleRequest(mockRequest, mockResponse);
    final View view = modelAndView.getView();
    assertTrue(view instanceof RedirectView);
    final RedirectView redirectView = (RedirectView) view;
    assertTrue(redirectView.getUrl().startsWith("https://api.twitter.com/oauth/authorize?oauth_token="));
}

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

@Test
public void testPrepareForShutdown() throws Exception {
    ModelAndView modelAndView = adminController.prepareForShutdown(mockRequest, mockResponse);
    verify(mockSchedulerManager).prepareForShutdown();
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("admin.do", view.getUrl());
    Map<String, Object> model = modelAndView.getModel();
    assertEquals(0, model.size());/*from  w w  w  .  j  a  va  2s  .c  om*/
}

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

@Test
public void testDelete() {
    Task task = new Task();
    task.setId(345);/*from w ww. j av  a  2 s . c o  m*/
    TaskDTO dto = new TaskDTO(task);
    when(mockTaskManager.get(task.getId())).thenReturn(task);
    BindException bindException = new BindException(dto, "bla");
    mockRequest.addParameter(Constants.PARAM_DELETE, "true");
    ModelAndView modelAndView = taskFormController.onSubmit(mockRequest, mockResponse, dto, bindException);
    RedirectView view = (RedirectView) modelAndView.getView();
    assertEquals("tasks.do?selectedGroupName=" + Constants.GROUP_NAME_ALL, view.getUrl());
    verify(mockTaskManager).delete(task);
    assertTrue(modelAndView.getModel().isEmpty());
}

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

@Test
public void testProcessLogout() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    UserCredentials userCredentials = new UserCredentials();
    userCredentials.setUserName("Testing");
    userCredentials.setPassword("TestPassword");
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(Constants.CREDENTIALS, userCredentials);
    request.setSession(session);/*from   w w w . ja v  a 2  s  .  c  o m*/
    RedirectView actual = (RedirectView) logoutController.processLogout(request);
    RedirectView expected = new RedirectView(Constants.HOME_URI, true);
    Assert.assertNotNull(actual);
    Assert.assertNull(session.getAttribute(Constants.CREDENTIALS));
    Assert.assertEquals(expected.getUrl(), actual.getUrl());
}

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   ww w.ja  v a  2 s.  c om*/
    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());
}

From source file:org.socialsignin.springsocial.security.web.CustomCallbackUrlConnectController.java

@RequestMapping(value = "/{providerId}", method = RequestMethod.POST)
public RedirectView connect(@PathVariable String providerId, NativeWebRequest request) {

    RedirectView redirectView = super.connect(providerId, request);
    if (overridenConnectCallbackBasePathsByProviderId.containsKey(providerId)) {
        String redirectUrl = redirectView.getUrl();

        // Modify the redirect url to specify an alternate callback base path for the provider
        redirectUrl = redirectUrl.replaceAll(
                getEncodedProviderCallbackPath(providerId, DEFAULT_CONNECT_CALLBACK_BASE_PATH),
                getEncodedProviderCallbackPath(providerId,
                        overridenConnectCallbackBasePathsByProviderId.get(providerId)));
        redirectView.setUrl(redirectUrl);

        return redirectView;

    } else {/* w w w  . ja v  a2 s.  co m*/
        return redirectView;
    }
}

From source file:eu.jasha.demo.sbtfragments.CityControllerTest.java

@Test
public void should_delete_city() throws Exception {
    RedirectView view = controller.deleteCity(CITY_ID);

    assertThat(view.isRedirectView()).isTrue();
    assertThat(view.getUrl()).isEqualTo("/cities");

    verify(cityDao).remove(CITY_ID);/* www. j a va2  s .co m*/
}

From source file:eu.jasha.demo.sbtfragments.CityControllerTest.java

@Test
public void should_update_city() throws Exception {
    RedirectView view = controller.updateCity(CITY_ID, city);

    assertThat(view.isRedirectView()).isTrue();
    assertThat(view.getUrl()).isEqualTo("");

    verify(cityDao).update(city);/*w w  w .j a  v  a 2  s .c  om*/
}