Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b9bb31cf
Commit
b9bb31cf
authored
Jan 09, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract RestDocsProperties
Extract properties used by RestDocs to their own class.
parent
d439b737
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
127 deletions
+121
-127
RestDocsAutoConfiguration.java
...est/autoconfigure/restdocs/RestDocsAutoConfiguration.java
+9
-9
RestDocsMockMvcBuilderCustomizer.java
...oconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java
+13
-41
RestDocsProperties.java
.../boot/test/autoconfigure/restdocs/RestDocsProperties.java
+71
-0
RestDocsRestAssuredBuilderCustomizer.java
...figure/restdocs/RestDocsRestAssuredBuilderCustomizer.java
+13
-37
RestDocsWebTestClientBuilderCustomizer.java
...gure/restdocs/RestDocsWebTestClientBuilderCustomizer.java
+15
-40
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java
View file @
b9bb31cf
...
@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
...
@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -47,13 +46,13 @@ import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
...
@@ -47,13 +46,13 @@ import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
* @since 1.4.0
* @since 1.4.0
*/
*/
@Configuration
@Configuration
@EnableConfigurationProperties
@ConditionalOnWebApplication
@ConditionalOnWebApplication
public
class
RestDocsAutoConfiguration
{
public
class
RestDocsAutoConfiguration
{
@Configuration
@Configuration
@ConditionalOnClass
(
MockMvcRestDocumentation
.
class
)
@ConditionalOnClass
(
MockMvcRestDocumentation
.
class
)
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
@EnableConfigurationProperties
(
RestDocsProperties
.
class
)
static
class
RestDocsMockMvcAutoConfiguration
{
static
class
RestDocsMockMvcAutoConfiguration
{
@Bean
@Bean
...
@@ -72,11 +71,11 @@ public class RestDocsAutoConfiguration {
...
@@ -72,11 +71,11 @@ public class RestDocsAutoConfiguration {
}
}
@Bean
@Bean
@ConfigurationProperties
(
prefix
=
"spring.test.restdocs"
)
public
RestDocsMockMvcBuilderCustomizer
restDocumentationConfigurer
(
public
RestDocsMockMvcBuilderCustomizer
restDocumentationConfigurer
(
RestDocsProperties
properties
,
MockMvcRestDocumentationConfigurer
configurer
,
MockMvcRestDocumentationConfigurer
configurer
,
ObjectProvider
<
RestDocumentationResultHandler
>
resultHandler
)
{
ObjectProvider
<
RestDocumentationResultHandler
>
resultHandler
)
{
return
new
RestDocsMockMvcBuilderCustomizer
(
configurer
,
return
new
RestDocsMockMvcBuilderCustomizer
(
properties
,
configurer
,
resultHandler
.
getIfAvailable
());
resultHandler
.
getIfAvailable
());
}
}
...
@@ -85,6 +84,7 @@ public class RestDocsAutoConfiguration {
...
@@ -85,6 +84,7 @@ public class RestDocsAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnClass
({
RequestSpecification
.
class
,
@ConditionalOnClass
({
RequestSpecification
.
class
,
RestAssuredRestDocumentation
.
class
})
RestAssuredRestDocumentation
.
class
})
@EnableConfigurationProperties
(
RestDocsProperties
.
class
)
static
class
RestDocsRestAssuredAutoConfiguration
{
static
class
RestDocsRestAssuredAutoConfiguration
{
@Bean
@Bean
...
@@ -103,10 +103,9 @@ public class RestDocsAutoConfiguration {
...
@@ -103,10 +103,9 @@ public class RestDocsAutoConfiguration {
}
}
@Bean
@Bean
@ConfigurationProperties
(
prefix
=
"spring.test.restdocs"
)
public
RestDocsRestAssuredBuilderCustomizer
restAssuredBuilderCustomizer
(
public
RestDocsRestAssuredBuilderCustomizer
restAssuredBuilderCustomizer
(
RequestSpecification
configurer
)
{
Re
stDocsProperties
properties
,
Re
questSpecification
configurer
)
{
return
new
RestDocsRestAssuredBuilderCustomizer
(
configurer
);
return
new
RestDocsRestAssuredBuilderCustomizer
(
properties
,
configurer
);
}
}
}
}
...
@@ -114,6 +113,7 @@ public class RestDocsAutoConfiguration {
...
@@ -114,6 +113,7 @@ public class RestDocsAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnClass
(
WebTestClientRestDocumentation
.
class
)
@ConditionalOnClass
(
WebTestClientRestDocumentation
.
class
)
@ConditionalOnWebApplication
(
type
=
Type
.
REACTIVE
)
@ConditionalOnWebApplication
(
type
=
Type
.
REACTIVE
)
@EnableConfigurationProperties
(
RestDocsProperties
.
class
)
static
class
RestDocsWebTestClientAutoConfiguration
{
static
class
RestDocsWebTestClientAutoConfiguration
{
@Bean
@Bean
...
@@ -132,10 +132,10 @@ public class RestDocsAutoConfiguration {
...
@@ -132,10 +132,10 @@ public class RestDocsAutoConfiguration {
}
}
@Bean
@Bean
@ConfigurationProperties
(
prefix
=
"spring.test.restdocs"
)
public
RestDocsWebTestClientBuilderCustomizer
restDocumentationConfigurer
(
public
RestDocsWebTestClientBuilderCustomizer
restDocumentationConfigurer
(
RestDocsProperties
properties
,
WebTestClientRestDocumentationConfigurer
configurer
)
{
WebTestClientRestDocumentationConfigurer
configurer
)
{
return
new
RestDocsWebTestClientBuilderCustomizer
(
configurer
);
return
new
RestDocsWebTestClientBuilderCustomizer
(
properties
,
configurer
);
}
}
}
}
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java
View file @
b9bb31cf
...
@@ -17,11 +17,12 @@
...
@@ -17,11 +17,12 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
restdocs
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
restdocs
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.boot.test.autoconfigure.web.servlet.MockMvcBuilderCustomizer
;
import
org.springframework.boot.test.autoconfigure.web.servlet.MockMvcBuilderCustomizer
;
import
org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer
;
import
org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer
;
import
org.springframework.restdocs.mockmvc.RestDocumentationResultHandler
;
import
org.springframework.restdocs.mockmvc.RestDocumentationResultHandler
;
import
org.springframework.restdocs.mockmvc.UriConfigurer
;
import
org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder
;
import
org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder
;
import
org.springframework.util.StringUtils
;
/**
/**
* A {@link MockMvcBuilderCustomizer} that configures Spring REST Docs.
* A {@link MockMvcBuilderCustomizer} that configures Spring REST Docs.
...
@@ -31,57 +32,28 @@ import org.springframework.util.StringUtils;
...
@@ -31,57 +32,28 @@ import org.springframework.util.StringUtils;
class
RestDocsMockMvcBuilderCustomizer
class
RestDocsMockMvcBuilderCustomizer
implements
InitializingBean
,
MockMvcBuilderCustomizer
{
implements
InitializingBean
,
MockMvcBuilderCustomizer
{
private
final
RestDocsProperties
properties
;
private
final
MockMvcRestDocumentationConfigurer
delegate
;
private
final
MockMvcRestDocumentationConfigurer
delegate
;
private
final
RestDocumentationResultHandler
resultHandler
;
private
final
RestDocumentationResultHandler
resultHandler
;
private
String
uriScheme
;
RestDocsMockMvcBuilderCustomizer
(
RestDocsProperties
properties
,
MockMvcRestDocumentationConfigurer
delegate
,
private
String
uriHost
;
private
Integer
uriPort
;
RestDocsMockMvcBuilderCustomizer
(
MockMvcRestDocumentationConfigurer
delegate
,
RestDocumentationResultHandler
resultHandler
)
{
RestDocumentationResultHandler
resultHandler
)
{
this
.
properties
=
properties
;
this
.
delegate
=
delegate
;
this
.
delegate
=
delegate
;
this
.
resultHandler
=
resultHandler
;
this
.
resultHandler
=
resultHandler
;
}
}
public
String
getUriScheme
()
{
return
this
.
uriScheme
;
}
public
void
setUriScheme
(
String
uriScheme
)
{
this
.
uriScheme
=
uriScheme
;
}
public
String
getUriHost
()
{
return
this
.
uriHost
;
}
public
void
setUriHost
(
String
uriHost
)
{
this
.
uriHost
=
uriHost
;
}
public
Integer
getUriPort
()
{
return
this
.
uriPort
;
}
public
void
setUriPort
(
Integer
uriPort
)
{
this
.
uriPort
=
uriPort
;
}
@Override
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
if
(
StringUtils
.
hasText
(
this
.
uriScheme
))
{
PropertyMapper
map
=
PropertyMapper
.
get
();
this
.
delegate
.
uris
().
withScheme
(
this
.
uriScheme
);
RestDocsProperties
properties
=
this
.
properties
;
}
UriConfigurer
uri
=
this
.
delegate
.
uris
();
if
(
StringUtils
.
hasText
(
this
.
uriHost
))
{
map
.
from
(
properties:
:
getUriScheme
).
whenHasText
().
to
(
uri:
:
withScheme
);
this
.
delegate
.
uris
().
withHost
(
this
.
uriHost
);
map
.
from
(
properties:
:
getUriHost
).
whenHasText
().
to
(
uri:
:
withHost
);
}
map
.
from
(
properties:
:
getUriPort
).
whenNonNull
().
to
(
uri:
:
withPort
);
if
(
this
.
uriPort
!=
null
)
{
this
.
delegate
.
uris
().
withPort
(
this
.
uriPort
);
}
}
}
@Override
@Override
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsProperties.java
0 → 100644
View file @
b9bb31cf
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
restdocs
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for Spring REST Docs.
*
* @author Andy Wilkinson
* @author Eddú Meléndez
* @author Phillip Webb
* @since 2.0.0
*/
@ConfigurationProperties
(
"spring.test.restdocs"
)
public
class
RestDocsProperties
{
/**
* The URI scheme for to use (for example http).
*/
private
String
uriScheme
;
/**
* The URI host to use.
*/
private
String
uriHost
;
/**
* The URI port to use.
*/
private
Integer
uriPort
;
public
String
getUriScheme
()
{
return
this
.
uriScheme
;
}
public
void
setUriScheme
(
String
uriScheme
)
{
this
.
uriScheme
=
uriScheme
;
}
public
String
getUriHost
()
{
return
this
.
uriHost
;
}
public
void
setUriHost
(
String
uriHost
)
{
this
.
uriHost
=
uriHost
;
}
public
Integer
getUriPort
()
{
return
this
.
uriPort
;
}
public
void
setUriPort
(
Integer
uriPort
)
{
this
.
uriPort
=
uriPort
;
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsRestAssuredBuilderCustomizer.java
View file @
b9bb31cf
...
@@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.restdocs;
...
@@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.restdocs;
import
io.restassured.specification.RequestSpecification
;
import
io.restassured.specification.RequestSpecification
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -28,50 +29,25 @@ import org.springframework.util.StringUtils;
...
@@ -28,50 +29,25 @@ import org.springframework.util.StringUtils;
*/
*/
class
RestDocsRestAssuredBuilderCustomizer
implements
InitializingBean
{
class
RestDocsRestAssuredBuilderCustomizer
implements
InitializingBean
{
private
final
RequestSpecification
delegate
;
private
final
RestDocsProperties
properties
;
private
String
uriScheme
;
private
String
uriHost
;
private
final
RequestSpecification
delegate
;
private
Integer
uriPort
;
RestDocsRestAssuredBuilderCustomizer
(
RequestSpecification
delegate
)
{
RestDocsRestAssuredBuilderCustomizer
(
RestDocsProperties
properties
,
RequestSpecification
delegate
)
{
this
.
properties
=
properties
;
this
.
delegate
=
delegate
;
this
.
delegate
=
delegate
;
}
}
public
String
getUriScheme
()
{
return
this
.
uriScheme
;
}
public
void
setUriScheme
(
String
uriScheme
)
{
this
.
uriScheme
=
uriScheme
;
}
public
String
getUriHost
()
{
return
this
.
uriHost
;
}
public
void
setUriHost
(
String
uriHost
)
{
this
.
uriHost
=
uriHost
;
}
public
Integer
getUriPort
()
{
return
this
.
uriPort
;
}
public
void
setUriPort
(
Integer
uriPort
)
{
this
.
uriPort
=
uriPort
;
}
@Override
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
if
(
StringUtils
.
hasText
(
this
.
uriScheme
)
&&
StringUtils
.
hasText
(
this
.
uriHost
))
{
PropertyMapper
map
=
PropertyMapper
.
get
();
this
.
delegate
.
baseUri
(
this
.
uriScheme
+
"://"
+
this
.
uriHost
);
String
host
=
this
.
properties
.
getUriHost
();
}
map
.
from
(
this
.
properties
::
getUriScheme
)
if
(
this
.
uriPort
!=
null
)
{
.
when
((
scheme
)
->
StringUtils
.
hasText
(
scheme
)
this
.
delegate
.
port
(
this
.
uriPort
);
&&
StringUtils
.
hasText
(
host
))
}
.
to
((
scheme
)
->
this
.
delegate
.
baseUri
(
scheme
+
"://"
+
host
));
map
.
from
(
this
.
properties
::
getUriPort
).
whenNonNull
().
to
(
this
.
delegate
::
port
);
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsWebTestClientBuilderCustomizer.java
View file @
b9bb31cf
...
@@ -29,43 +29,16 @@ import org.springframework.util.StringUtils;
...
@@ -29,43 +29,16 @@ import org.springframework.util.StringUtils;
*/
*/
class
RestDocsWebTestClientBuilderCustomizer
implements
WebTestClientBuilderCustomizer
{
class
RestDocsWebTestClientBuilderCustomizer
implements
WebTestClientBuilderCustomizer
{
private
final
WebTestClientRestDocumentationConfigurer
delegate
;
private
final
RestDocsProperties
properties
;
private
String
uriScheme
;
private
String
uriHost
;
private
final
WebTestClientRestDocumentationConfigurer
delegate
;
private
Integer
uriPort
;
RestDocsWebTestClientBuilderCustomizer
(
RestDocsWebTestClientBuilderCustomizer
(
RestDocsProperties
properties
,
WebTestClientRestDocumentationConfigurer
delegate
)
{
WebTestClientRestDocumentationConfigurer
delegate
)
{
this
.
properties
=
properties
;
this
.
delegate
=
delegate
;
this
.
delegate
=
delegate
;
}
}
public
String
getUriScheme
()
{
return
this
.
uriScheme
;
}
public
void
setUriScheme
(
String
uriScheme
)
{
this
.
uriScheme
=
uriScheme
;
}
public
String
getUriHost
()
{
return
this
.
uriHost
;
}
public
void
setUriHost
(
String
uriHost
)
{
this
.
uriHost
=
uriHost
;
}
public
Integer
getUriPort
()
{
return
this
.
uriPort
;
}
public
void
setUriPort
(
Integer
uriPort
)
{
this
.
uriPort
=
uriPort
;
}
@Override
@Override
public
void
customize
(
WebTestClient
.
Builder
builder
)
{
public
void
customize
(
WebTestClient
.
Builder
builder
)
{
customizeBaseUrl
(
builder
);
customizeBaseUrl
(
builder
);
...
@@ -73,21 +46,23 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust
...
@@ -73,21 +46,23 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust
}
}
private
void
customizeBaseUrl
(
WebTestClient
.
Builder
builder
)
{
private
void
customizeBaseUrl
(
WebTestClient
.
Builder
builder
)
{
String
scheme
=
StringUtils
.
hasText
(
this
.
uriScheme
)
?
this
.
uriScheme
:
"http"
;
String
scheme
=
this
.
properties
.
getUriScheme
();
String
host
=
StringUtils
.
hasText
(
this
.
uriHost
)
?
this
.
uriHost
:
"localhost"
;
String
host
=
this
.
properties
.
getUriHost
();
String
baseUrl
=
scheme
+
"://"
+
host
;
String
baseUrl
=
(
StringUtils
.
hasText
(
scheme
)
?
scheme
:
"http"
)
+
"://"
if
(!
isStandardPort
())
{
+
(
StringUtils
.
hasText
(
host
)
?
host
:
"localhost"
);
baseUrl
+=
":"
+
this
.
uriPort
;
Integer
port
=
this
.
properties
.
getUriPort
();
if
(!
isStandardPort
(
scheme
,
port
))
{
baseUrl
+=
":"
+
port
;
}
}
builder
.
baseUrl
(
baseUrl
);
builder
.
baseUrl
(
baseUrl
);
}
}
private
boolean
isStandardPort
()
{
private
boolean
isStandardPort
(
String
scheme
,
Integer
port
)
{
if
(
this
.
uriP
ort
==
null
)
{
if
(
p
ort
==
null
)
{
return
true
;
return
true
;
}
}
return
this
.
uriScheme
.
equals
(
"http"
)
&&
this
.
uriPort
==
80
return
(
scheme
.
equals
(
"http"
)
&&
port
==
80
)
||
this
.
uriScheme
.
equals
(
"https"
)
&&
this
.
uriPort
.
equals
(
443
);
||
(
scheme
.
equals
(
"https"
)
&&
port
==
443
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment