Brian, thanks for the low-down. It works well.
Regards
Adam
Relph,Brian on 03/04/08 15:53, wrote:
Copy paste error, you need to initialize the Dispatcher with your testConfig map:
Map<String, String> testConfig = new HashMap<String, String>();
testConfig.put("config",
"struts-default.xml,struts-plugin.xml,struts.xml,struts-test.xml");
dispatcher = new Dispatcher(servletContext,
testConfig);
dispatcher.init();
Dispatcher.setInstance(dispatcher);
-----Original Message-----
From: Relph,Brian [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2008 9:48 AM
To: Struts Users Mailing List
Subject: RE: struts.xml
You need to have access to the Dispatcher and the ServletContext in your tests,
but you could do something like this for per-unit test configurations:
ConfigurationProvider provider = new StrutsXmlConfigurationProvider(
"struts-test.xml", true, servletContext);
dispatcher.getConfigurationManager().addConfigurationProvider(provider);
dispatcher.getConfigurationManager().reload();
If you set devMode = true for your tests, you might be able to avoid the
reload() call.
If you have a just a single "struts-test.xml" for all of your tests, you could
do something like this in your setUp():
Map<String, String> testConfig = new HashMap<String, String>();
testConfig.put("config",
"struts-default.xml,struts-plugin.xml,struts.xml,struts-test.xml");
dispatcher = new Dispatcher(servletContext,
new HashMap<String, String>());
dispatcher.init();
Dispatcher.setInstance(dispatcher);
-----Original Message-----
From: Adam Hardy [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2008 5:00 AM
To: Struts Users Mailing List
Subject: Re: struts.xml
Adam Hardy on 02/04/08 12:23, wrote:
Can I have a second struts.xml in my test directory, and if so, how do
I configure it?
I'm testing some stuff using HttpUnit which launches the whole webapp
in my tests. Having a test-only struts.xml will keep the test mappings
out of the real webapp, allow me to drop stuff I don't need for the
tests, and make the tests faster.
From the lack of replies, I assume the answer is 'No, you cannot have an
alternative struts.xml'.
I was checking the low-down on the wiki, where I found that the struts
configuration xml can be in multiple files listed by the property in the
struts.properties:
### A list of configuration files automatically loaded by Struts
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
Using this property, I can set up my maven environment to filter
struts.properties as a resource and set that property explicitly, so in testing
I can have 'struts-test.xml'
This works to a limited extent, i.e. one struts.xml for all testing, another
for in-container deployment.
It's not quite ideal though, as I would prefer to choose the struts.xml on a
per-test basis.
Does anyone know of something I've missed that allows this?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]