Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 3f38001

Browse files
author
Dave Syer
committed
Add passing test
1 parent cbc8302 commit 3f38001

File tree

6 files changed

+52
-65
lines changed

6 files changed

+52
-65
lines changed

SPR-9498/src/main/java/org/springframework/issues/DefaultFoo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
*/
2121
public class DefaultFoo implements Foo {
2222

23-
private Bar accessTokenRequest;
23+
private Bar bar;
2424

25-
public DefaultFoo(Bar accessTokenRequest) {
26-
this.accessTokenRequest = accessTokenRequest;
25+
public DefaultFoo(Bar bar) {
26+
this.bar = bar;
2727
}
2828

29-
public Bar getAccessTokenRequest() {
30-
return accessTokenRequest;
29+
public Bar getBar() {
30+
return bar;
3131
}
3232

3333
}

SPR-9498/src/main/java/org/springframework/issues/Foo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
*/
2121
public interface Foo {
2222

23-
Bar getAccessTokenRequest();
23+
Bar getBar();
2424
}

SPR-9498/src/main/java/org/springframework/issues/HomeController.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

SPR-9498/src/test/java/org/springframework/issues/ContextTests.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.context.i18n.LocaleContextHolder;
2323
import org.springframework.context.support.GenericXmlApplicationContext;
2424
import org.springframework.mock.web.MockHttpServletRequest;
25-
import org.springframework.test.util.ReflectionTestUtils;
2625
import org.springframework.web.context.request.RequestContextHolder;
2726
import org.springframework.web.context.request.ServletRequestAttributes;
2827

@@ -48,13 +47,21 @@ public void clearScopes() {
4847
}
4948

5049
@Test
51-
public void test() {
50+
public void testOK() {
51+
request.setParameter("foo", "bar");
52+
GenericXmlApplicationContext context = new GenericXmlApplicationContext("classpath:/ok-context.xml");
53+
Foo foo = context.getBean(Foo.class);
54+
assertNotNull(foo);
55+
assertEquals("bar", foo.getBar().getFirst("foo"));
56+
}
57+
58+
@Test
59+
public void testFails() {
5260
request.setParameter("foo", "bar");
5361
GenericXmlApplicationContext context = new GenericXmlApplicationContext("classpath:/test-context.xml");
54-
HomeController controller = context.getBean(HomeController.class);
55-
Foo foo = (Foo) ReflectionTestUtils.getField(controller, "context");
62+
Foo foo = context.getBean(Foo.class);
5663
assertNotNull(foo);
57-
assertEquals("bar", foo.getAccessTokenRequest().getFirst("foo"));
64+
assertEquals("bar", foo.getBar().getFirst("foo"));
5865
}
5966

6067
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:aop="http://www.springframework.org/schema/aop"
4+
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
5+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<!--Basic application beans. -->
8+
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
9+
<property name="prefix" value="/WEB-INF/jsp/" />
10+
<property name="suffix" value=".jsp" />
11+
</bean>
12+
13+
<bean id="foo" class="org.springframework.issues.DefaultFoo" scope="request">
14+
<aop:scoped-proxy proxy-target-class="false" />
15+
<constructor-arg ref="bar" />
16+
</bean>
17+
18+
<bean id="bar" class="org.springframework.issues.DefaultBar" scope="request">
19+
<aop:scoped-proxy proxy-target-class="false" />
20+
<constructor-arg value="#{request.parameterMap}" />
21+
</bean>
22+
23+
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
24+
<property name="scopes">
25+
<map>
26+
<entry key="request"><bean class="org.springframework.web.context.request.RequestScope"/></entry>
27+
<entry key="session"><bean class="org.springframework.web.context.request.SessionScope"/></entry>
28+
</map>
29+
</property>
30+
</bean>
31+
32+
</beans>

SPR-9498/src/test/resources/test-context.xml

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,6 @@
66

77
<bean id="conversionService" class="org.springframework.core.convert.support.DefaultConversionService" />
88

9-
<!--Basic application beans. -->
10-
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
11-
<property name="prefix" value="/WEB-INF/jsp/" />
12-
<property name="suffix" value=".jsp" />
13-
</bean>
14-
15-
<bean class="org.springframework.issues.HomeController">
16-
<property name="foo" ref="foo" />
17-
</bean>
18-
19-
<bean id="foo" class="org.springframework.issues.DefaultFoo" scope="request">
20-
<aop:scoped-proxy proxy-target-class="false" />
21-
<constructor-arg ref="tokenRequest" />
22-
</bean>
23-
24-
<bean id="tokenRequest" class="org.springframework.issues.DefaultBar" scope="request">
25-
<aop:scoped-proxy proxy-target-class="false" />
26-
<constructor-arg value="#{request.parameterMap}" />
27-
</bean>
28-
29-
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
30-
<property name="scopes">
31-
<map>
32-
<entry key="request"><bean class="org.springframework.web.context.request.RequestScope"/></entry>
33-
<entry key="session"><bean class="org.springframework.web.context.request.SessionScope"/></entry>
34-
</map>
35-
</property>
36-
</bean>
37-
9+
<import resource="ok-context.xml"/>
10+
3811
</beans>

0 commit comments

Comments
 (0)