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
5320081d
Commit
5320081d
authored
Mar 14, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Only create a WebTestClient with WebFlux"
This reverts commit
282bd9f0
parent
b80620fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
37 deletions
+39
-37
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+0
-3
AutoConfigureWebTestClient.java
...utoconfigure/web/reactive/AutoConfigureWebTestClient.java
+1
-2
WebTestClientAutoConfiguration.java
...onfigure/web/reactive/WebTestClientAutoConfiguration.java
+1
-5
WebTestClientAutoConfigurationTests.java
...ure/web/reactive/WebTestClientAutoConfigurationTests.java
+37
-27
No files found.
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
5320081d
...
...
@@ -6520,9 +6520,6 @@ example shows a class that uses both `@WebFluxTest` and a `WebTestClient`:
}
----
TIP: This setup is only supported by WebFlux applications as using `WebTestClient` in a
mocked web application only works with WebFlux at the moment.
A list of the auto-configuration that is enabled by `@WebFluxTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java
View file @
5320081d
...
...
@@ -29,8 +29,7 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
import
org.springframework.test.web.reactive.server.WebTestClient
;
/**
* Annotation that can be applied to a test class to enable a {@link WebTestClient}. At
* the moment, only WebFlux applications are supported.
* Annotation that can be applied to a test class to enable a {@link WebTestClient}.
*
* @author Stephane Nicoll
* @since 2.0.0
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java
View file @
5320081d
...
...
@@ -22,11 +22,9 @@ import java.util.List;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
...
...
@@ -35,7 +33,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
org.springframework.web.server.WebHandler
;
/**
* Auto-configuration for {@link WebTestClient}.
...
...
@@ -46,13 +43,12 @@ import org.springframework.web.server.WebHandler;
*/
@Configuration
@ConditionalOnClass
({
WebClient
.
class
,
WebTestClient
.
class
})
@AutoConfigureAfter
(
{
CodecsAutoConfiguration
.
class
,
WebFluxAutoConfiguration
.
class
}
)
@AutoConfigureAfter
(
CodecsAutoConfiguration
.
class
)
@EnableConfigurationProperties
public
class
WebTestClientAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
WebHandler
.
class
)
public
WebTestClient
webTestClient
(
ApplicationContext
applicationContext
,
List
<
WebTestClientBuilderCustomizer
>
customizers
)
{
WebTestClient
.
Builder
builder
=
WebTestClient
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java
View file @
5320081d
...
...
@@ -18,15 +18,18 @@ package org.springframework.boot.test.autoconfigure.web.reactive;
import
java.time.Duration
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Collections
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.http.codec.CodecConfigurer
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
...
...
@@ -41,43 +44,50 @@ import static org.mockito.Mockito.verify;
* Tests for {@link WebTestClientAutoConfiguration}
*
* @author Brian Clozel
* @author Stephane Nicoll
*/
public
class
WebTestClientAutoConfigurationTests
{
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
WebTestClientAutoConfiguration
.
class
));
private
AnnotationConfigApplicationContext
context
;
@Test
public
void
shouldNotBeConfiguredWithoutWebHandler
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
).
doesNotHaveBean
(
WebTestClient
.
class
);
});
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
shouldCustomizeClientCodecs
()
{
this
.
contextRunner
.
withUserConfiguration
(
CodecConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
WebTestClient
.
class
);
assertThat
(
context
).
hasSingleBean
(
CodecCustomizer
.
class
);
verify
(
context
.
getBean
(
CodecCustomizer
.
class
)).
customize
(
any
(
CodecConfigurer
.
class
));
});
load
(
CodecConfiguration
.
class
);
WebTestClient
webTestClient
=
this
.
context
.
getBean
(
WebTestClient
.
class
);
CodecCustomizer
codecCustomizer
=
this
.
context
.
getBean
(
CodecCustomizer
.
class
);
assertThat
(
webTestClient
).
isNotNull
();
verify
(
codecCustomizer
).
customize
(
any
(
CodecConfigurer
.
class
));
}
@Test
public
void
shouldCustomizeTimeout
()
{
this
.
contextRunner
.
withUserConfiguration
(
BaseConfiguration
.
class
)
.
withPropertyValues
(
"spring.test.webtestclient.timeout=15m"
)
.
run
((
context
)
->
{
WebTestClient
webTestClient
=
context
.
getBean
(
WebTestClient
.
class
);
Object
duration
=
ReflectionTestUtils
.
getField
(
webTestClient
,
"timeout"
);
assertThat
(
duration
).
isEqualTo
(
Duration
.
of
(
15
,
ChronoUnit
.
MINUTES
));
});
PropertySource
<?>
propertySource
=
new
MapPropertySource
(
"test"
,
Collections
.
singletonMap
(
"spring.test.webtestclient.timeout"
,
(
Object
)
"PT15M"
));
load
(
propertySource
,
BaseConfiguration
.
class
);
WebTestClient
webTestClient
=
this
.
context
.
getBean
(
WebTestClient
.
class
);
Object
duration
=
ReflectionTestUtils
.
getField
(
webTestClient
,
"timeout"
);
assertThat
(
duration
).
isEqualTo
(
Duration
.
of
(
15
,
ChronoUnit
.
MINUTES
));
}
private
void
load
(
Class
<?>...
config
)
{
load
(
null
,
config
);
}
private
void
load
(
PropertySource
<?>
propertySource
,
Class
<?>...
config
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
if
(
propertySource
!=
null
)
{
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
}
context
.
register
(
config
);
context
.
register
(
WebTestClientAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
}
@Configuration
...
...
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