1
1
/*
2
- * Copyright 2002-2006 the original author or authors.
2
+ * Copyright 2002-2008 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import org .springframework .beans .factory .FactoryBean ;
26
26
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
27
27
import org .springframework .beans .factory .xml .XmlBeanDefinitionReader ;
28
+ import org .springframework .context .expression .StandardBeanExpressionResolver ;
28
29
import org .springframework .core .io .ClassPathResource ;
29
30
import org .springframework .mock .web .MockHttpServletRequest ;
30
31
31
32
/**
32
33
* @author Rob Harrop
33
34
* @author Juergen Hoeller
34
35
* @author Mark Fisher
35
- * @since 2.0
36
36
*/
37
37
public class RequestScopeTests extends TestCase {
38
38
@@ -41,20 +41,23 @@ public class RequestScopeTests extends TestCase {
41
41
protected void setUp () throws Exception {
42
42
this .beanFactory = new DefaultListableBeanFactory ();
43
43
this .beanFactory .registerScope ("request" , new RequestScope ());
44
+ this .beanFactory .setBeanExpressionResolver (new StandardBeanExpressionResolver ());
44
45
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader (this .beanFactory );
45
46
reader .loadBeanDefinitions (new ClassPathResource ("requestScopeTests.xml" , getClass ()));
46
47
this .beanFactory .preInstantiateSingletons ();
47
48
}
48
49
49
50
public void testGetFromScope () throws Exception {
50
51
MockHttpServletRequest request = new MockHttpServletRequest ();
52
+ request .setContextPath ("/path" );
51
53
RequestAttributes requestAttributes = new ServletRequestAttributes (request );
52
54
RequestContextHolder .setRequestAttributes (requestAttributes );
53
55
54
56
try {
55
57
String name = "requestScopedObject" ;
56
58
assertNull (request .getAttribute (name ));
57
59
TestBean bean = (TestBean ) this .beanFactory .getBean (name );
60
+ assertEquals ("/path" , bean .getName ());
58
61
assertSame (bean , request .getAttribute (name ));
59
62
assertSame (bean , this .beanFactory .getBean (name ));
60
63
}
0 commit comments