From 07986acc54b2b799c3de612a26b124ceec644cd3 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Fri, 29 May 2015 15:17:49 -0500 Subject: [PATCH] =?UTF-8?q?DATAREST-553=20-=20Removed=20RepositoryRestConf?= =?UTF-8?q?iguration.setBaseUri(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../config/RepositoryRestConfiguration.java | 36 ++----------------- spring-data-rest-webmvc/pom.xml | 7 ++++ .../AugmentingHandlerMappingUnitTests.java | 4 +-- ...RepositoryRestHandlerMappingUnitTests.java | 13 +++---- 4 files changed, 16 insertions(+), 44 deletions(-) diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java index a27871ae3..27e8e5bf4 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java @@ -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)); diff --git a/spring-data-rest-webmvc/pom.xml b/spring-data-rest-webmvc/pom.xml index 43c3104e2..9a85a6d64 100644 --- a/spring-data-rest-webmvc/pom.xml +++ b/spring-data-rest-webmvc/pom.xml @@ -266,6 +266,13 @@ + + + commons-io + commons-io + 2.3 + test + diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java index e5b868b11..7527c9c10 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java @@ -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)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java index fc26646d7..dff1906ff 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java @@ -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);