You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2008/04/02 13:23:55 UTC

struts.xml

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.


Thanks
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts.xml

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I completely jumped the gun. My test was flawed and on fixing it, I found that 
struts was reloading its config on my dispatcher.init() call, and then again 
just before the request but without my config and so ignoring the configured 
Dispatch that I set!

I tried the other approach but I can't see any way to get hold of the Dispatcher 
(since Dispatcher.getInstance() returns null before I launch the request).




Adam Hardy on 04/04/08 00:46, wrote:
> Brian, thanks for the low-down. It works well.
> 
> 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:Brian.Relph@Cerner.com] 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:ahardy.struts@cyberspaceroad.com]
>> 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.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts.xml

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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:Brian.Relph@Cerner.com] 
> 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:ahardy.struts@cyberspaceroad.com]
> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: struts.xml

Posted by "Relph,Brian" <Br...@Cerner.com>.
 
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:Brian.Relph@Cerner.com] 
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:ahardy.struts@cyberspaceroad.com]
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

----------------------------------------------------------------------
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: struts.xml

Posted by "Relph,Brian" <Br...@Cerner.com>.
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:ahardy.struts@cyberspaceroad.com] 
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

----------------------------------------------------------------------
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts.xml

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org