DATAREST-553 - Removed RepositoryRestConfiguration.setBaseUri(…).
Updated existing unit tests to use setBasePath. Added extra assertion to setBasePath to guard against sending in a URI with a protocol. Original pull request: #178.
This commit is contained in:
committed by
Oliver Gierke
parent
018fa22593
commit
07986acc54
@@ -33,6 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
* @author Jeremy Rickard
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RepositoryRestConfiguration {
|
||||
@@ -98,40 +99,6 @@ public class RepositoryRestConfiguration {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base URI against which the exporter should calculate its links.
|
||||
*
|
||||
* @param baseUri must not be {@literal null}.
|
||||
* @deprecated use {@link #setBasePath(String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public RepositoryRestConfiguration setBaseUri(URI baseUri) {
|
||||
|
||||
Assert.notNull(baseUri, "The base URI cannot be null.");
|
||||
|
||||
LOGGER.warn("Configuring a base URI has been deprecated. Use basePath property instead!");
|
||||
|
||||
if (baseUri.isAbsolute()) {
|
||||
LOGGER
|
||||
.warn("Using absolute base URIs will not be supported as of Spring Data REST 2.3! Be sure to switch to configuring a base path!");
|
||||
}
|
||||
|
||||
this.baseUri = baseUri;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base URI against which the exporter should calculate its links.
|
||||
*
|
||||
* @param baseUri must not be {@literal null}.
|
||||
* @deprecated use {@link #setBasePath(String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public RepositoryRestConfiguration setBaseUri(String baseUri) {
|
||||
Assert.notNull(baseUri, "The base URI cannot be null.");
|
||||
return setBaseUri(URI.create(baseUri));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the base path to be used by Spring Data REST to expose repository resources.
|
||||
*
|
||||
@@ -139,6 +106,7 @@ public class RepositoryRestConfiguration {
|
||||
*/
|
||||
public void setBasePath(String basePath) {
|
||||
|
||||
Assert.isTrue(!basePath.startsWith("http"), "Use a path not a URI");
|
||||
basePath = StringUtils.trimTrailingCharacter(basePath, '/');
|
||||
this.basePath = URI.create(basePath.startsWith("/") ? basePath : "/".concat(basePath));
|
||||
|
||||
|
||||
@@ -266,6 +266,13 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</profile>
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
* Unit tests for {@link BasePathAwareHandlerMapping}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class AugmentingHandlerMappingUnitTests {
|
||||
|
||||
@@ -47,11 +48,10 @@ public class AugmentingHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void augmentsRequestMappingsWithBaseUriFromConfiguration() {
|
||||
|
||||
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration();
|
||||
configuration.setBaseUri("api");
|
||||
configuration.setBasePath("api");
|
||||
|
||||
BasePathAwareHandlerMapping mapping = new BasePathAwareHandlerMapping(configuration);
|
||||
mapping.setApplicationContext(new AnnotationConfigApplicationContext(Config.class));
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.web.method.HandlerMethod;
|
||||
* Unit tests for {@link RepositoryRestHandlerMapping}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryRestHandlerMappingUnitTests {
|
||||
@@ -150,13 +151,12 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
* @see DATAREST-276
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base/people/");
|
||||
|
||||
configuration.setBaseUri("http://localhost/base");
|
||||
configuration.setBasePath("/base");
|
||||
handlerMapping.afterPropertiesSet();
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base/people/", mockRequest);
|
||||
@@ -169,14 +169,13 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
* @see DATAREST-276
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
||||
mockRequest.setServletPath("/base/people");
|
||||
|
||||
configuration.setBaseUri("http://localhost/base");
|
||||
configuration.setBasePath("/base");
|
||||
handlerMapping.afterPropertiesSet();
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base/people", mockRequest);
|
||||
@@ -189,14 +188,13 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
* @see DATAREST-276
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/servlet-path");
|
||||
mockRequest.setServletPath("/servlet-path");
|
||||
|
||||
configuration.setBaseUri("http://localhost/base");
|
||||
configuration.setBasePath("/base");
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/servlet-path", mockRequest);
|
||||
|
||||
@@ -207,7 +205,6 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
* @see DATAREST-276
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void refrainsFromMappingWhenUrisDontMatch() throws Exception {
|
||||
|
||||
String baseUri = "foo";
|
||||
@@ -217,7 +214,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
mockRequest = new MockHttpServletRequest("GET", uri);
|
||||
mockRequest.setServletPath(uri);
|
||||
|
||||
configuration.setBaseUri(baseUri);
|
||||
configuration.setBasePath(baseUri);
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/people", mockRequest);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user