1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 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.
49
49
* @author Juergen Hoeller
50
50
* @author Chris Beams
51
51
*/
52
- public final class ClassPathXmlApplicationContextTests {
52
+ public class ClassPathXmlApplicationContextTests {
53
53
54
54
private static final String PATH = "/org/springframework/context/support/" ;
55
55
private static final String RESOURCE_CONTEXT = PATH + "ClassPathXmlApplicationContextTests-resource.xml" ;
@@ -82,13 +82,23 @@ public void testSingleConfigLocation() {
82
82
@ Test
83
83
public void testMultipleConfigLocations () {
84
84
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
85
- new String [] { FQ_CONTEXT_B , FQ_CONTEXT_C , FQ_CONTEXT_A } );
85
+ FQ_CONTEXT_B , FQ_CONTEXT_C , FQ_CONTEXT_A );
86
86
assertTrue (ctx .containsBean ("service" ));
87
87
assertTrue (ctx .containsBean ("logicOne" ));
88
88
assertTrue (ctx .containsBean ("logicTwo" ));
89
+
90
+ // re-refresh (after construction refresh)
89
91
Service service = (Service ) ctx .getBean ("service" );
90
92
ctx .refresh ();
91
93
assertTrue (service .isProperlyDestroyed ());
94
+
95
+ // regular close call
96
+ service = (Service ) ctx .getBean ("service" );
97
+ ctx .close ();
98
+ assertTrue (service .isProperlyDestroyed ());
99
+
100
+ // re-activating and re-closing the context (SPR-13425)
101
+ ctx .refresh ();
92
102
service = (Service ) ctx .getBean ("service" );
93
103
ctx .close ();
94
104
assertTrue (service .isProperlyDestroyed ());
@@ -107,16 +117,15 @@ public void testConfigLocationPattern() {
107
117
108
118
@ Test
109
119
public void testSingleConfigLocationWithClass () {
110
- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
111
- SIMPLE_CONTEXT , getClass ());
120
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (SIMPLE_CONTEXT , getClass ());
112
121
assertTrue (ctx .containsBean ("someMessageSource" ));
113
122
ctx .close ();
114
123
}
115
124
116
125
@ Test
117
126
public void testAliasWithPlaceholder () {
118
127
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
119
- new String [] { FQ_CONTEXT_B , FQ_ALIASED_CONTEXT_C , FQ_CONTEXT_A } );
128
+ FQ_CONTEXT_B , FQ_ALIASED_CONTEXT_C , FQ_CONTEXT_A );
120
129
assertTrue (ctx .containsBean ("service" ));
121
130
assertTrue (ctx .containsBean ("logicOne" ));
122
131
assertTrue (ctx .containsBean ("logicTwo" ));
@@ -144,16 +153,14 @@ public void testContextWithInvalidValueType() throws IOException {
144
153
private void checkExceptionFromInvalidValueType (Throwable ex ) throws IOException {
145
154
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
146
155
ex .printStackTrace (new PrintStream (baos ));
147
- String dump = FileCopyUtils .copyToString (
148
- new InputStreamReader (new ByteArrayInputStream (baos .toByteArray ())));
156
+ String dump = FileCopyUtils .copyToString (new InputStreamReader (new ByteArrayInputStream (baos .toByteArray ())));
149
157
assertTrue (dump .contains ("someMessageSource" ));
150
158
assertTrue (dump .contains ("useCodeAsDefaultMessage" ));
151
159
}
152
160
153
161
@ Test
154
162
public void testContextWithInvalidLazyClass () {
155
- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
156
- INVALID_CLASS_CONTEXT , getClass ());
163
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (INVALID_CLASS_CONTEXT , getClass ());
157
164
assertTrue (ctx .containsBean ("someMessageSource" ));
158
165
try {
159
166
ctx .getBean ("someMessageSource" );
@@ -167,8 +174,7 @@ public void testContextWithInvalidLazyClass() {
167
174
168
175
@ Test
169
176
public void testContextWithClassNameThatContainsPlaceholder () {
170
- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
171
- CLASS_WITH_PLACEHOLDER_CONTEXT , getClass ());
177
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (CLASS_WITH_PLACEHOLDER_CONTEXT , getClass ());
172
178
assertTrue (ctx .containsBean ("someMessageSource" ));
173
179
assertTrue (ctx .getBean ("someMessageSource" ) instanceof StaticMessageSource );
174
180
ctx .close ();
@@ -282,7 +288,7 @@ public void testAliasThatOverridesParent() {
282
288
@ Test
283
289
public void testAliasThatOverridesEarlierBean () {
284
290
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
285
- new String [] { FQ_SIMPLE_CONTEXT , ALIAS_THAT_OVERRIDES_PARENT_CONTEXT } );
291
+ FQ_SIMPLE_CONTEXT , ALIAS_THAT_OVERRIDES_PARENT_CONTEXT );
286
292
Object myMs = ctx .getBean ("myMessageSource" );
287
293
Object someMs2 = ctx .getBean ("someMessageSource" );
288
294
assertSame (myMs , someMs2 );
0 commit comments