Polishing.
Added test case and re-enabled the base URI to be prepended even in case a controller path prefix is configured. That functionality had been lost with the originally submitted changes. Related ticket: #2157 Original pull request: #2088.
This commit is contained in:
@@ -26,6 +26,8 @@ import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
@@ -36,11 +38,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
class BasePathAwareHandlerMappingUnitTests {
|
||||
|
||||
HandlerMappingStub mapping;
|
||||
RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class);
|
||||
doReturn(URI.create("")).when(configuration).getBasePath();
|
||||
|
||||
mapping = new HandlerMappingStub(configuration);
|
||||
@@ -79,6 +81,20 @@ class BasePathAwareHandlerMappingUnitTests {
|
||||
.isThrownBy(() -> mapping.isHandler(ValidController.class));
|
||||
}
|
||||
|
||||
@Test // #2087
|
||||
void combinesBasePathAndControllerPrefixesCorrectly() throws Exception {
|
||||
|
||||
doReturn(URI.create("/base")).when(configuration).getBasePath();
|
||||
mapping = new HandlerMappingStub(configuration);
|
||||
|
||||
var method = ReflectionUtils.findMethod(PrefixedController.class, "someMethod");
|
||||
var info = mapping.getMappingForMethod(method, PrefixedController.class);
|
||||
|
||||
var next = info.getPatternValues().iterator().next();
|
||||
|
||||
assertThat(next).isEqualTo("/base/controllerBase/method");
|
||||
}
|
||||
|
||||
private static Class<?> createProxy(Object source) {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(source);
|
||||
@@ -114,4 +130,11 @@ class BasePathAwareHandlerMappingUnitTests {
|
||||
@Controller
|
||||
@RequestMapping("/sample")
|
||||
static class ValidController {}
|
||||
|
||||
@BasePathAwareController("/controllerBase")
|
||||
static class PrefixedController {
|
||||
|
||||
@GetMapping("/method")
|
||||
void someMethod() {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user