|
19 | 19 | package com.opensymphony.xwork2.ognl; |
20 | 20 |
|
21 | 21 | import com.opensymphony.xwork2.ActionContext; |
22 | | -import com.opensymphony.xwork2.ActionProxyFactory; |
23 | 22 | import com.opensymphony.xwork2.XWorkException; |
24 | 23 | import com.opensymphony.xwork2.XWorkTestCase; |
25 | | -import com.opensymphony.xwork2.config.ConfigurationManager; |
26 | | -import com.opensymphony.xwork2.config.ConfigurationProvider; |
27 | | -import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider; |
| 24 | +import com.opensymphony.xwork2.config.ConfigurationException; |
28 | 25 | import com.opensymphony.xwork2.conversion.impl.XWorkConverter; |
29 | | -import com.opensymphony.xwork2.inject.Container; |
| 26 | +import com.opensymphony.xwork2.inject.ContainerBuilder; |
30 | 27 | import com.opensymphony.xwork2.interceptor.ChainingInterceptor; |
| 28 | +import com.opensymphony.xwork2.test.StubConfigurationProvider; |
31 | 29 | import com.opensymphony.xwork2.test.User; |
32 | 30 | import com.opensymphony.xwork2.util.*; |
| 31 | +import com.opensymphony.xwork2.util.location.LocatableProperties; |
33 | 32 | import com.opensymphony.xwork2.util.reflection.ReflectionContextState; |
34 | 33 | import ognl.*; |
| 34 | +import org.apache.struts2.StrutsConstants; |
35 | 35 |
|
36 | 36 | import java.lang.reflect.Method; |
37 | 37 | import java.text.DateFormat; |
@@ -1312,61 +1312,25 @@ public void testGetExcludedPackageNamePatterns() { |
1312 | 1312 | } |
1313 | 1313 |
|
1314 | 1314 | private void reloadTestContainerConfiguration(boolean devMode, boolean allowStaticMethod) throws Exception { |
1315 | | - super.tearDown(); |
1316 | | - |
1317 | | - ConfigurationProvider configurationProvider; |
1318 | | - if (devMode == true && allowStaticMethod == true) { |
1319 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-allowstatic-devmode-true.xml", true); |
1320 | | - } |
1321 | | - else if (devMode == true && allowStaticMethod == false) { |
1322 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-devmode-true.xml", true); |
1323 | | - } |
1324 | | - else if (devMode == false && allowStaticMethod == true) { |
1325 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-allowstatic-true.xml", true); |
1326 | | - } |
1327 | | - else { // devMode, allowStatic both false |
1328 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-allowstatic-devmode-false.xml", true); |
1329 | | - } |
1330 | | - |
1331 | | - configurationManager = new ConfigurationManager(Container.DEFAULT_NAME); |
1332 | | - configurationManager.addContainerProvider(configurationProvider); |
1333 | | - configuration = configurationManager.getConfiguration(); |
1334 | | - container = configuration.getContainer(); |
1335 | | - container.inject(configurationProvider); |
1336 | | - configurationProvider.init(configuration); |
1337 | | - actionProxyFactory = container.getInstance(ActionProxyFactory.class); |
1338 | | - |
1339 | | - // Reset the value stack |
1340 | | - ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); |
1341 | | - stack.getContext().put(ActionContext.CONTAINER, container); |
1342 | | - ActionContext.setContext(new ActionContext(stack.getContext())); |
1343 | | - |
| 1315 | + loadConfigurationProviders(new StubConfigurationProvider() { |
| 1316 | + @Override |
| 1317 | + public void register(ContainerBuilder builder, |
| 1318 | + LocatableProperties props) throws ConfigurationException { |
| 1319 | + props.setProperty(StrutsConstants.STRUTS_DEVMODE, "" + devMode); |
| 1320 | + props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, "" + allowStaticMethod); |
| 1321 | + } |
| 1322 | + }); |
1344 | 1323 | ognlUtil = container.getInstance(OgnlUtil.class); |
1345 | 1324 | } |
1346 | 1325 |
|
1347 | 1326 | private void reloadTestContainerConfiguration(boolean allowStaticField) throws Exception { |
1348 | | - super.tearDown(); |
1349 | | - |
1350 | | - ConfigurationProvider configurationProvider; |
1351 | | - if (allowStaticField) { |
1352 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-staticfield-true.xml", true); |
1353 | | - } else { |
1354 | | - configurationProvider = new XmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-staticfield-false.xml", true); |
1355 | | - } |
1356 | | - |
1357 | | - configurationManager = new ConfigurationManager(Container.DEFAULT_NAME); |
1358 | | - configurationManager.addContainerProvider(configurationProvider); |
1359 | | - configuration = configurationManager.getConfiguration(); |
1360 | | - container = configuration.getContainer(); |
1361 | | - container.inject(configurationProvider); |
1362 | | - configurationProvider.init(configuration); |
1363 | | - actionProxyFactory = container.getInstance(ActionProxyFactory.class); |
1364 | | - |
1365 | | - // Reset the value stack |
1366 | | - ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); |
1367 | | - stack.getContext().put(ActionContext.CONTAINER, container); |
1368 | | - ActionContext.setContext(new ActionContext(stack.getContext())); |
1369 | | - |
| 1327 | + loadConfigurationProviders(new StubConfigurationProvider() { |
| 1328 | + @Override |
| 1329 | + public void register(ContainerBuilder builder, |
| 1330 | + LocatableProperties props) throws ConfigurationException { |
| 1331 | + props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS, "" + allowStaticField); |
| 1332 | + } |
| 1333 | + }); |
1370 | 1334 | ognlUtil = container.getInstance(OgnlUtil.class); |
1371 | 1335 | } |
1372 | 1336 |
|
|
0 commit comments