Fix BasePathAwareHandlerMappingUnitTests.

Fixes GH-2338.
This commit is contained in:
Oliver Drotbohm
2023-12-13 17:38:59 +01:00
parent ec0e25e0ca
commit 630d610936

View File

@@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.util.ReflectionUtils;
@@ -45,7 +46,7 @@ class BasePathAwareHandlerMappingUnitTests {
doReturn(URI.create("")).when(configuration).getBasePath();
mapping = new HandlerMappingStub(configuration);
mapping = getHandlerMappingStub(configuration);
}
@Test // DATAREST-1132
@@ -85,7 +86,7 @@ class BasePathAwareHandlerMappingUnitTests {
void combinesBasePathAndControllerPrefixesCorrectly() throws Exception {
doReturn(URI.create("/base")).when(configuration).getBasePath();
mapping = new HandlerMappingStub(configuration);
mapping = getHandlerMappingStub(configuration);
var method = ReflectionUtils.findMethod(PrefixedController.class, "someMethod");
var info = mapping.getMappingForMethod(method, PrefixedController.class);
@@ -105,6 +106,15 @@ class BasePathAwareHandlerMappingUnitTests {
return proxy.getClass();
}
private static HandlerMappingStub getHandlerMappingStub(RepositoryRestConfiguration configuration) {
HandlerMappingStub mapping = new HandlerMappingStub(configuration);
mapping.setApplicationContext(new StaticApplicationContext());
mapping.afterPropertiesSet();
return mapping;
}
@BasePathAwareController
static class SomeController {}