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:
Oliver Gierke
2018-10-18 12:00:50 +02:00
parent 74be650a0c
commit ffb38a067e
2 changed files with 50 additions and 1 deletions

View File

@@ -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);