Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
4818378c
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4818378c
编写于
1月 14, 2016
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better document client-side tests against MockMvc
Issue: SPR-13815
上级
7690f27c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
6 deletion
+30
-6
spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java
...pringframework/test/web/client/MockRestServiceServer.java
+6
-0
src/asciidoc/testing.adoc
src/asciidoc/testing.adoc
+24
-6
未找到文件。
spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java
浏览文件 @
4818378c
...
...
@@ -80,6 +80,12 @@ import org.springframework.web.client.support.RestGatewaySupport;
* classes), you can typically use the Code Completion features (i.e.
* ctrl-space) in your IDE to set up the mocks.
*
* <p>An alternative to the above is to use
* {@link MockMvcClientHttpRequestFactory} which allows executing requests
* against a {@link org.springframework.test.web.servlet.MockMvc MockMvc}
* instance. That allows you to process requests using your server-side code
* but without running a server.
*
* <p><strong>Credits:</strong> The client-side REST testing support was
* inspired by and initially based on similar code in the Spring WS project for
* client-side tests involving the {@code WebServiceTemplate}.
...
...
src/asciidoc/testing.adoc
浏览文件 @
4818378c
...
...
@@ -5035,8 +5035,10 @@ http://www.gebish.org/manual/current/[The Book of Geb] user's manual.
[[
spring
-
mvc
-
test
-
client
]]
====
Client
-
Side
REST
Tests
Client
-
side
tests
are
for
code
using
the
`
RestTemplate
`.
The
goal
is
to
define
expected
requests
and
provide
"stub"
responses
:
Client
-
side
tests
can
be
used
to
test
code
that
internally
uses
the
`
RestTemplate
`.
The
idea
is
to
declare
expected
requests
and
to
provide
"stub"
responses
so
that
you
can
focus
on
testing
the
code
in
isolation
,
i
.
e
.
without
running
a
server
.
Here
is
an
example
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
...
...
@@ -5046,7 +5048,7 @@ requests and provide "stub" responses:
MockRestServiceServer
mockServer
=
MockRestServiceServer
.
createServer
(
restTemplate
);
mockServer
.
expect
(
requestTo
(
"/greeting"
)).
andRespond
(
withSuccess
(
"Hello world"
,
MediaType
.
TEXT_PLAIN
));
//
us
e
RestTemplate
...
//
Test
code
that
uses
the
abov
e
RestTemplate
...
mockServer
.
verify
();
----
...
...
@@ -5056,12 +5058,28 @@ tests -- configures the `RestTemplate` with a custom `ClientHttpRequestFactory`
asserts
actual
requests
against
expectations
and
returns
"stub"
responses
.
In
this
case
we
expect
a
single
request
to
"/greeting"
and
want
to
return
a
200
response
with
"text/plain"
content
.
We
could
define
as
many
additional
requests
and
stub
responses
as
necessary
.
Once
expected
requests
and
stub
responses
have
been
defined
,
the
`
RestTemplate
`
can
be
necessary
.
Once
expected
requests
and
stub
responses
have
been
defined
,
the
`
RestTemplate
`
can
be
used
in
client
-
side
code
as
usual
.
At
the
end
of
the
tests
`
mockServer
.
verify
()`
can
be
used
to
verify
that
all
expected
requests
were
performed
.
The
client
-
side
test
support
also
provides
an
alternative
`
ClientHttpRequestFactory
`
strategy
for
executing
requests
with
a
`
MockMvc
`
instance
.
That
allows
you
to
process
requests
using
your
server
-
side
code
but
without
running
a
server
.
Here
is
an
example
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
----
MockMvc
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
wac
).
build
();
this
.
restTemplate
=
new
RestTemplate
(
new
MockMvcClientHttpRequestFactory
(
mockMvc
));
//
Test
code
that
uses
the
above
RestTemplate
...
mockServer
.
verify
();
----
[[
spring
-
mvc
-
test
-
client
-
static
-
imports
]]
=====
Static
Imports
Just
like
with
server
-
side
tests
,
the
fluent
API
for
client
-
side
tests
requires
a
few
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录