Re: any struts 2 unit testers out there?

2009-06-12 Thread R. Duval

As simples as it may seem. Assuming you're creating an instance on your setUp
method, and just to make things funnier, using a facade mock which is
expected to be action constructor parameter, it would look like this:

...
Mockery mockContext = new Mockery();
SomeFacade someFacadeMock;
MyAction myAction;

@Before
public void setUp() throws Exception {
someFacadeMock = mockContext.mock(SomeFacade.class);
myAction = new MyAction(someFacadeMock) {
@Override
public String getText(String textName) {
return "dummy";
}
}
}
...

This way you can assume any calls to ActionSupport#getText(String) will
return dummy. You can even make some assertions on that (assuming you are
using it to set an action error), like:

...
assertTrue(myAction.getActionErrors.contains("dummy"));
...

By now you might have figured that, but worth the time to expose a possible
and simple solution.

Cya,


Adam Hardy (debian) wrote:
> 
> I am unit testing my MVC layer and looking for the best way to override
> ActionSupport.getText() cleanly and efficiently for testing purposes (from
> a developer time point of view).
> 
> Rather than reinventing the wheel, is there anything out there now that
> people are willing to share? (Did I miss it somewhere?)
> 
> Fortunately I already have my own Action subclass which inherits
> ActionSupport, so it shouldn't be too difficult to implement, but it would
> be nice to be able to sort out it quickly (in the background I hear the
> unmistakeable splat of another unforeseen coding session hitting the
> project time line...)
> 
> For anyone reading this msg in the archives, when I've got something
> (self-created or other) I'll see if I can put it up on the web somewhere -
> in the wiki or even in a msg here.
> 
> Regards
> Adam
> 

-- 
View this message in context: 
http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p24006147.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: any struts 2 unit testers out there?

2008-10-10 Thread Adam Hardy (struts)

I am unit testing my MVC layer and looking for the best way to override
ActionSupport.getText() cleanly and efficiently for testing purposes (from a
developer time point of view).

Rather than reinventing the wheel, is there anything out there now that
people are willing to share? (Did I miss it somewhere?)

Fortunately I already have my own Action subclass which inherits
ActionSupport, so it shouldn't be too difficult to implement, but it would
be nice to be able to sort out it quickly (in the background I hear the
unmistakeable splat of another unforeseen coding session hitting the project
time line...)

For anyone reading this msg in the archives, when I've got something
(self-created or other) I'll see if I can put it up on the web somewhere -
in the wiki or even in a msg here.

Regards
Adam



paulbrickell on 05/04/08 10:28, wrote:
>Yeah, I think for the moment I will simply override the getText method. The
other solutions do require
>much more effort.
>
>Actually I did not search Jira. Maybe there is already a request. I will
take a look.
>
>Thanks,
>
>Paul B.
>>
>>As Ian says, the mock objects supplied by XWork may make this all a lot 
>>easier, but in any case all this is predicated on the fact that you're 
>>using ActionSupport's implementation of TextProvider which doesn't make 
>>provision for mocking at test time. I think it would make a great deal 
>>of sense to improve that (open an enhancement request in Jira), but in 
>>the mean time, there's nothing preventing you from providing a getText() 
>>implementation that's more conducive to testing.
>>
>>I feel your pain on this one, and the right solution is to fix the 
>>framework (patches always welcome ;-), but it shouldn't be that hard to 
>>get around.
>>
>>L.
>>paulbrickell wrote:
>>> 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.
>>> 
>>> 
>>> 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:[EMAIL PROTECTED] 
>>>> Sent: Thursday, April 03, 2008 11:44 AM
>>>> To: user@struts.apache.org
>>>> 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.LocalizedTextUti

Re: any struts 2 unit testers out there?

2008-04-05 Thread paulbrickell

Yeah, I think for the moment I will simply override the getText method. The
other solutions do require much more effort.

Actually I did not search Jira. Maybe there is already a request. I will
take a look.

Thanks,

Paul B.


Laurie Harper wrote:
> 
> As Ian says, the mock objects supplied by XWork may make this all a lot 
> easier, but in any case all this is predicated on the fact that you're 
> using ActionSupport's implementation of TextProvider which doesn't make 
> provision for mocking at test time. I think it would make a great deal 
> of sense to improve that (open an enhancement request in Jira), but in 
> the mean time, there's nothing preventing you from providing a getText() 
> implementation that's more conducive to testing.
> 
> I feel your pain on this one, and the right solution is to fix the 
> framework (patches always welcome ;-), but it shouldn't be that hard to 
> get around.
> 
> L.
> 
> paulbrickell wrote:
>> 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:[EMAIL PROTECTED] 
>>> Sent: Thursday, April 03, 2008 11:44 AM
>>> To: user@struts.apache.org
>>> 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)
>>> 
>>> 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

