Author Login
Post Reply
user Digest 4 Apr 2008 14:21:47 -0000 Issue 7964
Topics (messages 185046 through 185063):
form within form
185046 by: puneet duggal
185053 by: Ehteshamul Haque
Re: Tiles in 1.3.9
185047 by: Antonio Petrelli
185049 by: Lukasz Lenart
185050 by: Antonio Petrelli
185056 by: balaji.m.cs
185057 by: Mihai Scripca
185058 by: Antonio Petrelli
Re: [S2] Struts with Web Services
185048 by: Lukasz Lenart
Re: Freemarker (old version that struts2 uses) disappearing pages
185051 by: Jonny Cavell
Re: any struts 2 unit testers out there?
185052 by: paulbrickell
185054 by: paulbrickell
185055 by: paulbrickell
185062 by: Karr, David
185063 by: Ian Roughley
[OT] What do you code today?
185059 by: Ted Husted
Re: struts.xml
185060 by: Adam Hardy
Re: Struts 2.1 TabbedPanel scenario
185061 by: Shoaib Gauhar
Administrivia:
---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)
----------------------------------------------------------------------

Attachment:
user_185046.ezm (zipped)hello friends Is it possible? that we can take form within form
---------------------------------
Sent from Yahoo! Mail.
A Smarter Inbox.

Attachment:
user_185053.ezm (zipped)I dont think so. Can you please tell why we need that? you can use lookup dispatch action if you want to chose action depending upon criterion.
Thank you.
----------------
Ehteshamul Haque
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com

Attachment:
user_185047.ezm (zipped)
Attachment:
user_185049.ezm (zipped)Hi,
> <struts-config>
> <action-mappings>
> <action path="/baselayout"
forward=".tiles-defs"/>
> </action-mappings>
> tiles-defs.xml
<definition name=".tiles-defs" path="/jsp/baseLayout.jsp">
There is good practice to start Tiles definitions with dot -> .tiles-defs
I don't see ant forwards in your struts-config.xml, could you past them here?
Regards
--
Lukasz
http://www.linkedin.com/in/lukaszlenart

Attachment:
user_185050.ezm (zipped)2008/4/4, Lukasz Lenart <lukasz.lenart@(protected)>:
>
> Hi,
>
>
> > <struts-config>
> > <action-mappings>
> > <action path="/baselayout"
> forward=".tiles-defs"/>
> > </action-mappings>
>
>
> > tiles-defs.xml
>
> <definition name=".tiles-defs" path="/jsp/baseLayout.jsp">
Good catch Lukasz! Now I remember that:
*Struts-Tiles does not support forward actions, only forwards inside normal
actions*
Antonio

Attachment:
user_185056.ezm (zipped)
i point the issue by myself.
the main issue is i have not given the
<controller processorClass="org.apache.struts.action.TilesRequestProcessor"
bufferSize="4096" debug="0"/>
in struts-config.xml.
after i give its working... thanks for giving me the best pratices on
tiles...
if u still find any issues in my code pls say so that i can have a
correction....
Lukasz Lenart wrote:
>
> Hi,
>
>> <struts-config>
>> <action-mappings>
>> <action path="/baselayout"
> forward=".tiles-defs"/>
>> </action-mappings>
>
>> tiles-defs.xml
> <definition name=".tiles-defs" path="/jsp/baseLayout.jsp">
>
> There is good practice to start Tiles definitions with dot -> .tiles-defs
> I don't see ant forwards in your struts-config.xml, could you past them
> here?
>
>
> Regards
> --
> Lukasz
>
> http://www.linkedin.com/in/lukaszlenart
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_185057.ezm (zipped)dont you think it would be better practice naming tiles like this:
tile.def (*.def are like .jsp but virtual pages)
and only class tiles should be named with dot first like this .class-name?
> i point the issue by myself.
> the main issue is i have not given the
>
> <controller processorClass="org.apache.struts.action.TilesRequestProcessor"
> bufferSize="4096" debug="0"/>
> in struts-config.xml.
> after i give its working... thanks for giving me the best pratices on
> tiles...
>
> if u still find any issues in my code pls say so that i can have a
> correction....
>
> Lukasz Lenart wrote:
>
>> Hi,
>>
>>
>>> <struts-config>
>>> <action-mappings>
>>> <action path="/baselayout"
>>>
>> forward=".tiles-defs"/>
>>
>>> </action-mappings>
>>>
>>> tiles-defs.xml
>>>
>> <definition name=".tiles-defs" path="/jsp/baseLayout.jsp">
>>
>> There is good practice to start Tiles definitions with dot -> .tiles-defs
>> I don't see ant forwards in your struts-config.xml, could you past them
>> here?
>>
>>
>> Regards
>> --
>> Lukasz
>>
>> http://www.linkedin.com/in/lukaszlenart
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>>
>
>

Attachment:
user_185058.ezm (zipped)2008/4/4, Mihai Scripca <mihaiscripca@(protected)>:
>
> dont you think it would be better practice naming tiles like this:
> tile.def (*.def are like .jsp but virtual pages)
>
> and only class tiles should be named with dot first like this .class-name?
Well, there is no guideline/best practice defined for Tiles definition
names, so you can do your own :-D
Antonio

