Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
29b12adb
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,发现更多精彩内容 >>
提交
29b12adb
编写于
8月 12, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revised web scoping tests
上级
a79c0152
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
14 deletion
+30
-14
org.springframework.web/src/test/java/org/springframework/web/context/request/RequestAndSessionScopedBeanTests.java
...web/context/request/RequestAndSessionScopedBeanTests.java
+9
-6
org.springframework.web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java
...ramework/web/context/request/RequestScopedProxyTests.java
+21
-8
未找到文件。
org.springframework.web/src/test/java/org/springframework/web/context/request/RequestAndSessionScoped
Proxy
Tests.java
→
org.springframework.web/src/test/java/org/springframework/web/context/request/RequestAndSessionScoped
Bean
Tests.java
浏览文件 @
29b12adb
/*
* Copyright 2002-20
06
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -18,23 +18,23 @@ package org.springframework.web.context.request;
import
javax.servlet.http.HttpServletRequest
;
import
junit.framework.TestCase
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.springframework.beans.TestBean
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.support.StaticWebApplicationContext
;
/**
* @author Rod Johnson
* @author Juergen Hoeller
*/
public
class
RequestAndSessionScoped
ProxyTests
extends
TestCase
{
public
class
RequestAndSessionScoped
BeanTests
{
@Test
public
void
testPutBeanInRequest
()
throws
Exception
{
String
targetBeanName
=
"target"
;
...
...
@@ -73,6 +73,7 @@ public class RequestAndSessionScopedProxyTests extends TestCase {
}
}
@Test
public
void
testPutBeanInSession
()
throws
Exception
{
String
targetBeanName
=
"target"
;
HttpServletRequest
request
=
new
MockHttpServletRequest
();
...
...
@@ -97,6 +98,8 @@ public class RequestAndSessionScopedProxyTests extends TestCase {
catch
(
BeanCreationException
ex
)
{
// expected
}
}
}
org.springframework.web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java
浏览文件 @
29b12adb
/*
* Copyright 2002-20
08
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -16,7 +16,9 @@
package
org.springframework.web.context.request
;
import
junit.framework.TestCase
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.beans.DerivedTestBean
;
...
...
@@ -33,11 +35,12 @@ import org.springframework.mock.web.MockHttpServletRequest;
/**
* @author Juergen Hoeller
*/
public
class
RequestScopedProxyTests
extends
TestCase
{
public
class
RequestScopedProxyTests
{
private
DefaultListableBeanFactory
beanFactory
;
protected
void
setUp
()
throws
Exception
{
@Before
public
void
setUp
()
throws
Exception
{
this
.
beanFactory
=
new
DefaultListableBeanFactory
();
this
.
beanFactory
.
registerScope
(
"request"
,
new
RequestScope
());
XmlBeanDefinitionReader
reader
=
new
XmlBeanDefinitionReader
(
this
.
beanFactory
);
...
...
@@ -45,6 +48,7 @@ public class RequestScopedProxyTests extends TestCase {
this
.
beanFactory
.
preInstantiateSingletons
();
}
@Test
public
void
testGetFromScope
()
throws
Exception
{
String
name
=
"requestScopedObject"
;
TestBean
bean
=
(
TestBean
)
this
.
beanFactory
.
getBean
(
name
);
...
...
@@ -58,15 +62,18 @@ public class RequestScopedProxyTests extends TestCase {
assertNull
(
request
.
getAttribute
(
"scopedTarget."
+
name
));
assertEquals
(
"scoped"
,
bean
.
getName
());
assertNotNull
(
request
.
getAttribute
(
"scopedTarget."
+
name
));
assertEquals
(
TestBean
.
class
,
request
.
getAttribute
(
"scopedTarget."
+
name
).
getClass
());
assertEquals
(
"scoped"
,
((
TestBean
)
request
.
getAttribute
(
"scopedTarget."
+
name
)).
getName
());
TestBean
target
=
(
TestBean
)
request
.
getAttribute
(
"scopedTarget."
+
name
);
assertEquals
(
TestBean
.
class
,
target
.
getClass
());
assertEquals
(
"scoped"
,
target
.
getName
());
assertSame
(
bean
,
this
.
beanFactory
.
getBean
(
name
));
assertEquals
(
bean
.
toString
(),
target
.
toString
());
}
finally
{
RequestContextHolder
.
setRequestAttributes
(
null
);
}
}
@Test
public
void
testGetFromScopeThroughDynamicProxy
()
throws
Exception
{
String
name
=
"requestScopedProxy"
;
ITestBean
bean
=
(
ITestBean
)
this
.
beanFactory
.
getBean
(
name
);
...
...
@@ -80,15 +87,18 @@ public class RequestScopedProxyTests extends TestCase {
assertNull
(
request
.
getAttribute
(
"scopedTarget."
+
name
));
assertEquals
(
"scoped"
,
bean
.
getName
());
assertNotNull
(
request
.
getAttribute
(
"scopedTarget."
+
name
));
assertEquals
(
TestBean
.
class
,
request
.
getAttribute
(
"scopedTarget."
+
name
).
getClass
());
assertEquals
(
"scoped"
,
((
TestBean
)
request
.
getAttribute
(
"scopedTarget."
+
name
)).
getName
());
TestBean
target
=
(
TestBean
)
request
.
getAttribute
(
"scopedTarget."
+
name
);
assertEquals
(
TestBean
.
class
,
target
.
getClass
());
assertEquals
(
"scoped"
,
target
.
getName
());
assertSame
(
bean
,
this
.
beanFactory
.
getBean
(
name
));
assertEquals
(
bean
.
toString
(),
target
.
toString
());
}
finally
{
RequestContextHolder
.
setRequestAttributes
(
null
);
}
}
@Test
public
void
testDestructionAtRequestCompletion
()
throws
Exception
{
String
name
=
"requestScopedDisposableObject"
;
DerivedTestBean
bean
=
(
DerivedTestBean
)
this
.
beanFactory
.
getBean
(
name
);
...
...
@@ -114,6 +124,7 @@ public class RequestScopedProxyTests extends TestCase {
}
}
@Test
public
void
testGetFromFactoryBeanInScope
()
throws
Exception
{
String
name
=
"requestScopedFactoryBean"
;
TestBean
bean
=
(
TestBean
)
this
.
beanFactory
.
getBean
(
name
);
...
...
@@ -135,6 +146,7 @@ public class RequestScopedProxyTests extends TestCase {
}
}
@Test
public
void
testGetInnerBeanFromScope
()
throws
Exception
{
TestBean
bean
=
(
TestBean
)
this
.
beanFactory
.
getBean
(
"outerBean"
);
assertFalse
(
AopUtils
.
isAopProxy
(
bean
));
...
...
@@ -158,6 +170,7 @@ public class RequestScopedProxyTests extends TestCase {
}
}
@Test
public
void
testGetAnonymousInnerBeanFromScope
()
throws
Exception
{
TestBean
bean
=
(
TestBean
)
this
.
beanFactory
.
getBean
(
"outerBean"
);
assertFalse
(
AopUtils
.
isAopProxy
(
bean
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录