RE: any struts 2 unit testers out there?

2008-04-05 Thread paulbrickell

Yes, I did discuss the pros and cons of them in this post
http://www.nabble.com/any-struts-2-unit-testers-out-there--to13437046.html#a16490696

Cheers,
Paul B.


dkarr wrote:
> 
> And did you investigate using either of the common Java frameworks for
> Mock objects, jMock and EasyMock? 
> 
>> -Original Message-
>> From: paulbrickell [mailto:[EMAIL PROTECTED] 
>> Sent: Friday, April 04, 2008 3:04 AM
>> To: user@struts.apache.org
>> 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:[EMAIL PROTECTED]
>> > Sent: Thursday, April 03, 2008 11:44 AM
>> > To: user@struts.apache.org
>> > 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)
>> > 
>> >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.M

Re: any struts 2 unit testers out there?

2008-04-04 Thread Laurie Harper
As Ian says, the mock objects supplied by XWork may make this all a lot 
easier, but in any case all this is predicated on the fact that you're 
using ActionSupport's implementation of TextProvider which doesn't make 
provision for mocking at test time. I think it would make a great deal 
of sense to improve that (open an enhancement request in Jira), but in 
the mean time, there's nothing preventing you from providing a getText() 
implementation that's more conducive to testing.


I feel your pain on this one, and the right solution is to fix the 
framework (patches always welcome ;-), but it shouldn't be that hard to 
get around.


L.

paulbrickell wrote:

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:[EMAIL PROTECTED] 
Sent: Thursday, April 03, 2008 11:44 AM

To: user@struts.apache.org
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)

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.Remote

Re: any struts 2 unit testers out there?

2008-04-04 Thread Ian Roughley
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:[EMAIL PROTECTED] 
Sent: Friday, April 04, 2008 3:04 AM

To: user@struts.apache.org
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:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2008 11:44 AM
To: user@struts.apache.org
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)



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:6

RE: any struts 2 unit testers out there?

2008-04-04 Thread Karr, David
And did you investigate using either of the common Java frameworks for
Mock objects, jMock and EasyMock? 

> -Original Message-
> From: paulbrickell [mailto:[EMAIL PROTECTED] 
> Sent: Friday, April 04, 2008 3:04 AM
> To: user@struts.apache.org
> 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:[EMAIL PROTECTED]
> > Sent: Thursday, April 03, 2008 11:44 AM
> > To: user@struts.apache.org
> > 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)
> > 
> > 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.int

RE: any struts 2 unit testers out there?

2008-04-04 Thread paulbrickell

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:[EMAIL PROTECTED] 
> Sent: Thursday, April 03, 2008 11:44 AM
> To: user@struts.apache.org
> 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)
> 
>   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 be

RE: any struts 2 unit testers out there?

2008-04-04 Thread paulbrickell

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:[EMAIL PROTECTED] 
> Sent: Thursday, April 03, 2008 11:44 AM
> To: user@struts.apache.org
> 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)
> 
>   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 be

RE: any struts 2 unit testers out there?

2008-04-03 Thread Relph,Brian

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:[EMAIL PROTECTED] 
Sent: Thursday, April 03, 2008 11:44 AM
To: user@struts.apache.org
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)

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

Re: any struts 2 unit testers out there?

2008-04-03 Thread paulbrickell
w 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: any struts 2 unit testers out there?

2007-10-29 Thread Ian Roughley
And 4 - have you looked in the source for unit tests testing this 
functionality?


Tom Schneider wrote:

My first suggestion is the make sure that the package.properties files are on
the classpath when you run your junit test.

Secondly, it would be helpful for us to help you figure this out if you post
the stack trace for the null pointer exception.

Third, you may want to debug into the getText() method so you can tell us
exactly where the framework is having problems.  Based on the information
you've provided, it's really hard to figure out where the problem is.  My
guess is it's somewhere in XWork, but without some more information, it's
hard to tell.  Webwork and Struts 2 are very JUnit friendly frameworks, so
I'm sure it's just a matter of configuration.
Tom


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






  


Re: any struts 2 unit testers out there?

2007-10-28 Thread Tom Schneider

My first suggestion is the make sure that the package.properties files are on
the classpath when you run your junit test.

Secondly, it would be helpful for us to help you figure this out if you post
the stack trace for the null pointer exception.

Third, you may want to debug into the getText() method so you can tell us
exactly where the framework is having problems.  Based on the information
you've provided, it's really hard to figure out where the problem is.  My
guess is it's somewhere in XWork, but without some more information, it's
hard to tell.  Webwork and Struts 2 are very JUnit friendly frameworks, so
I'm sure it's just a matter of configuration.
Tom


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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/any-struts-2-unit-testers-out-there--tf4700279.html#a13459997
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



any struts 2 unit testers out there?

2007-10-26 Thread Session A Mwamufiya
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]