Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
1d35c7c5
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,发现更多精彩内容 >>
提交
1d35c7c5
编写于
1月 25, 2017
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish MockMvc setup classes
上级
2d951994
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
29 deletion
+38
-29
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
...mework/test/web/servlet/setup/AbstractMockMvcBuilder.java
+12
-14
spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java
...rk/test/web/servlet/setup/ConfigurableMockMvcBuilder.java
+3
-2
spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java
...ngframework/test/web/servlet/setup/MockMvcConfigurer.java
+23
-13
未找到文件。
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
浏览文件 @
1d35c7c5
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -33,14 +33,16 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import
org.springframework.test.web.servlet.request.RequestPostProcessor
;
import
org.springframework.util.Assert
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.test.web.servlet.MockMvcBuilder
;
/**
* An abstract implementation of {@link org.springframework.test.web.servlet.MockMvcBuilder}
* with common methods for configuring filters, default request properties, global
* expectations and global result actions.
* <p>
* Sub-classes can use different strategies to prepare a WebApplicationContext to
* pass to the DispatcherServlet.
* Abstract implementation of {@link MockMvcBuilder} with common methods for
* configuring filters, default request properties, global expectations and
* global result actions.
*
* <p>Sub-classes can use different strategies to prepare the Spring
* {@code WebApplicationContext} that will be passed to the
* {@code DispatcherServlet}.
*
* @author Rossen Stoyanchev
* @author Stephane Nicoll
...
...
@@ -64,7 +66,6 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
public
final
<
T
extends
B
>
T
addFilters
(
Filter
...
filters
)
{
Assert
.
notNull
(
filters
,
"filters cannot be null"
);
for
(
Filter
f
:
filters
)
{
Assert
.
notNull
(
f
,
"filters cannot contain null values"
);
this
.
filters
.
add
(
f
);
...
...
@@ -73,14 +74,11 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
}
public
final
<
T
extends
B
>
T
addFilter
(
Filter
filter
,
String
...
urlPatterns
)
{
Assert
.
notNull
(
filter
,
"filter cannot be null"
);
Assert
.
notNull
(
urlPatterns
,
"urlPatterns cannot be null"
);
if
(
urlPatterns
.
length
>
0
)
{
filter
=
new
PatternMappingFilterProxy
(
filter
,
urlPatterns
);
}
this
.
filters
.
add
(
filter
);
return
self
();
}
...
...
@@ -153,9 +151,9 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
}
/**
* A method to obtain the
WebApplicationContext to be passed to the DispatcherServlet.
* Invoked from {@link #build()} before the
* {@link
org.springframework.test.web.servlet.
MockMvc} instance is created.
* A method to obtain the
{@code WebApplicationContext} to be passed to the
*
{@code DispatcherServlet}.
Invoked from {@link #build()} before the
* {@link MockMvc} instance is created.
*/
protected
abstract
WebApplicationContext
initWebAppContext
();
...
...
spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java
浏览文件 @
1d35c7c5
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -29,7 +29,8 @@ import org.springframework.test.web.servlet.ResultMatcher;
* @author Rossen Stoyanchev
* @since 4.1
*/
public
interface
ConfigurableMockMvcBuilder
<
B
extends
ConfigurableMockMvcBuilder
<
B
>>
extends
MockMvcBuilder
{
public
interface
ConfigurableMockMvcBuilder
<
B
extends
ConfigurableMockMvcBuilder
<
B
>>
extends
MockMvcBuilder
{
/**
* Add filters mapped to any request (i.e. "/*"). For example:
...
...
spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java
浏览文件 @
1d35c7c5
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -19,17 +19,21 @@ package org.springframework.test.web.servlet.setup;
import
org.springframework.test.web.servlet.request.RequestPostProcessor
;
import
org.springframework.web.context.WebApplicationContext
;
/**
*
Allows a sub-class to encapsulate logic for pre-configuring a
*
{@code ConfigurableMockMvcBuilder} for some specific purpose. A 3rd party
*
library may use this to provide shortcuts for setting up
MockMvc.
*
Contract for customizing a {@code ConfigurableMockMvcBuilder} in some
*
specific way, e.g. a 3rd party library that wants to provide shortcuts for
*
setting up a
MockMvc.
*
* <p>Can be plugged in via {@link ConfigurableMockMvcBuilder#apply} with
* instances of this type likely created via static methods, e.g.:
* <p>An implementation of this interface can be plugged in via
* {@link ConfigurableMockMvcBuilder#apply} with instances of this type likely
* created via static methods, e.g.:
*
* <pre class="code">
* MockMvcBuilders.webAppContextSetup(context).apply(mySetup("foo","bar")).build();
* import static org.example.ExampleSetup.mySetup;
*
* // ...
*
* MockMvcBuilders.webAppContextSetup(context).apply(mySetup("foo","bar")).build();
* </pre>
*
* @author Rossen Stoyanchev
...
...
@@ -39,16 +43,22 @@ import org.springframework.web.context.WebApplicationContext;
public
interface
MockMvcConfigurer
{
/**
* Invoked immediately
after a
{@code MockMvcConfigurer} is added via
* Invoked immediately
when this
{@code MockMvcConfigurer} is added via
* {@link ConfigurableMockMvcBuilder#apply}.
* @param builder the builder for the MockMvc
*/
void
afterConfigurerAdded
(
ConfigurableMockMvcBuilder
<?>
builder
);
/**
* Invoked just before the MockMvc instance is created. Implementations may
* return a RequestPostProcessor to be applied to every request performed
* through the created {@code MockMvc} instance.
* Invoked when the MockMvc instance is about to be created with the MockMvc
* builder and the Spring WebApplicationContext that will be passed to the
* {@code DispatcherServlet}.
* @param builder the builder for the MockMvc
* @param context the Spring configuration
* @return a post processor to be applied to every request performed
* through the {@code MockMvc} instance.
*/
RequestPostProcessor
beforeMockMvcCreated
(
ConfigurableMockMvcBuilder
<?>
builder
,
WebApplicationContext
context
);
RequestPostProcessor
beforeMockMvcCreated
(
ConfigurableMockMvcBuilder
<?>
builder
,
WebApplicationContext
context
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录