Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
41c413a7
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,体验更适合开发者的 AI 搜索 >>
提交
41c413a7
编写于
3月 16, 2017
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add MockServerWebExchange and toExchange shortcuts
Issue: SPR-15350
上级
45aa1edf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
162 addition
and
13 deletion
+162
-13
spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java
...work/mock/http/server/reactive/MockServerHttpRequest.java
+22
-2
spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerWebExchange.java
...work/mock/http/server/reactive/MockServerWebExchange.java
+47
-0
spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java
...ramework/web/server/adapter/DefaultServerWebExchange.java
+0
-9
spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java
...mock/http/server/reactive/test/MockServerHttpRequest.java
+46
-2
spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerWebExchange.java
...mock/http/server/reactive/test/MockServerWebExchange.java
+47
-0
未找到文件。
spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java
浏览文件 @
41c413a7
...
...
@@ -103,6 +103,15 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
return
this
.
cookies
;
}
/**
* Shortcut to wrap the request with a {@code MockServerWebExchange}.
*/
public
MockServerWebExchange
toExchange
()
{
return
new
MockServerWebExchange
(
this
);
}
// Static builder methods
/**
...
...
@@ -199,8 +208,8 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
/**
*
Defines a builder that adds headers to the request
.
* @param <B> the builder subclass
*
Request builder exposing properties not related to the body
.
* @param <B> the builder sub
-
class
*/
public
interface
BaseBuilder
<
B
extends
BaseBuilder
<
B
>>
{
...
...
@@ -290,6 +299,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest
build
();
/**
* Shortcut for:<br>
* {@code build().toExchange()}
*/
MockServerWebExchange
toExchange
();
}
/**
...
...
@@ -466,6 +481,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
public
MockServerHttpRequest
build
()
{
return
body
(
Flux
.
empty
());
}
@Override
public
MockServerWebExchange
toExchange
()
{
return
build
().
toExchange
();
}
}
}
\ No newline at end of file
spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerWebExchange.java
0 → 100644
浏览文件 @
41c413a7
/*
* Copyright 2002-2017 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.mock.http.server.reactive
;
import
org.springframework.web.server.ServerWebExchangeDecorator
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
org.springframework.web.server.session.DefaultWebSessionManager
;
/**
* {@code ServerWebExchange} for use in tests.
*
* <p>Effectively a wrapper around {@link DefaultServerWebExchange} plugged in
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
*
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
*
* @author Rossen Stoyanchev
* @since 5.0
*/
public
class
MockServerWebExchange
extends
ServerWebExchangeDecorator
{
public
MockServerWebExchange
(
MockServerHttpRequest
request
)
{
super
(
new
DefaultServerWebExchange
(
request
,
new
MockServerHttpResponse
(),
new
DefaultWebSessionManager
()));
}
@Override
public
MockServerHttpResponse
getResponse
()
{
return
(
MockServerHttpResponse
)
super
.
getResponse
();
}
}
spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java
浏览文件 @
41c413a7
...
...
@@ -44,7 +44,6 @@ import org.springframework.util.MultiValueMap;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.WebSession
;
import
org.springframework.web.server.session.DefaultWebSessionManager
;
import
org.springframework.web.server.session.WebSessionManager
;
/**
...
...
@@ -82,14 +81,6 @@ public class DefaultServerWebExchange implements ServerWebExchange {
private
volatile
boolean
notModified
;
/**
* Constructor with a request and response only.
* By default creates a session manager of type {@link DefaultWebSessionManager}.
*/
public
DefaultServerWebExchange
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
this
(
request
,
response
,
new
DefaultWebSessionManager
());
}
/**
* Alternate constructor with a WebSessionManager parameter.
*/
...
...
spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java
浏览文件 @
41c413a7
...
...
@@ -103,6 +103,15 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
return
this
.
cookies
;
}
/**
* Shortcut to wrap the request with a {@code MockServerWebExchange}.
*/
public
MockServerWebExchange
toExchange
()
{
return
new
MockServerWebExchange
(
this
);
}
// Static builder methods
/**
...
...
@@ -199,8 +208,8 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
/**
*
Defines a builder that adds headers to the request
.
* @param <B> the builder subclass
*
Request builder exposing properties not related to the body
.
* @param <B> the builder sub
-
class
*/
public
interface
BaseBuilder
<
B
extends
BaseBuilder
<
B
>>
{
...
...
@@ -219,6 +228,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
*/
B
cookie
(
String
path
,
HttpCookie
...
cookie
);
/**
* Add the given cookies.
* @param cookies the cookies.
*/
B
cookies
(
MultiValueMap
<
String
,
HttpCookie
>
cookies
);
/**
* Add the given, single header value under the given name.
* @param headerName the header name
...
...
@@ -227,6 +242,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
*/
B
header
(
String
headerName
,
String
...
headerValues
);
/**
* Add the given header values.
* @param headers the header values
*/
B
headers
(
MultiValueMap
<
String
,
String
>
headers
);
/**
* Set the list of acceptable {@linkplain MediaType media types}, as
* specified by the {@code Accept} header.
...
...
@@ -278,6 +299,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest
build
();
/**
* Shortcut for:<br>
* {@code build().toExchange()}
*/
MockServerWebExchange
toExchange
();
}
/**
...
...
@@ -360,6 +387,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
return
this
;
}
@Override
public
BodyBuilder
cookies
(
MultiValueMap
<
String
,
HttpCookie
>
cookies
)
{
this
.
cookies
.
putAll
(
cookies
);
return
this
;
}
@Override
public
BodyBuilder
header
(
String
headerName
,
String
...
headerValues
)
{
for
(
String
headerValue
:
headerValues
)
{
...
...
@@ -368,6 +401,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
return
this
;
}
@Override
public
BodyBuilder
headers
(
MultiValueMap
<
String
,
String
>
headers
)
{
this
.
headers
.
putAll
(
headers
);
return
this
;
}
@Override
public
BodyBuilder
accept
(
MediaType
...
acceptableMediaTypes
)
{
this
.
headers
.
setAccept
(
Arrays
.
asList
(
acceptableMediaTypes
));
...
...
@@ -442,6 +481,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
public
MockServerHttpRequest
build
()
{
return
body
(
Flux
.
empty
());
}
@Override
public
MockServerWebExchange
toExchange
()
{
return
build
().
toExchange
();
}
}
}
\ No newline at end of file
spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerWebExchange.java
0 → 100644
浏览文件 @
41c413a7
/*
* Copyright 2002-2017 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.mock.http.server.reactive.test
;
import
org.springframework.web.server.ServerWebExchangeDecorator
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
org.springframework.web.server.session.DefaultWebSessionManager
;
/**
* {@code ServerWebExchange} for use in tests.
*
* <p>Effectively a wrapper around {@link DefaultServerWebExchange} plugged in
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
*
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
*
* @author Rossen Stoyanchev
* @since 5.0
*/
public
class
MockServerWebExchange
extends
ServerWebExchangeDecorator
{
public
MockServerWebExchange
(
MockServerHttpRequest
request
)
{
super
(
new
DefaultServerWebExchange
(
request
,
new
MockServerHttpResponse
(),
new
DefaultWebSessionManager
()));
}
@Override
public
MockServerHttpResponse
getResponse
()
{
return
(
MockServerHttpResponse
)
super
.
getResponse
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录