Search in sources :

Example 31 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class PathResourceResolverTests method relativePathEncodedForUrlResource.

@Test
public void relativePathEncodedForUrlResource() throws Exception {
    TestUrlResource location = new TestUrlResource("file:///tmp");
    List<TestUrlResource> locations = Collections.singletonList(location);
    // ISO-8859-1
    this.resolver.setUrlPathHelper(new UrlPathHelper());
    this.resolver.setLocationCharsets(Collections.singletonMap(location, StandardCharsets.ISO_8859_1));
    this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null);
    assertThat(location.getSavedRelativePath()).isEqualTo("%C4%20%3B%E4.txt");
    // UTF-8
    this.resolver.setLocationCharsets(Collections.singletonMap(location, StandardCharsets.UTF_8));
    this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null);
    assertThat(location.getSavedRelativePath()).isEqualTo("%C3%84%20%3B%C3%A4.txt");
    // UTF-8 by default
    this.resolver.setLocationCharsets(Collections.emptyMap());
    this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null);
    assertThat(location.getSavedRelativePath()).isEqualTo("%C3%84%20%3B%C3%A4.txt");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Test(org.junit.jupiter.api.Test)

Example 32 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-security by spring-projects.

the class AntPathRequestMatcherTests method matchesWhenUrlPathHelperThenMatchesOnRequestUri.

@Test
public void matchesWhenUrlPathHelperThenMatchesOnRequestUri() {
    AntPathRequestMatcher matcher = new AntPathRequestMatcher("/foo/bar", null, true, new UrlPathHelper());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/bar");
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Test(org.junit.jupiter.api.Test)

Aggregations

UrlPathHelper (org.springframework.web.util.UrlPathHelper)32 Test (org.junit.jupiter.api.Test)10 PathMatcher (org.springframework.util.PathMatcher)5 Map (java.util.Map)4 Test (org.junit.Test)4 MultiValueMap (org.springframework.util.MultiValueMap)4 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)4 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)3 PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)3 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)3 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)3 Collections (java.util.Collections)2 List (java.util.List)2 BiConsumer (java.util.function.BiConsumer)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 BDDMockito.given (org.mockito.BDDMockito.given)2