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? Thanks Adam --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ---------------------------------------------------------------------- CONFIDENTIALITY NOTICE This message and any included attachments are from Cerner Corporation and are intended only for the addressee. The information contained in this message is confidential and may constitute inside or non-public information under international, federal, or state securities laws. Unauthorized forwarding, printing, copying, distribution, or use of such information is strictly prohibited and may be unlawful. If you are not the addressee, please promptly delete this message and notify the sender of the delivery error by e-mail or you may call Cerner's corporate offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]