Skip to content

Commit ea0c5ef

Browse files
committed
Adds a test
Signed-off-by: Jens Mallien <[email protected]>
1 parent e27e320 commit ea0c5ef

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2013-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.gateway.server.mvc.filter;
18+
19+
import java.util.Collections;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.mock.web.MockHttpServletRequest;
24+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
25+
import org.springframework.web.servlet.function.ServerRequest;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* @author Jens Mallien
31+
*/
32+
public class BeforeFilterFunctionsTests {
33+
34+
@Test
35+
public void rewritePath() {
36+
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/get")
37+
.buildRequest(null);
38+
39+
ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());
40+
41+
ServerRequest modified = BeforeFilterFunctions.rewritePath("get", "modified").apply(request);
42+
43+
assertThat(modified.uri().getRawPath()).isEqualTo("/modified");
44+
}
45+
46+
@Test
47+
public void rewritePathWithSpace() {
48+
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/get/path/with spaces")
49+
.buildRequest(null);
50+
51+
ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());
52+
53+
ServerRequest modified = BeforeFilterFunctions.rewritePath("get", "modified").apply(request);
54+
55+
assertThat(modified.uri().getRawPath()).isEqualTo("/modified/path/with%20spaces");
56+
}
57+
58+
}

0 commit comments

Comments
 (0)