Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
df223eb1
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
df223eb1
编写于
1月 21, 2016
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish custom HTTP verb in Spring MVC Test
Issue: SPR-13719
上级
35543489
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
69 deletion
+54
-69
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
...st/web/servlet/request/MockHttpServletRequestBuilder.java
+10
-12
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java
...work/test/web/servlet/request/MockMvcRequestBuilders.java
+31
-42
spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java
...b/servlet/request/MockHttpServletRequestBuilderTests.java
+13
-15
未找到文件。
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
浏览文件 @
df223eb1
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -113,6 +113,11 @@ public class MockHttpServletRequestBuilder
/**
* Package private constructor. To get an instance, use static factory
* methods in {@link MockMvcRequestBuilders}.
* <p>Although this class cannot be extended, additional ways to initialize
* the {@code MockHttpServletRequest} can be plugged in via
* {@link #with(RequestPostProcessor)}.
* @param httpMethod the HTTP method (GET, POST, etc)
* @param url a URL template; the resulting URL will be encoded
* @param vars zero or more URL variables
...
...
@@ -122,25 +127,18 @@ public class MockHttpServletRequestBuilder
}
/**
* @param httpMethod the HTTP method (GET, POST, etc)
* @param url a URL template; the resulting URL will be encoded
* @param vars zero or more URL variables
* @since 4.3
*/
MockHttpServletRequestBuilder
(
String
httpMethod
,
String
url
,
Object
...
vars
)
{
this
(
httpMethod
,
UriComponentsBuilder
.
fromUriString
(
url
).
buildAndExpand
(
vars
).
encode
().
toUri
());
}
/**
* Alternative to {@link #MockHttpServletRequestBuilder(HttpMethod, String, Object...)}
* with a pre-built URI.
* @param httpMethod the HTTP method (GET, POST, etc)
* @param url the URL
* @since 4.0.3
*/
MockHttpServletRequestBuilder
(
HttpMethod
httpMethod
,
URI
url
)
{
this
(
httpMethod
.
name
(),
url
);
this
(
httpMethod
.
name
(),
url
);
}
/**
* Alternative constructor for custom HTTP methods.
* @param httpMethod the HTTP method (GET, POST, etc)
* @param url the URL
* @since 4.3
...
...
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java
浏览文件 @
df223eb1
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -50,10 +50,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a GET request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
get
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
GET
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
get
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
GET
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -68,10 +68,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
post
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
POST
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
post
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
POST
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -86,10 +86,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PUT request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
put
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
PUT
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
put
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
PUT
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -104,10 +104,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
patch
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
PATCH
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
patch
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
PATCH
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -122,10 +122,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
delete
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
DELETE
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
delete
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
DELETE
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -140,10 +140,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
options
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
OPTIONS
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
options
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
OPTIONS
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -158,11 +158,11 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
* @since 4.1
*/
public
static
MockHttpServletRequestBuilder
head
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
HEAD
,
urlTemplate
,
urlVar
iable
s
);
public
static
MockHttpServletRequestBuilder
head
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
HttpMethod
.
HEAD
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -176,23 +176,12 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method.
* @param
httpM
ethod the HTTP method (GET, POST, etc)
* @param
m
ethod the HTTP method (GET, POST, etc)
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockHttpServletRequestBuilder
request
(
HttpMethod
httpMethod
,
String
urlTemplate
,
Object
...
urlVariables
)
{
return
new
MockHttpServletRequestBuilder
(
httpMethod
,
urlTemplate
,
urlVariables
);
}
/**
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method.
* @param httpMethod the HTTP method (GET, POST, etc)
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @since 4.3
*/
public
static
MockHttpServletRequestBuilder
request
(
String
httpMethod
,
String
urlTemplate
,
Object
...
urlVariables
)
{
return
new
MockHttpServletRequestBuilder
(
httpMethod
,
urlTemplate
,
urlVariables
);
public
static
MockHttpServletRequestBuilder
request
(
HttpMethod
method
,
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockHttpServletRequestBuilder
(
method
,
urlTemplate
,
urlVars
);
}
/**
...
...
@@ -206,8 +195,8 @@ public abstract class MockMvcRequestBuilders {
}
/**
*
Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method
.
* @param httpMethod the HTTP method
(GET, POST, etc)
*
Alternative factory method that allows for custom HTTP verbs (e.g. WebDAV)
.
* @param httpMethod the HTTP method
* @param uri the URL
* @since 4.3
*/
...
...
@@ -218,10 +207,10 @@ public abstract class MockMvcRequestBuilders {
/**
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVar
iable
s zero or more URL variables
* @param urlVars zero or more URL variables
*/
public
static
MockMultipartHttpServletRequestBuilder
fileUpload
(
String
urlTemplate
,
Object
...
urlVar
iable
s
)
{
return
new
MockMultipartHttpServletRequestBuilder
(
urlTemplate
,
urlVar
iable
s
);
public
static
MockMultipartHttpServletRequestBuilder
fileUpload
(
String
urlTemplate
,
Object
...
urlVars
)
{
return
new
MockMultipartHttpServletRequestBuilder
(
urlTemplate
,
urlVars
);
}
/**
...
...
spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java
浏览文件 @
df223eb1
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -25,7 +25,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
javax.servlet.ServletContext
;
import
javax.servlet.http.Cookie
;
...
...
@@ -43,8 +42,12 @@ import org.springframework.util.LinkedMultiValueMap;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.servlet.FlashMap
;
import
org.springframework.web.servlet.support.SessionFlashMapManager
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
/**
* Unit tests for building a {@link MockHttpServletRequest} with
...
...
@@ -429,7 +432,7 @@ public class MockHttpServletRequestBuilderTests {
@Test
public
void
sessionAttributes
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"foo"
,
"bar"
);
this
.
builder
.
sessionAttrs
(
map
);
...
...
@@ -471,9 +474,8 @@ public class MockHttpServletRequestBuilderTests {
assertEquals
(
user
,
request
.
getUserPrincipal
());
}
/**
* See SPR-12945
*/
// SPR-12945
@Test
public
void
mergeInvokesDefaultRequestPostProcessorFirst
()
{
final
String
ATTR
=
"ATTR"
;
...
...
@@ -494,17 +496,13 @@ public class MockHttpServletRequestBuilderTests {
assertEquals
(
EXEPCTED
,
request
.
getAttribute
(
ATTR
));
}
/**
* See SPR-13719
*/
// SPR-13719
@Test
public
void
arbitraryMethod
()
{
/*
* http method is case-sensitive
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1
*/
String
httpMethod
=
"REPort"
;
this
.
builder
=
new
MockHttpServletRequestBuilder
(
httpMethod
,
"/foo/{bar}"
,
42
);
URI
url
=
UriComponentsBuilder
.
fromPath
(
"/foo/{bar}"
).
buildAndExpand
(
42
).
toUri
();
this
.
builder
=
new
MockHttpServletRequestBuilder
(
httpMethod
,
url
);
MockHttpServletRequest
request
=
this
.
builder
.
buildRequest
(
this
.
servletContext
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录