DATAREST-1294 - Expose effective repository lookup path as request attribute.
We now expose a partially resolved PathPattern to contain the explicit repository base path so that the subpaths can be grouped around the individual repositories exposed. Related ticket: spring-projects/spring-boot#14872
This commit is contained in:
@@ -43,6 +43,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RepositoryRestHandlerMapping}.
|
||||
@@ -270,6 +271,22 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
assertThat(mapping.isHandler(type)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-1294
|
||||
public void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/people/search/findByLastnameLike");
|
||||
|
||||
handlerMapping.afterPropertiesSet();
|
||||
handlerMapping.lookupHandlerMethod("/people/search/findByLastnameLike", mockRequest);
|
||||
|
||||
assertThat(mockRequest.getAttribute(RepositoryRestHandlerMapping.EFFECTIVE_LOOKUP_PATH_KEY)) //
|
||||
.isInstanceOfSatisfying(PathPattern.class, it -> {
|
||||
assertThat(it.getPatternString()).isEqualTo("/people/search/{search}");
|
||||
});
|
||||
}
|
||||
|
||||
private static Class<?> createProxy(Object source) {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(source);
|
||||
|
||||
Reference in New Issue
Block a user