Attachment:
user_185048.ezm (zipped)> http://www.ja-sig.org/products/cas/
>
> -Wes
Do you have some experience with that? It looks quite interesting ;-)
Regards
--
Lukasz
http://www.linkedin.com/in/lukaszlenart

Attachment:
user_185051.ezm (zipped)
I use Maven, and if you look at struts 2.0.11.1's dependencies
(http://www.mvnrepository.com/artifact/org.apache.struts/struts2-core/2.0.11.1)
you'll see that it's Freemarker version 2.3.8 it depends on. I can't
override this in Maven, even if I attempt to exclude it and force the latest
version of Freemarker:
....
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11</version>
<exclusions>
<exclusion>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.12</version>
</dependency>
....
Cheers
Jonny
Jeromy Evans - Blue Sky Minds wrote:
>
> Jonny Cavell wrote:
>> I have a problem that seems to occur periodically.
>>
>> My freemarker templates, served by struts2, stop appearing - I get a
>> blank
>> page. There are no useful messages in the logs, other than saying that it
>> couldn't find the template (which it could find previously).
>>
>> First question - does anybody know what this problem might be?
>>
>>
> No, other than a classpath/deployment problem.
>> I would like to upgrade to the latest version of Freemarker. However,
>> Struts2 in its wisdom has locked me down to version 2.3.8, and this was
>> released way back in 2006. Are there any plans to resolve this issue?
>>
>>
> The 2.1.1 version of Struts uses FreeMarker 2.3.11 You may be able to
> replace the 2.3.8 jar with the 2.3.11 jar without problems.
>
> I doubt the problem is with FreeMarker. It's more likely to be the
> FreeMarkerManager included with Struts 2 that's responsible for
> searching for templates in the classpath.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_185052.ezm (zipped)Actually thats an interesting post. To my mind it doesn't demonstrate a
solution. It demonstrates the problem.
Here is why I think this.
Struts 2 is just frankly brilliant for people doing test first development.
The classes you create really are POJOs. There are no dependencies on any
framework in my action classes. For example parameters are parsed well away
from my action and the values are set using simple properties, things like
sessions are simply maps. It is a truly new world for those of who have
suffered the horror of mocking http requests, responses, context and the
like.
But this simple scenario brings all that pain flooding back. I add a line in
my action like this...
String yadaYada = getText("some.doodad");
And my lovely world comes unraveled real quick. Now I need mock objects up
the ying-yang.
I started using the tutorial from the link posted (I am an Arsenal fan btw,
so got two for the price of one, thanks), but it still doesn't provide a
simple solution to the problem. To get this to work I have to build not just
the application context but a mass of supporting objects to get a web
application framework up and running before I can test my simple POJO.
I am not going to give up just yet, but I think I am still going to have to
look for another way.
Cheers,
Paul B.
Relph,Brian wrote:
>
>
> I recommend creating an action context. Here is the basic guide I
> followed to do so:
>
> http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>
> If you are not using spring or the struts2 spring plugin, you can cut out
> all the code around the applicationContext.
>
>
> -----Original Message-----
> From: paulbrickell [mailto:paul.brickell@(protected)]
> Sent: Thursday, April 03, 2008 11:44 AM
> To: user@(protected)
> Subject: Re: any struts 2 unit testers out there?
>
>
> I am trying to deal with the same issue. Did you get any resolution?
>
> Following on from the reply asking for a stack trace, here is what I am
> getting...
>
>
>
java.lang.NullPointerException> at
>
com.opensymphony.xwork2.util.LocalizedTextUtil.findText (
LocalizedTextUtil.java:299)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:172)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:87)
> at
com.opensymphony.xwork2.ActionSupport.getText (
ActionSupport.java:80)
> <SNIP>
> at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
sun.reflect.NativeMethodAccessorImpl.invoke (
NativeMethodAccessorImpl.java:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke (
DelegatingMethodAccessorImpl.java:25)
> at
java.lang.reflect.Method.invoke (
Method.java:585)
> at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> at
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
> at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
> at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:460)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:673)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (
RemoteTestRunner.java:386)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (
RemoteTestRunner.java:196)
>
>
> It is caused by ActionContext.getContext() returning null. Quite obviously
> I do not have an action context during my unit testing.
>
> Now I can certainly use the ActionContext.setContext() in my tests setup
> method to push one into thread local storage and that works OK. It isn't
> ideal though because ActionContext is a concrete class and so my choices
> then become a bit limited.
>
> I could create an instance but when I try this I find I have to create a
> rather large object model to make it actually work. To the point where I
> despair and give up.
>
> Alternatively I could use a mock library (like easy mock). But I am not
> inclined to include a mocking library that requires byte code rewriting
> (not even for testing).
>
> What I really want to do is inject a text provider into the ActionSupport
> class. At the top of the ActionSupport class is this...
>
> private final transient TextProvider textProvider = new
> TextProviderFactory().createInstance(getClass(), this);
>
> Damn its final and so I cannot inject my own text provider.
>
> BUT it uses a factory, thats good. I know I will have a look at the
> factory I bet I can monkey with that and inject a mock. Nope. It's all
> instance based. No way I can get in there. And thats that. Now what do I
> do?
>
> I can see two (half) workable solutions.
>
> One is to override the the getText method in the action class when I
> instantiate it during testing. So I end up doing this in all my action
> unit tests...
>
> Action action = new MyAction()
> {
> @Override
> public String getText(String textName)
> {
> return "mocked";
> }
> };
>
> It works, but its cheese.
>
> Or two I can add a level of indirection in my action class, like so...
>
>
> String text =
> MyTextProviderFactory.getInstance(class.name).getText("some.property");
>
> Then I can use a delegate to the real text provider during live code and a
> mock of my own text provider during testing. The question here is, Why for
> the love of Pete, why?
>
> So in conclusion there are at least four options for testing Action
> classes that use get text.
>
> 1. Build an action context by hand. (Too hard) 2. Use a class rewriting
> mocking library. (Not on my watch) 3. Mock the get text method. (Cheese)
> 4. Add another level of indirection. (Man thats just annoying)
>
> Comments?
>
> BTW If you got this far, thanks for taking the time.
> Paul B.
>
>
>
>
> Session Mwamufiya wrote:
>>
>> Hi All,
>>
>> Would someone let me know whether it's possible to tweak something so
>> that JUnit test code can run on an action method that calls the
>> ActionSupport method getText() to fetch string resources from a
>> package.properties file.
>> As it stands, I keep getting a null exception when getText() is called
>> during the unit test.
>>
>> Thanks,
>> Session
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p16467812.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(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: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_185054.ezm (zipped)Actually thats an interesting post. To my mind it doesn't demonstrate a
solution. It demonstrates the problem.
Here is why I think this.
Struts 2 is just frankly brilliant for people doing test first development.
The classes you create really are POJOs. There are no dependencies on any
framework in my action classes. For example parameters are parsed well away
from my action and the values are set using simple properties, things like
sessions are simply maps. It is a truly new world for those of who have
suffered the horror of mocking http requests, responses, context and the
like.
But this simple scenario brings all that pain flooding back. I add a line in
my action like this...
String yadaYada = getText("some.doodad");
And my lovely world comes unraveled real quick. Now I need mock objects up
the ying-yang.
I started using the tutorial from the link posted (I am an Arsenal fan btw,
so got two for the price of one, thanks), but it still doesn't provide a
simple solution to the problem. To get this to work I have to build not just
the application context but a mass of supporting objects to get a web
application framework up and running before I can test my simple POJO.
I am not going to give up just yet, but I think I am still going to have to
look for another way.
Cheers,
Paul B.
Relph,Brian wrote:
>
>
> I recommend creating an action context. Here is the basic guide I
> followed to do so:
>
> http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>
> If you are not using spring or the struts2 spring plugin, you can cut out
> all the code around the applicationContext.
>
>
> -----Original Message-----
> From: paulbrickell [mailto:paul.brickell@(protected)]
> Sent: Thursday, April 03, 2008 11:44 AM
> To: user@(protected)
> Subject: Re: any struts 2 unit testers out there?
>
>
> I am trying to deal with the same issue. Did you get any resolution?
>
> Following on from the reply asking for a stack trace, here is what I am
> getting...
>
>
>
java.lang.NullPointerException> at
>
com.opensymphony.xwork2.util.LocalizedTextUtil.findText (
LocalizedTextUtil.java:299)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:172)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:87)
> at
com.opensymphony.xwork2.ActionSupport.getText (
ActionSupport.java:80)
> <SNIP>
> at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
sun.reflect.NativeMethodAccessorImpl.invoke (
NativeMethodAccessorImpl.java:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke (
DelegatingMethodAccessorImpl.java:25)
> at
java.lang.reflect.Method.invoke (
Method.java:585)
> at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> at
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
> at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
> at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:460)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:673)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (
RemoteTestRunner.java:386)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (
RemoteTestRunner.java:196)
>
>
> It is caused by ActionContext.getContext() returning null. Quite obviously
> I do not have an action context during my unit testing.
>
> Now I can certainly use the ActionContext.setContext() in my tests setup
> method to push one into thread local storage and that works OK. It isn't
> ideal though because ActionContext is a concrete class and so my choices
> then become a bit limited.
>
> I could create an instance but when I try this I find I have to create a
> rather large object model to make it actually work. To the point where I
> despair and give up.
>
> Alternatively I could use a mock library (like easy mock). But I am not
> inclined to include a mocking library that requires byte code rewriting
> (not even for testing).
>
> What I really want to do is inject a text provider into the ActionSupport
> class. At the top of the ActionSupport class is this...
>
> private final transient TextProvider textProvider = new
> TextProviderFactory().createInstance(getClass(), this);
>
> Damn its final and so I cannot inject my own text provider.
>
> BUT it uses a factory, thats good. I know I will have a look at the
> factory I bet I can monkey with that and inject a mock. Nope. It's all
> instance based. No way I can get in there. And thats that. Now what do I
> do?
>
> I can see two (half) workable solutions.
>
> One is to override the the getText method in the action class when I
> instantiate it during testing. So I end up doing this in all my action
> unit tests...
>
> Action action = new MyAction()
> {
> @Override
> public String getText(String textName)
> {
> return "mocked";
> }
> };
>
> It works, but its cheese.
>
> Or two I can add a level of indirection in my action class, like so...
>
>
> String text =
> MyTextProviderFactory.getInstance(class.name).getText("some.property");
>
> Then I can use a delegate to the real text provider during live code and a
> mock of my own text provider during testing. The question here is, Why for
> the love of Pete, why?
>
> So in conclusion there are at least four options for testing Action
> classes that use get text.
>
> 1. Build an action context by hand. (Too hard) 2. Use a class rewriting
> mocking library. (Not on my watch) 3. Mock the get text method. (Cheese)
> 4. Add another level of indirection. (Man thats just annoying)
>
> Comments?
>
> BTW If you got this far, thanks for taking the time.
> Paul B.
>
>
>
>
> Session Mwamufiya wrote:
>>
>> Hi All,
>>
>> Would someone let me know whether it's possible to tweak something so
>> that JUnit test code can run on an action method that calls the
>> ActionSupport method getText() to fetch string resources from a
>> package.properties file.
>> As it stands, I keep getting a null exception when getText() is called
>> during the unit test.
>>
>> Thanks,
>> Session
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p16467812.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(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: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_185055.ezm (zipped)Actually thats an interesting post. To my mind it doesn't demonstrate a
solution. It demonstrates the problem.
Here is why I think this.
Struts 2 is just frankly brilliant for people doing test first development.
The classes you create really are POJOs. There are no dependencies on any
framework in my action classes. For example parameters are parsed well away
from my action and the values are set using simple properties, things like
sessions are simply maps. It is a truly new world for those of who have
suffered the horror of mocking http requests, responses, context and the
like.
But this simple scenario brings all that pain flooding back. I add a line in
my action like this...
String yadaYada = getText("some.doodad");
And my lovely world comes unraveled real quick. Now I need mock objects up
the ying-yang.
I started using the tutorial from the link posted (I am an Arsenal fan btw,
so got two for the price of one, thanks), but it still doesn't provide a
simple solution to the problem. To get this to work I have to build not just
the application context but a mass of supporting objects to get a (partial)
web application framework up and running before I can test my simple POJO.
I am not going to give up just yet, but I think I am still going to have to
look for another way.
Cheers,
Paul B.
Relph,Brian wrote:
>
>
> I recommend creating an action context. Here is the basic guide I
> followed to do so:
>
> http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>
> If you are not using spring or the struts2 spring plugin, you can cut out
> all the code around the applicationContext.
>
>
> -----Original Message-----
> From: paulbrickell [mailto:paul.brickell@(protected)]
> Sent: Thursday, April 03, 2008 11:44 AM
> To: user@(protected)
> Subject: Re: any struts 2 unit testers out there?
>
>
> I am trying to deal with the same issue. Did you get any resolution?
>
> Following on from the reply asking for a stack trace, here is what I am
> getting...
>
>
>
java.lang.NullPointerException> at
>
com.opensymphony.xwork2.util.LocalizedTextUtil.findText (
LocalizedTextUtil.java:299)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:172)
> at
>
com.opensymphony.xwork2.TextProviderSupport.getText (
TextProviderSupport.java:87)
> at
com.opensymphony.xwork2.ActionSupport.getText (
ActionSupport.java:80)
> <SNIP>
> at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
sun.reflect.NativeMethodAccessorImpl.invoke (
NativeMethodAccessorImpl.java:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke (
DelegatingMethodAccessorImpl.java:25)
> at
java.lang.reflect.Method.invoke (
Method.java:585)
> at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> at
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
> at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
> at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:460)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
RemoteTestRunner.java:673)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (
RemoteTestRunner.java:386)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (
RemoteTestRunner.java:196)
>
>
> It is caused by ActionContext.getContext() returning null. Quite obviously
> I do not have an action context during my unit testing.
>
> Now I can certainly use the ActionContext.setContext() in my tests setup
> method to push one into thread local storage and that works OK. It isn't
> ideal though because ActionContext is a concrete class and so my choices
> then become a bit limited.
>
> I could create an instance but when I try this I find I have to create a
> rather large object model to make it actually work. To the point where I
> despair and give up.
>
> Alternatively I could use a mock library (like easy mock). But I am not
> inclined to include a mocking library that requires byte code rewriting
> (not even for testing).
>
> What I really want to do is inject a text provider into the ActionSupport
> class. At the top of the ActionSupport class is this...
>
> private final transient TextProvider textProvider = new
> TextProviderFactory().createInstance(getClass(), this);
>
> Damn its final and so I cannot inject my own text provider.
>
> BUT it uses a factory, thats good. I know I will have a look at the
> factory I bet I can monkey with that and inject a mock. Nope. It's all
> instance based. No way I can get in there. And thats that. Now what do I
> do?
>
> I can see two (half) workable solutions.
>
> One is to override the the getText method in the action class when I
> instantiate it during testing. So I end up doing this in all my action
> unit tests...
>
> Action action = new MyAction()
> {
> @Override
> public String getText(String textName)
> {
> return "mocked";
> }
> };
>
> It works, but its cheese.
>
> Or two I can add a level of indirection in my action class, like so...
>
>
> String text =
> MyTextProviderFactory.getInstance(class.name).getText("some.property");
>
> Then I can use a delegate to the real text provider during live code and a
> mock of my own text provider during testing. The question here is, Why for
> the love of Pete, why?
>
> So in conclusion there are at least four options for testing Action
> classes that use get text.
>
> 1. Build an action context by hand. (Too hard) 2. Use a class rewriting
> mocking library. (Not on my watch) 3. Mock the get text method. (Cheese)
> 4. Add another level of indirection. (Man thats just annoying)
>
> Comments?
>
> BTW If you got this far, thanks for taking the time.
> Paul B.
>
>
>
>
> Session Mwamufiya wrote:
>>
>> Hi All,
>>
>> Would someone let me know whether it's possible to tweak something so
>> that JUnit test code can run on an action method that calls the
>> ActionSupport method getText() to fetch string resources from a
>> package.properties file.
>> As it stands, I keep getting a null exception when getText() is called
>> during the unit test.
>>
>> Thanks,
>> Session
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p16467812.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(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: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_185062.ezm (zipped)And did you investigate using either of the common Java frameworks for
Mock objects, jMock and EasyMock?
> -----Original Message-----
> From: paulbrickell [mailto:paul.brickell@(protected)]
> Sent: Friday, April 04, 2008 3:04 AM
> To: user@(protected)
> Subject: RE: any struts 2 unit testers out there?
>
>
> Actually thats an interesting post. To my mind it doesn't
> demonstrate a solution. It demonstrates the problem.
>
> Here is why I think this.
>
> Struts 2 is just frankly brilliant for people doing test
> first development.
> The classes you create really are POJOs. There are no
> dependencies on any framework in my action classes. For
> example parameters are parsed well away from my action and
> the values are set using simple properties, things like
> sessions are simply maps. It is a truly new world for those
> of who have suffered the horror of mocking http requests,
> responses, context and the like.
>
> But this simple scenario brings all that pain flooding back.
> I add a line in my action like this...
>
> String yadaYada = getText("some.doodad");
>
> And my lovely world comes unraveled real quick. Now I need
> mock objects up the ying-yang.
>
> I started using the tutorial from the link posted (I am an
> Arsenal fan btw, so got two for the price of one, thanks),
> but it still doesn't provide a simple solution to the
> problem. To get this to work I have to build not just the
> application context but a mass of supporting objects to get a
> (partial) web application framework up and running before I
> can test my simple POJO.
>
> I am not going to give up just yet, but I think I am still
> going to have to look for another way.
>
> Cheers,
> Paul B.
>
>
>
>
> Relph,Brian wrote:
> >
> >
> > I recommend creating an action context. Here is the basic guide I
> > followed to do so:
> >
> >
> http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-
> > junit/
> >
> > If you are not using spring or the struts2 spring plugin,
> you can cut
> > out all the code around the applicationContext.
> >
> >
> > -----Original Message-----
> > From: paulbrickell [mailto:paul.brickell@(protected)]
> > Sent: Thursday, April 03, 2008 11:44 AM
> > To: user@(protected)
> > Subject: Re: any struts 2 unit testers out there?
> >
> >
> > I am trying to deal with the same issue. Did you get any resolution?
> >
> > Following on from the reply asking for a stack trace, here
> is what I
> > am getting...
> >
> >
> >
java.lang.NullPointerException> > at
> >
>
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(Locali
> zedTextUtil.java:299)
> > at
> >
>
com.opensymphony.xwork2.TextProviderSupport.getText(TextProvid
> erSupport.java:172)
> > at
> >
>
com.opensymphony.xwork2.TextProviderSupport.getText(TextProvid
> erSupport.java:87)
> > at
>
com.opensymphony.xwork2.ActionSupport.getText (
ActionSupport.java:80)
> > <SNIP>
> > at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.java:39)
> > at
> >
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessorImpl.java:25)
> > at
java.lang.reflect.Method.invoke (
Method.java:585)
> > at
> org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> > at
> >
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRo
> adie.java:98)
> > at
> org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> > at
> >
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThen
> Afters(MethodRoadie.java:87)
> > at
> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> > at
> org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> > at
> >
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(
> JUnit4ClassRunner.java:88)
> > at
> >
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4
> ClassRunner.java:51)
> > at
> >
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4Class
Runner.java:44)
> > at
> >
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoa
> die.java:27)
> > at
> >
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadi
> e.java:37)
> > at
> >
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRu
> nner.java:42)
> > at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
> (JUnit4TestReference.java:38)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestEx
> ecution.java:38)
> > at
> >
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTest> s(RemoteTestRunner.java:460)
> > at
> >
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTest> s(RemoteTestRunner.java:673)
> > at
> >
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Rem
> oteTestRunner.java:386)
> > at
> >
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTest
> > Runner.java:196)
> >
> >
> > It is caused by ActionContext.getContext() returning null. Quite
> > obviously I do not have an action context during my unit testing.
> >
> > Now I can certainly use the ActionContext.setContext() in my tests
> > setup method to push one into thread local storage and that
> works OK.
> > It isn't ideal though because ActionContext is a concrete
> class and so
> > my choices then become a bit limited.
> >
> > I could create an instance but when I try this I find I
> have to create
> > a rather large object model to make it actually work. To the point
> > where I despair and give up.
> >
> > Alternatively I could use a mock library (like easy mock). But I am
> > not inclined to include a mocking library that requires byte code
> > rewriting (not even for testing).
> >
> > What I really want to do is inject a text provider into the
> > ActionSupport class. At the top of the ActionSupport class
> is this...
> >
> > private final transient TextProvider textProvider = new
> > TextProviderFactory().createInstance(getClass(), this);
> >
> > Damn its final and so I cannot inject my own text provider.
> >
> > BUT it uses a factory, thats good. I know I will have a look at the
> > factory I bet I can monkey with that and inject a mock.
> Nope. It's all
> > instance based. No way I can get in there. And thats that.
> Now what do
> > I do?
> >
> > I can see two (half) workable solutions.
> >
> > One is to override the the getText method in the action
> class when I
> > instantiate it during testing. So I end up doing this in
> all my action
> > unit tests...
> >
> > Action action = new MyAction()
> > {
> > @Override
> > public String getText(String textName)
> > {
> > return "mocked";
> > }
> > };
> >
> > It works, but its cheese.
> >
> > Or two I can add a level of indirection in my action class,
> like so...
> >
> >
> > String text =
> >
> MyTextProviderFactory.getInstance(class.name).getText("some.property")
> > ;
> >
> > Then I can use a delegate to the real text provider during
> live code
> > and a mock of my own text provider during testing. The
> question here
> > is, Why for the love of Pete, why?
> >
> > So in conclusion there are at least four options for testing Action
> > classes that use get text.
> >
> > 1. Build an action context by hand. (Too hard) 2. Use a class
> > rewriting mocking library. (Not on my watch) 3. Mock the get text
> > method. (Cheese) 4. Add another level of indirection. (Man
> thats just
> > annoying)
> >
> > Comments?
> >
> > BTW If you got this far, thanks for taking the time.
> > Paul B.
> >
> >
> >
> >
> > Session Mwamufiya wrote:
> >>
> >> Hi All,
> >>
> >> Would someone let me know whether it's possible to tweak
> something so
> >> that JUnit test code can run on an action method that calls the
> >> ActionSupport method getText() to fetch string resources from a
> >> package.properties file.
> >> As it stands, I keep getting a null exception when getText() is
> >> called during the unit test.
> >>
> >> Thanks,
> >> Session
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >> For additional commands, e-mail: user-help@(protected)
> >>
> >>
> >>
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p
> > 16467812.html Sent from the Struts - User mailing list archive at
> > Nabble.com.
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(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: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp1
3437046p16490696.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>

Attachment:
user_185063.ezm (zipped)Or look at the xwork / s2 test cases - there are some test classes in
there that can help you.
/Ian
Karr, David wrote:
> And did you investigate using either of the common Java frameworks for
> Mock objects, jMock and EasyMock?
>
>
>> -----Original Message-----
>> From: paulbrickell [mailto:paul.brickell@(protected)]
>> Sent: Friday, April 04, 2008 3:04 AM
>> To: user@(protected)
>> Subject: RE: any struts 2 unit testers out there?
>>
>>
>> Actually thats an interesting post. To my mind it doesn't
>> demonstrate a solution. It demonstrates the problem.
>>
>> Here is why I think this.
>>
>> Struts 2 is just frankly brilliant for people doing test
>> first development.
>> The classes you create really are POJOs. There are no
>> dependencies on any framework in my action classes. For
>> example parameters are parsed well away from my action and
>> the values are set using simple properties, things like
>> sessions are simply maps. It is a truly new world for those
>> of who have suffered the horror of mocking http requests,
>> responses, context and the like.
>>
>> But this simple scenario brings all that pain flooding back.
>> I add a line in my action like this...
>>
>> String yadaYada = getText("some.doodad");
>>
>> And my lovely world comes unraveled real quick. Now I need
>> mock objects up the ying-yang.
>>
>> I started using the tutorial from the link posted (I am an
>> Arsenal fan btw, so got two for the price of one, thanks),
>> but it still doesn't provide a simple solution to the
>> problem. To get this to work I have to build not just the
>> application context but a mass of supporting objects to get a
>> (partial) web application framework up and running before I
>> can test my simple POJO.
>>
>> I am not going to give up just yet, but I think I am still
>> going to have to look for another way.
>>
>> Cheers,
>> Paul B.
>>
>>
>>
>>
>> Relph,Brian wrote:
>>
>>> I recommend creating an action context. Here is the basic guide I
>>> followed to do so:
>>>
>>>
>>>
>> http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-
>>
>>> junit/
>>>
>>> If you are not using spring or the struts2 spring plugin,
>>>
>> you can cut
>>
>>> out all the code around the applicationContext.
>>>
>>>
>>> -----Original Message-----
>>> From: paulbrickell [mailto:paul.brickell@(protected)]
>>> Sent: Thursday, April 03, 2008 11:44 AM
>>> To: user@(protected)
>>> Subject: Re: any struts 2 unit testers out there?
>>>
>>>
>>> I am trying to deal with the same issue. Did you get any resolution?
>>>
>>> Following on from the reply asking for a stack trace, here
>>>
>> is what I
>>
>>> am getting...
>>>
>>>
>>>
java.lang.NullPointerException>>> at
>>>
>>>
>>
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(Locali
>> zedTextUtil.java:299)
>>
>>> at
>>>
>>>
>>
com.opensymphony.xwork2.TextProviderSupport.getText(TextProvid
>> erSupport.java:172)
>>
>>> at
>>>
>>>
>>
com.opensymphony.xwork2.TextProviderSupport.getText(TextProvid
>> erSupport.java:87)
>>
>>> at
>>>
>>
com.opensymphony.xwork2.ActionSupport.getText (
ActionSupport.java:80)
>>
>>> <SNIP>
>>> at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>>
>>>
>>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
>> orImpl.java:39)
>>
>>> at
>>>
>>>
>>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
>> odAccessorImpl.java:25)
>>
>>> at
java.lang.reflect.Method.invoke (
Method.java:585)
>>> at
>>>
>> org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRo
>> adie.java:98)
>>
>>> at
>>>
>> org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThen
>> Afters(MethodRoadie.java:87)
>>
>>> at
>>>
>> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>>
>>> at
>>>
>> org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(
>> JUnit4ClassRunner.java:88)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4
>> ClassRunner.java:51)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4Class
>>
> Runner.java:44)
>
>>> at
>>>
>>>
>> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoa
>> die.java:27)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadi
>> e.java:37)
>>
>>> at
>>>
>>>
>> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRu
>> nner.java:42)
>>
>>> at
>>>
>>>
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
>> (JUnit4TestReference.java:38)
>>
>>> at
>>>
>>>
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestEx
>> ecution.java:38)
>>
>>> at
>>>
>>>
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTest>> s(RemoteTestRunner.java:460)
>>
>>> at
>>>
>>>
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTest>> s(RemoteTestRunner.java:673)
>>
>>> at
>>>
>>>
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Rem
>> oteTestRunner.java:386)
>>
>>> at
>>>
>>>
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTest
>>
>>> Runner.java:196)
>>>
>>>
>>> It is caused by ActionContext.getContext() returning null. Quite
>>> obviously I do not have an action context during my unit testing.
>>>
>>> Now I can certainly use the ActionContext.setContext() in my tests
>>> setup method to push one into thread local storage and that
>>>
>> works OK.
>>
>>> It isn't ideal though because ActionContext is a concrete
>>>
>> class and so
>>
>>> my choices then become a bit limited.
>>>
>>> I could create an instance but when I try this I find I
>>>
>> have to create
>>
>>> a rather large object model to make it actually work. To the point
>>> where I despair and give up.
>>>
>>> Alternatively I could use a mock library (like easy mock). But I am
>>> not inclined to include a mocking library that requires byte code
>>> rewriting (not even for testing).
>>>
>>> What I really want to do is inject a text provider into the
>>> ActionSupport class. At the top of the ActionSupport class
>>>
>> is this...
>>
>>> private final transient TextProvider textProvider = new
>>> TextProviderFactory().createInstance(getClass(), this);
>>>
>>> Damn its final and so I cannot inject my own text provider.
>>>
>>> BUT it uses a factory, thats good. I know I will have a look at the
>>> factory I bet I can monkey with that and inject a mock.
>>>
>> Nope. It's all
>>
>>> instance based. No way I can get in there. And thats that.
>>>
>> Now what do
>>
>>> I do?
>>>
>>> I can see two (half) workable solutions.
>>>
>>> One is to override the the getText method in the action
>>>
>> class when I
>>
>>> instantiate it during testing. So I end up doing this in
>>>
>> all my action
>>
>>> unit tests...
>>>
>>> Action action = new MyAction()
>>> {
>>> @Override
>>> public String getText(String textName)
>>> {
>>> return "mocked";
>>> }
>>> };
>>>
>>> It works, but its cheese.
>>>
>>> Or two I can add a level of indirection in my action class,
>>>
>> like so...
>>
>>> String text =
>>>
>>>
>> MyTextProviderFactory.getInstance(class.name).getText("some.property")
>>
>>> ;
>>>
>>> Then I can use a delegate to the real text provider during
>>>
>> live code
>>
>>> and a mock of my own text provider during testing. The
>>>
>> question here
>>
>>> is, Why for the love of Pete, why?
>>>
>>> So in conclusion there are at least four options for testing Action
>>> classes that use get text.
>>>
>>> 1. Build an action context by hand. (Too hard) 2. Use a class
>>> rewriting mocking library. (Not on my watch) 3. Mock the get text
>>> method. (Cheese) 4. Add another level of indirection. (Man
>>>
>> thats just
>>
>>> annoying)
>>>
>>> Comments?
>>>
>>> BTW If you got this far, thanks for taking the time.
>>> Paul B.
>>>
>>>
>>>
>>>
>>> Session Mwamufiya wrote:
>>>
>>>> Hi All,
>>>>
>>>> Would someone let me know whether it's possible to tweak
>>>>
>> something so
>>
>>>> that JUnit test code can run on an action method that calls the
>>>> ActionSupport method getText() to fetch string resources from a
>>>> package.properties file.
>>>> As it stands, I keep getting a null exception when getText() is
>>>> called during the unit test.
>>>>
>>>> Thanks,
>>>> Session
>>>>
>>>>
>>>>
>>>>
>> ---------------------------------------------------------------------
>>
>>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>>> For additional commands, e-mail: user-help@(protected)
>>>>
>>>>
>>>>
>>>>
>>> --
>>> View this message in context:
>>>
>>>
>> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p
>>
>>> 16467812.html Sent from the Struts - User mailing list archive at
>>> Nabble.com.
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(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: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>>>
>> --
>> View this message in context:
>> http://www.nabble.com/any-struts-2-unit-testers-out-there--tp1
>>
> 3437046p16490696.html
>
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_185059.ezm (zipped)While outward facing web application get the most publicity, I know
that most of us are heads-down on internally-facing applications
designed for fellow employees to use over the corporate intranet.
I'm trying to put together a list of the typical types of applications
that enterprise developer write in real life. For example, my last
project involved a system to track drafting, granting, monitoring, and
enforcing water permits administered by a government agency. We would
create an initial record for a permit, and then add child records to
track progress through the workflow, and also update the master record
along the way. For management, a key item here is a tracking report,
which we exported to Word (using a third-party tool) for better
formatting. For engineers, a key item was a flexible search system to
quickly find a master or child record. Other interesting features are
workflows where one task leads to another. When we completed one task
(child record), the next is often implied, and so we had a workflow
that would default the next task to work on when a current task was
closed. Another interesting requirement was that sometimes master
items were merged under another uber-master-item, becoming, in effect,
child items themselves. In most cases, the application simply exposed
business models that we designed into the database, so the application
has little business logic of its own. Most of the workflows were
designed to find, list, edit, or view one database entity or the
other.
So, if anyone else is up for sharing, I'd be interested in hearing
what sort of things other people are doing these days. (If your not
comfortable posting the list, feel free to mail me direct.)
-Ted.

Attachment:
user_185060.ezm (zipped)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@(protected),
>> 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@(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.

Attachment:
user_185061.ezm (zipped)
It has definitely solved a big problem. Now, i can show the correct data of
two tabs, submit them and have correct results. Actually, my case is very
simple, as i told you that the two tabs will not be related, so, each tab
will be submitted independently without needing each others data because
there is no common data. So, everything is fine. EXCEPT.....
If i submit one tab the page submits and as a result of this the other tabs'
data is lost. By lost i mean that the changes i made in other tabs are reset
because the page is submitted. I am still unable to find out how to make
each tab ajax based. Here is my jsp code.
<s:url var="test1" value="demo/DefaultAllowanceDetailsAction.action"/>
<s:url var="test2" value="demo/LibraryFormDefaultAction.action"/>
<sx:tabbedpanel id="tabbedPanel" useSelectedTabCookie="true">
<sx:div id="div1" label="Allowance Details" href="%{test1}"
refreshOnShow="false" preload="true">
<s:action name="demo/DefaultAllowanceDetailsAction.action"
executeResult="true" />
</sx:div>
<sx:div id="div2" label="Library Form" href="%{test2}"
refreshOnShow="false" preload="true">
<s:action name="demo/LibraryFormDefaultAction.action"
executeResult="true" />
</sx:div >
</sx:tabbedpanel>
I have put false in refreshOnShow attribute so the tab is not refreshed once
it gets selected. What i want is to maintain the history of the changes made
to other tabs which were not submitted.
Thanks,
Shoaib Ahmad Gauhar
Shoaib Gauhar wrote:
>
> Hello,
>
> Here is the scenrio. I have two action classes. ClassA and ClassB. There
> is no relationship among these classes. You might say that if there is no
> relationship then why i have to put them in one single jsp. Well its a
> client's requirement.
>
> In a single jsp there are two tabs. Tab1ForClassA and Tab2ForClassB.
>
> Each tab has fields concerned to their classes as defined above. Tab1 ->
> ClassA and Tab2 -> ClassB.
>
> Can we do it? I have tried this but what happens is that when i submit the
> data on Tab1, Tab2's data becomes empty.
>
> So, any ideas will be highly appreciated. Furthermore, i am quite new to
> tabbed panel and would require clear tips and ideas.
>
> Thanks in advance,
>
> Shoaib Ahmad Gauhar
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.