Add static factory/accessor methods to LookupPath

Issue: SPR-15397
This commit is contained in:
Rossen Stoyanchev
2017-06-02 15:15:42 -04:00
parent a7020e419a
commit d2685dfe67
12 changed files with 64 additions and 70 deletions

View File

@@ -222,8 +222,7 @@ public class PatternsRequestConditionTests {
private MockServerWebExchange initExchange(String path) {
MockServerWebExchange exchange = get(path).toExchange();
exchange.getAttributes().put(LookupPath.LOOKUP_PATH_ATTRIBUTE,
new HttpRequestPathHelper().getLookupPathForRequest(exchange));
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
return exchange;
}

View File

@@ -29,9 +29,9 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.reactive.result.method.RequestMappingInfo;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.support.HttpRequestPathHelper;
import org.springframework.web.server.support.LookupPath;
import org.springframework.web.server.ServerWebExchange;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
@@ -48,7 +48,7 @@ import static org.springframework.web.reactive.result.method.RequestMappingInfo.
*/
public class RequestMappingInfoTests {
// TODO: CORS pre-flight (see @Ignored)
// TODO: CORS pre-flight (see @Ignore)
@Test
@@ -67,7 +67,7 @@ public class RequestMappingInfoTests {
@Test
public void matchPatternsCondition() {
MockServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo*", "/bar").build();
RequestMappingInfo expected = paths("/foo*").build();
@@ -83,7 +83,7 @@ public class RequestMappingInfoTests {
@Test
public void matchParamsCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
@@ -99,7 +99,7 @@ public class RequestMappingInfoTests {
@Test
public void matchHeadersCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").header("foo", "bar").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo").headers("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
@@ -115,7 +115,7 @@ public class RequestMappingInfoTests {
@Test
public void matchConsumesCondition() {
ServerWebExchange exchange = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo").consumes("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
@@ -131,7 +131,7 @@ public class RequestMappingInfoTests {
@Test
public void matchProducesCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo").produces("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
@@ -147,7 +147,7 @@ public class RequestMappingInfoTests {
@Test
public void matchCustomCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
@@ -169,7 +169,7 @@ public class RequestMappingInfoTests {
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
@@ -279,9 +279,4 @@ public class RequestMappingInfoTests {
assertNull("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD", match);
}
private void initLookupPath(ServerWebExchange exchange) {
exchange.getAttributes().put(LookupPath.LOOKUP_PATH_ATTRIBUTE,
new HttpRequestPathHelper().getLookupPathForRequest(exchange));
}
}

View File

@@ -219,17 +219,17 @@ public class ViewResolutionResultHandlerTests {
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
MockServerWebExchange exchange = get("/account").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
exchange = get("/account/").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
exchange = get("/account.123").toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
}
@@ -256,7 +256,7 @@ public class ViewResolutionResultHandlerTests {
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
@@ -307,11 +307,6 @@ public class ViewResolutionResultHandlerTests {
assertEquals("/", response.getHeaders().getLocation().toString());
}
private void initLookupPath(ServerWebExchange exchange) {
exchange.getAttributes().put(LookupPath.LOOKUP_PATH_ATTRIBUTE,
new HttpRequestPathHelper().getLookupPathForRequest(exchange));
}
private ViewResolutionResultHandler resultHandler(ViewResolver... resolvers) {
return resultHandler(Collections.emptyList(), resolvers);
@@ -333,7 +328,7 @@ public class ViewResolutionResultHandlerTests {
model.addAttribute("id", "123");
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
MockServerWebExchange exchange = get(path).toExchange();
initLookupPath(exchange);
LookupPath.getOrCreate(exchange, new HttpRequestPathHelper());
resultHandler(resolvers).handleResult(exchange, result).block(Duration.ofSeconds(5));
assertResponseBody(exchange, responseBody);
return exchange;