Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
65afc808
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,发现更多精彩内容 >>
提交
65afc808
编写于
4月 01, 2009
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Working on SPR-5631
上级
accf9747
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
111 addition
and
7 deletion
+111
-7
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
...notation/UriTemplateServletAnnotationControllerTests.java
+111
-7
未找到文件。
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
浏览文件 @
65afc808
...
...
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.junit.Ignore
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
...
...
@@ -21,6 +22,7 @@ import org.springframework.web.bind.WebDataBinder;
import
org.springframework.web.bind.annotation.InitBinder
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.support.GenericWebApplicationContext
;
import
org.springframework.web.servlet.DispatcherServlet
;
...
...
@@ -44,10 +46,10 @@ public class UriTemplateServletAnnotationControllerTests {
public
void
multiple
()
throws
Exception
{
initServlet
(
MultipleUriTemplateController
.
class
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42/bookings/21"
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42/bookings/21
-other
"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"test-42-21"
,
response
.
getContentAsString
());
assertEquals
(
"test-42-21
-other
"
,
response
.
getContentAsString
());
}
@Test
...
...
@@ -71,6 +73,7 @@ public class UriTemplateServletAnnotationControllerTests {
}
@Test
@Ignore
(
"In progress"
)
public
void
relative
()
throws
Exception
{
initServlet
(
RelativePathUriTemplateController
.
class
);
...
...
@@ -78,6 +81,11 @@ public class UriTemplateServletAnnotationControllerTests {
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"test-42-21"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42/bookings/21.html"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"test-42-21"
,
response
.
getContentAsString
());
}
@Test
...
...
@@ -101,6 +109,48 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"Invalid response status code"
,
HttpServletResponse
.
SC_BAD_REQUEST
,
response
.
getStatus
());
}
@Test
public
void
explicitSubPath
()
throws
Exception
{
initServlet
(
ExplicitSubPathController
.
class
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"test-42"
,
response
.
getContentAsString
());
}
@Test
@Ignore
(
"In progress"
)
public
void
implicitSubPath
()
throws
Exception
{
initServlet
(
ImplicitSubPathController
.
class
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"test-42"
,
response
.
getContentAsString
());
}
@Test
@Ignore
(
"In progress"
)
public
void
crud
()
throws
Exception
{
initServlet
(
CrudController
.
class
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"getHotels"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"POST"
,
"/hotels"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"newHotel"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"POST"
,
"/hotels"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"newHotel"
,
response
.
getContentAsString
());
}
private
void
initServlet
(
final
Class
<?>
controllerclass
)
throws
ServletException
{
servlet
=
new
DispatcherServlet
()
{
@Override
...
...
@@ -133,12 +183,14 @@ public class UriTemplateServletAnnotationControllerTests {
@Controller
public
static
class
MultipleUriTemplateController
{
@RequestMapping
(
"/hotels/{hotel}/bookings/{booking}"
)
public
void
handle
(
@PathVariable
(
"hotel"
)
String
hotel
,
@PathVariable
int
booking
,
Writer
writer
)
throws
IOException
{
@RequestMapping
(
"/hotels/{hotel}/bookings/{booking}-{other}"
)
public
void
handle
(
@PathVariable
(
"hotel"
)
String
hotel
,
@PathVariable
int
booking
,
@PathVariable
String
other
,
Writer
writer
)
throws
IOException
{
assertEquals
(
"Invalid path variable value"
,
"42"
,
hotel
);
assertEquals
(
"Invalid path variable value"
,
21
,
booking
);
writer
.
write
(
"test-"
+
hotel
+
"-"
+
booking
);
writer
.
write
(
"test-"
+
hotel
+
"-"
+
booking
+
"-"
+
other
);
}
}
...
...
@@ -166,7 +218,7 @@ public class UriTemplateServletAnnotationControllerTests {
}
@Controller
@RequestMapping
(
"/hotels/{hotel}
/**
"
)
@RequestMapping
(
"/hotels/{hotel}"
)
public
static
class
RelativePathUriTemplateController
{
@RequestMapping
(
"bookings/{booking}"
)
...
...
@@ -198,7 +250,59 @@ public class UriTemplateServletAnnotationControllerTests {
writer
.
write
(
"wildcard"
);
}
}
@Controller
@RequestMapping
(
"/hotels/*"
)
public
static
class
ExplicitSubPathController
{
@RequestMapping
(
"{hotel}"
)
public
void
handleHotel
(
@PathVariable
String
hotel
,
Writer
writer
)
throws
IOException
{
writer
.
write
(
"test-"
+
hotel
);
}
}
@Controller
@RequestMapping
(
"hotels"
)
public
static
class
ImplicitSubPathController
{
@RequestMapping
(
"{hotel}"
)
public
void
handleHotel
(
@PathVariable
String
hotel
,
Writer
writer
)
throws
IOException
{
writer
.
write
(
"test-"
+
hotel
);
}
}
@Controller
@RequestMapping
(
"hotels"
)
public
static
class
CrudController
{
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
void
list
(
Writer
writer
)
throws
IOException
{
writer
.
write
(
"list"
);
}
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
void
create
(
Writer
writer
)
throws
IOException
{
writer
.
write
(
"create"
);
}
@RequestMapping
(
value
=
"{hotel}"
,
method
=
RequestMethod
.
GET
)
public
void
show
(
@PathVariable
String
hotel
,
Writer
writer
)
throws
IOException
{
writer
.
write
(
"show-"
+
hotel
);
}
@RequestMapping
(
value
=
"{hotel}"
,
method
=
RequestMethod
.
PUT
)
public
void
createOrUpdate
(
@PathVariable
String
hotel
,
Writer
writer
)
throws
IOException
{
writer
.
write
(
"createOrUpdate-"
+
hotel
);
}
@RequestMapping
(
value
=
"{hotel}"
,
method
=
RequestMethod
.
DELETE
)
public
void
remove
(
@PathVariable
String
hotel
,
Writer
writer
)
throws
IOException
{
writer
.
write
(
"remove-"
+
hotel
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录