From 6be072ae0715932fa444db18a2564932e2f400be Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 1 Oct 2015 14:44:23 -0700 Subject: [PATCH] Polish --- .../data/rest/RepositoryRestProperties.java | 76 +++++------ ...positoryRestMvcAutoConfigurationTests.java | 18 ++- .../boot/SpringApplication.java | 122 +++++++++--------- .../boot/SpringApplicationTests.java | 85 ++++++------ 4 files changed, 149 insertions(+), 152 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java index 1a7c378a13..2005f90773 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestProperties.java @@ -50,12 +50,14 @@ public class RepositoryRestProperties { private String pageParamName; /** - * Name of the URL query string parameter that indicates how many results to return at once. + * Name of the URL query string parameter that indicates how many results to return at + * once. */ private String limitParamName; /** - * Name of the URL query string parameter that indicates what direction to sort results. + * Name of the URL query string parameter that indicates what direction to sort + * results. */ private String sortParamName; @@ -75,44 +77,11 @@ public class RepositoryRestProperties { private Boolean returnBodyOnUpdate; /** - * Enable enum value translation via the Spring Data REST default resource bundle. Will use - * the fully qualified enum name as key. + * Enable enum value translation via the Spring Data REST default resource bundle. + * Will use the fully qualified enum name as key. */ private Boolean enableEnumTranslation; - public void applyTo(RepositoryRestConfiguration configuration) { - if (this.basePath != null) { - configuration.setBasePath(this.basePath); - } - if (this.defaultPageSize != null) { - configuration.setDefaultPageSize(this.defaultPageSize); - } - if (this.maxPageSize != null) { - configuration.setMaxPageSize(this.maxPageSize); - } - if (this.pageParamName != null) { - configuration.setPageParamName(this.pageParamName); - } - if (this.limitParamName != null) { - configuration.setLimitParamName(this.limitParamName); - } - if (this.sortParamName != null) { - configuration.setSortParamName(this.sortParamName); - } - if (this.defaultMediaType != null) { - configuration.setDefaultMediaType(this.defaultMediaType); - } - if (this.returnBodyOnCreate != null) { - configuration.setReturnBodyOnCreate(this.returnBodyOnCreate); - } - if (this.returnBodyOnUpdate != null) { - configuration.setReturnBodyOnUpdate(this.returnBodyOnUpdate); - } - if (this.enableEnumTranslation != null) { - configuration.setEnableEnumTranslation(this.enableEnumTranslation); - } - } - public String getBasePath() { return this.basePath; } @@ -193,4 +162,37 @@ public class RepositoryRestProperties { this.enableEnumTranslation = enableEnumTranslation; } + public void applyTo(RepositoryRestConfiguration configuration) { + if (this.basePath != null) { + configuration.setBasePath(this.basePath); + } + if (this.defaultPageSize != null) { + configuration.setDefaultPageSize(this.defaultPageSize); + } + if (this.maxPageSize != null) { + configuration.setMaxPageSize(this.maxPageSize); + } + if (this.pageParamName != null) { + configuration.setPageParamName(this.pageParamName); + } + if (this.limitParamName != null) { + configuration.setLimitParamName(this.limitParamName); + } + if (this.sortParamName != null) { + configuration.setSortParamName(this.sortParamName); + } + if (this.defaultMediaType != null) { + configuration.setDefaultMediaType(this.defaultMediaType); + } + if (this.returnBodyOnCreate != null) { + configuration.setReturnBodyOnCreate(this.returnBodyOnCreate); + } + if (this.returnBodyOnUpdate != null) { + configuration.setReturnBodyOnUpdate(this.returnBodyOnUpdate); + } + if (this.enableEnumTranslation != null) { + configuration.setEnableEnumTranslation(this.enableEnumTranslation); + } + } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java index a0488ff3dd..2bf00dd095 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java @@ -90,8 +90,7 @@ public class RepositoryRestMvcAutoConfigurationTests { @Test public void testWithCustomSettings() throws Exception { - load(TestConfiguration.class, - "spring.data.rest.default-page-size:42", + load(TestConfiguration.class, "spring.data.rest.default-page-size:42", "spring.data.rest.max-page-size:78", "spring.data.rest.page-param-name:_page", "spring.data.rest.limit-param-name:_limit", @@ -106,13 +105,18 @@ public class RepositoryRestMvcAutoConfigurationTests { assertEquals("Custom default page size not set", 42, bean.getDefaultPageSize()); assertEquals("Custom max page size not set", 78, bean.getMaxPageSize()); assertEquals("Custom page param name not set", "_page", bean.getPageParamName()); - assertEquals("Custom limit param name not set", "_limit", bean.getLimitParamName()); + assertEquals("Custom limit param name not set", "_limit", + bean.getLimitParamName()); assertEquals("Custom sort param name not set", "_sort", bean.getSortParamName()); assertEquals("Custom default media type not set", - MediaType.parseMediaType("application/my-json"), bean.getDefaultMediaType()); - assertEquals("Custom return body on create flag not set", false, bean.returnBodyOnCreate(null)); - assertEquals("Custom return body on update flag not set", false, bean.returnBodyOnUpdate(null)); - assertEquals("Custom enable enum translation flag not set", true, bean.isEnableEnumTranslation()); + MediaType.parseMediaType("application/my-json"), + bean.getDefaultMediaType()); + assertEquals("Custom return body on create flag not set", false, + bean.returnBodyOnCreate(null)); + assertEquals("Custom return body on update flag not set", false, + bean.returnBodyOnUpdate(null)); + assertEquals("Custom enable enum translation flag not set", true, + bean.isEnableEnumTranslation()); } @Test diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 3d96535f6d..a7120b0ca9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -120,8 +120,7 @@ import org.springframework.web.context.support.StandardServletEnvironment; * your application, however, any of the following sources can also be used: * *