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

Commit c981426

Browse files
author
Dave Syer
committed
Finally a test case that fails
1 parent 27648b3 commit c981426

File tree

6 files changed

+126
-2
lines changed

6 files changed

+126
-2
lines changed

SPR-9498/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@
157157
-->
158158

159159
<!-- Test -->
160+
<dependency>
161+
<groupId>org.springframework</groupId>
162+
<artifactId>spring-test</artifactId>
163+
<version>${org.springframework-version}</version>
164+
<scope>test</scope>
165+
</dependency>
160166
<dependency>
161167
<groupId>junit</groupId>
162168
<artifactId>junit</artifactId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HomeController {
1212

1313
private Foo context;
1414

15-
public void setClientContext(Foo context) {
15+
public void setFoo(Foo context) {
1616
this.context = context;
1717
}
1818

SPR-9498/src/main/resources/log4j.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
3+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
4+
5+
<!-- Appenders -->
6+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
7+
<param name="Target" value="System.out" />
8+
<layout class="org.apache.log4j.PatternLayout">
9+
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
10+
</layout>
11+
</appender>
12+
13+
<!-- Application Loggers -->
14+
<logger name="org.test.mvc">
15+
<level value="info" />
16+
</logger>
17+
18+
<!-- 3rdparty Loggers -->
19+
<logger name="org.springframework.core">
20+
<level value="info" />
21+
</logger>
22+
23+
<logger name="org.springframework.beans">
24+
<level value="info" />
25+
</logger>
26+
27+
<logger name="org.springframework.context">
28+
<level value="info" />
29+
</logger>
30+
31+
<logger name="org.springframework.web">
32+
<level value="info" />
33+
</logger>
34+
35+
<!-- Root Logger -->
36+
<root>
37+
<priority value="warn" />
38+
<appender-ref ref="console" />
39+
</root>
40+
41+
</log4j:configuration>

SPR-9498/src/main/webapp/WEB-INF/spring-servlet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</bean>
1919

2020
<bean class="org.springframework.issues.HomeController">
21-
<property name="clientContext" ref="foo" />
21+
<property name="foo" ref="foo" />
2222
</bean>
2323

2424
<bean id="foo" class="org.springframework.issues.DefaultFoo" scope="request">
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Cloud Foundry 2012.02.03 Beta
3+
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4+
*
5+
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
6+
* You may not use this product except in compliance with the License.
7+
*
8+
* This product includes a number of subcomponents with
9+
* separate copyright notices and license terms. Your use of these
10+
* subcomponents is subject to the terms and conditions of the
11+
* subcomponent's license, as noted in the LICENSE file.
12+
*/
13+
14+
package org.springframework.issues;
15+
16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertNotNull;
18+
19+
import org.junit.After;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
import org.springframework.context.i18n.LocaleContextHolder;
23+
import org.springframework.context.support.GenericXmlApplicationContext;
24+
import org.springframework.mock.web.MockHttpServletRequest;
25+
import org.springframework.test.util.ReflectionTestUtils;
26+
import org.springframework.web.context.request.RequestContextHolder;
27+
import org.springframework.web.context.request.ServletRequestAttributes;
28+
29+
/**
30+
* @author Dave Syer
31+
*
32+
*/
33+
public class ContextTests {
34+
35+
private MockHttpServletRequest request = new MockHttpServletRequest();
36+
37+
@Before
38+
public void initScopes() {
39+
ServletRequestAttributes attributes = new ServletRequestAttributes(request);
40+
LocaleContextHolder.setLocale(request.getLocale(), true);
41+
RequestContextHolder.setRequestAttributes(attributes, true);
42+
}
43+
44+
@After
45+
public void clearScopes() {
46+
LocaleContextHolder.resetLocaleContext();
47+
RequestContextHolder.resetRequestAttributes();
48+
}
49+
50+
@Test
51+
public void test() {
52+
request.setParameter("foo", "bar");
53+
GenericXmlApplicationContext context = new GenericXmlApplicationContext("classpath:/test-context.xml");
54+
HomeController controller = context.getBean(HomeController.class);
55+
Foo foo = (Foo) ReflectionTestUtils.getField(controller, "context");
56+
assertNotNull(foo);
57+
assertEquals("bar", foo.getAccessTokenRequest().getFirst("foo"));
58+
}
59+
60+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
6+
<import resource="file:./src/main/webapp/WEB-INF/spring-servlet.xml"/>
7+
8+
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
9+
<property name="scopes">
10+
<map>
11+
<entry key="request"><bean class="org.springframework.web.context.request.RequestScope"/></entry>
12+
<entry key="session"><bean class="org.springframework.web.context.request.SessionScope"/></entry>
13+
</map>
14+
</property>
15+
</bean>
16+
17+
</beans>

0 commit comments

Comments
 (0)