Skip to content

Commit 29b12ad

Browse files
committed
revised web scoping tests
1 parent a79c015 commit 29b12ad

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,23 +18,23 @@
1818

1919
import javax.servlet.http.HttpServletRequest;
2020

21-
import junit.framework.TestCase;
21+
import static org.junit.Assert.*;
22+
import org.junit.Test;
2223

2324
import org.springframework.beans.TestBean;
24-
import org.springframework.beans.factory.support.RootBeanDefinition;
2525
import org.springframework.beans.factory.BeanCreationException;
26+
import org.springframework.beans.factory.support.RootBeanDefinition;
2627
import org.springframework.mock.web.MockHttpServletRequest;
2728
import org.springframework.web.context.WebApplicationContext;
28-
import org.springframework.web.context.request.RequestContextHolder;
29-
import org.springframework.web.context.request.ServletRequestAttributes;
3029
import org.springframework.web.context.support.StaticWebApplicationContext;
3130

3231
/**
3332
* @author Rod Johnson
3433
* @author Juergen Hoeller
3534
*/
36-
public class RequestAndSessionScopedProxyTests extends TestCase {
35+
public class RequestAndSessionScopedBeanTests {
3736

37+
@Test
3838
public void testPutBeanInRequest() throws Exception {
3939
String targetBeanName = "target";
4040

@@ -73,6 +73,7 @@ public void testPutBeanInRequest() throws Exception {
7373
}
7474
}
7575

76+
@Test
7677
public void testPutBeanInSession() throws Exception {
7778
String targetBeanName = "target";
7879
HttpServletRequest request = new MockHttpServletRequest();
@@ -97,6 +98,8 @@ public void testPutBeanInSession() throws Exception {
9798
catch (BeanCreationException ex) {
9899
// expected
99100
}
101+
102+
100103
}
101104

102105
}

org.springframework.web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,9 @@
1616

1717
package org.springframework.web.context.request;
1818

19-
import junit.framework.TestCase;
19+
import static org.junit.Assert.*;
20+
import org.junit.Before;
21+
import org.junit.Test;
2022

2123
import org.springframework.aop.support.AopUtils;
2224
import org.springframework.beans.DerivedTestBean;
@@ -33,18 +35,20 @@
3335
/**
3436
* @author Juergen Hoeller
3537
*/
36-
public class RequestScopedProxyTests extends TestCase {
38+
public class RequestScopedProxyTests {
3739

3840
private DefaultListableBeanFactory beanFactory;
3941

40-
protected void setUp() throws Exception {
42+
@Before
43+
public void setUp() throws Exception {
4144
this.beanFactory = new DefaultListableBeanFactory();
4245
this.beanFactory.registerScope("request", new RequestScope());
4346
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
4447
reader.loadBeanDefinitions(new ClassPathResource("requestScopedProxyTests.xml", getClass()));
4548
this.beanFactory.preInstantiateSingletons();
4649
}
4750

51+
@Test
4852
public void testGetFromScope() throws Exception {
4953
String name = "requestScopedObject";
5054
TestBean bean = (TestBean) this.beanFactory.getBean(name);
@@ -58,15 +62,18 @@ public void testGetFromScope() throws Exception {
5862
assertNull(request.getAttribute("scopedTarget." + name));
5963
assertEquals("scoped", bean.getName());
6064
assertNotNull(request.getAttribute("scopedTarget." + name));
61-
assertEquals(TestBean.class, request.getAttribute("scopedTarget." + name).getClass());
62-
assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName());
65+
TestBean target = (TestBean) request.getAttribute("scopedTarget." + name);
66+
assertEquals(TestBean.class, target.getClass());
67+
assertEquals("scoped", target.getName());
6368
assertSame(bean, this.beanFactory.getBean(name));
69+
assertEquals(bean.toString(), target.toString());
6470
}
6571
finally {
6672
RequestContextHolder.setRequestAttributes(null);
6773
}
6874
}
6975

76+
@Test
7077
public void testGetFromScopeThroughDynamicProxy() throws Exception {
7178
String name = "requestScopedProxy";
7279
ITestBean bean = (ITestBean) this.beanFactory.getBean(name);
@@ -80,15 +87,18 @@ public void testGetFromScopeThroughDynamicProxy() throws Exception {
8087
assertNull(request.getAttribute("scopedTarget." + name));
8188
assertEquals("scoped", bean.getName());
8289
assertNotNull(request.getAttribute("scopedTarget." + name));
83-
assertEquals(TestBean.class, request.getAttribute("scopedTarget." + name).getClass());
84-
assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName());
90+
TestBean target = (TestBean) request.getAttribute("scopedTarget." + name);
91+
assertEquals(TestBean.class, target.getClass());
92+
assertEquals("scoped", target.getName());
8593
assertSame(bean, this.beanFactory.getBean(name));
94+
assertEquals(bean.toString(), target.toString());
8695
}
8796
finally {
8897
RequestContextHolder.setRequestAttributes(null);
8998
}
9099
}
91100

101+
@Test
92102
public void testDestructionAtRequestCompletion() throws Exception {
93103
String name = "requestScopedDisposableObject";
94104
DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
@@ -114,6 +124,7 @@ public void testDestructionAtRequestCompletion() throws Exception {
114124
}
115125
}
116126

127+
@Test
117128
public void testGetFromFactoryBeanInScope() throws Exception {
118129
String name = "requestScopedFactoryBean";
119130
TestBean bean = (TestBean) this.beanFactory.getBean(name);
@@ -135,6 +146,7 @@ public void testGetFromFactoryBeanInScope() throws Exception {
135146
}
136147
}
137148

149+
@Test
138150
public void testGetInnerBeanFromScope() throws Exception {
139151
TestBean bean = (TestBean) this.beanFactory.getBean("outerBean");
140152
assertFalse(AopUtils.isAopProxy(bean));
@@ -158,6 +170,7 @@ public void testGetInnerBeanFromScope() throws Exception {
158170
}
159171
}
160172

173+
@Test
161174
public void testGetAnonymousInnerBeanFromScope() throws Exception {
162175
TestBean bean = (TestBean) this.beanFactory.getBean("outerBean");
163176
assertFalse(AopUtils.isAopProxy(bean));

0 commit comments

Comments
 (0)