You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Milan Milanovic <mi...@yahoo.com> on 2008/12/16 18:19:15 UTC

[S2] Problem with testing S2 Action when JasperResult type is used

Hi,

I have defined a following Struts 2 action which show one simple PDF report: 

<action name="showReport" method="showReport" class="ReportAction">
	      	<result name="success" type="jasper">
                    /reports/MainReport.jasper
	            parameters
	            connection
	            PDF
	        </result>
</action>

And I'm trying to test with JUnit 4 this action by using BaseStrutsTestCase
class (
http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
). But I have a problem because JasperReportsResult is trying to find
location of my report by using finalLocation parameter of its doExecute(...)
method. The problem is that this file is not found during test, while, when
application is running on server IT IS found. So, how can I solve this
problem, i.e., how to pass correct location to doExecute method of
JasperReportsResult during Junit test, or maybe I can pass this somehow ?

--
Thx, M.
-- 
View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21037498.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
I've never used that base test class, but usually when I write a unit
test for a Struts action, I isolate everything around and just verify
the result string of the method executed ("success", "error", "input"
etc). The test never executes the result.

Nils-H

On Wed, Dec 17, 2008 at 6:07 PM, Milan Milanovic
<mi...@yahoo.com> wrote:
>
> I'm not sure too, just because of that I'm asking you this :-).
>
>
> Paweł Wielgus wrote:
>>
>> Then You definitively should read the servlet specs,
>> i'm not sure if servletContext is present or real under junit - is it?
>>
>> Best greetings,
>> Paweł Wielgus.
>>
>> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>>
>>> No, I'm runing test from my Eclipse 3.3 environment (right click to class
>>> ->
>>> Run As -> JUnit 4 test).
>>>
>>>
>>> Paweł Wielgus wrote:
>>>>
>>>> Hi Milan,
>>>> are You running your app from war file?
>>>> If yes, servletContext.getRealPath(...) might not work,
>>>> if i remember it correct, it is in servlet specification.
>>>>
>>>> Best greetings,
>>>> Paweł Wielgus.
>>>>
>>>> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>>>>
>>>>> I tried to set location programatically, and from my test I tried to
>>>>> set
>>>>> different paths, e.g.: "WebContent/reports/" and
>>>>> "\\WebContet\\reports\\",
>>>>> but every time I get FileNotFoundException from
>>>>> servletContext.getRealPath(...) method.
>>>>>
>>>>>
>>>>> Milan Milanovic wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have defined a following Struts 2 action which show one simple PDF
>>>>>> report:
>>>>>>
>>>>>> <action name="showReport" method="showReport" class="ReportAction">
>>>>>>               <result name="success" type="jasper">
>>>>>>                     /reports/MainReport.jasper
>>>>>>                   parameters
>>>>>>                   connection
>>>>>>                   PDF
>>>>>>               </result>
>>>>>> </action>
>>>>>>
>>>>>> And I'm trying to test with JUnit 4 this action by using
>>>>>> BaseStrutsTestCase class (
>>>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>>>> ). But I have a problem because JasperReportsResult is trying to find
>>>>>> location of my report by using finalLocation parameter of its
>>>>>> doExecute(...) method. The problem is that this file is not found
>>>>>> during
>>>>>> test, while, when application is running on server IT IS found. So,
>>>>>> how
>>>>>> can I solve this problem, i.e., how to pass correct location to
>>>>>> doExecute
>>>>>> method of JasperReportsResult during Junit test, or maybe I can pass
>>>>>> this
>>>>>> somehow ?
>>>>>>
>>>>>> --
>>>>>> Thx, M.
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
>>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21056441.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21057142.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Milan Milanovic <mi...@yahoo.com>.
I'm not sure too, just because of that I'm asking you this :-).


Paweł Wielgus wrote:
> 
> Then You definitively should read the servlet specs,
> i'm not sure if servletContext is present or real under junit - is it?
> 
> Best greetings,
> Paweł Wielgus.
> 
> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>
>> No, I'm runing test from my Eclipse 3.3 environment (right click to class
>> ->
>> Run As -> JUnit 4 test).
>>
>>
>> Paweł Wielgus wrote:
>>>
>>> Hi Milan,
>>> are You running your app from war file?
>>> If yes, servletContext.getRealPath(...) might not work,
>>> if i remember it correct, it is in servlet specification.
>>>
>>> Best greetings,
>>> Paweł Wielgus.
>>>
>>> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>>>
>>>> I tried to set location programatically, and from my test I tried to
>>>> set
>>>> different paths, e.g.: "WebContent/reports/" and
>>>> "\\WebContet\\reports\\",
>>>> but every time I get FileNotFoundException from
>>>> servletContext.getRealPath(...) method.
>>>>
>>>>
>>>> Milan Milanovic wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I have defined a following Struts 2 action which show one simple PDF
>>>>> report:
>>>>>
>>>>> <action name="showReport" method="showReport" class="ReportAction">
>>>>>               <result name="success" type="jasper">
>>>>>                     /reports/MainReport.jasper
>>>>>                   parameters
>>>>>                   connection
>>>>>                   PDF
>>>>>               </result>
>>>>> </action>
>>>>>
>>>>> And I'm trying to test with JUnit 4 this action by using
>>>>> BaseStrutsTestCase class (
>>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>>> ). But I have a problem because JasperReportsResult is trying to find
>>>>> location of my report by using finalLocation parameter of its
>>>>> doExecute(...) method. The problem is that this file is not found
>>>>> during
>>>>> test, while, when application is running on server IT IS found. So,
>>>>> how
>>>>> can I solve this problem, i.e., how to pass correct location to
>>>>> doExecute
>>>>> method of JasperReportsResult during Junit test, or maybe I can pass
>>>>> this
>>>>> somehow ?
>>>>>
>>>>> --
>>>>> Thx, M.
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21056441.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21057142.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Paweł Wielgus <po...@gmail.com>.
Then You definitively should read the servlet specs,
i'm not sure if servletContext is present or real under junit - is it?

Best greetings,
Paweł Wielgus.

2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>
> No, I'm runing test from my Eclipse 3.3 environment (right click to class ->
> Run As -> JUnit 4 test).
>
>
> Paweł Wielgus wrote:
>>
>> Hi Milan,
>> are You running your app from war file?
>> If yes, servletContext.getRealPath(...) might not work,
>> if i remember it correct, it is in servlet specification.
>>
>> Best greetings,
>> Paweł Wielgus.
>>
>> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>>
>>> I tried to set location programatically, and from my test I tried to set
>>> different paths, e.g.: "WebContent/reports/" and
>>> "\\WebContet\\reports\\",
>>> but every time I get FileNotFoundException from
>>> servletContext.getRealPath(...) method.
>>>
>>>
>>> Milan Milanovic wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have defined a following Struts 2 action which show one simple PDF
>>>> report:
>>>>
>>>> <action name="showReport" method="showReport" class="ReportAction">
>>>>               <result name="success" type="jasper">
>>>>                     /reports/MainReport.jasper
>>>>                   parameters
>>>>                   connection
>>>>                   PDF
>>>>               </result>
>>>> </action>
>>>>
>>>> And I'm trying to test with JUnit 4 this action by using
>>>> BaseStrutsTestCase class (
>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>>> ). But I have a problem because JasperReportsResult is trying to find
>>>> location of my report by using finalLocation parameter of its
>>>> doExecute(...) method. The problem is that this file is not found during
>>>> test, while, when application is running on server IT IS found. So, how
>>>> can I solve this problem, i.e., how to pass correct location to
>>>> doExecute
>>>> method of JasperReportsResult during Junit test, or maybe I can pass
>>>> this
>>>> somehow ?
>>>>
>>>> --
>>>> Thx, M.
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21056441.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Milan Milanovic <mi...@yahoo.com>.
No, I'm runing test from my Eclipse 3.3 environment (right click to class ->
Run As -> JUnit 4 test).


Paweł Wielgus wrote:
> 
> Hi Milan,
> are You running your app from war file?
> If yes, servletContext.getRealPath(...) might not work,
> if i remember it correct, it is in servlet specification.
> 
> Best greetings,
> Paweł Wielgus.
> 
> 2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>>
>> I tried to set location programatically, and from my test I tried to set
>> different paths, e.g.: "WebContent/reports/" and
>> "\\WebContet\\reports\\",
>> but every time I get FileNotFoundException from
>> servletContext.getRealPath(...) method.
>>
>>
>> Milan Milanovic wrote:
>>>
>>> Hi,
>>>
>>> I have defined a following Struts 2 action which show one simple PDF
>>> report:
>>>
>>> <action name="showReport" method="showReport" class="ReportAction">
>>>               <result name="success" type="jasper">
>>>                     /reports/MainReport.jasper
>>>                   parameters
>>>                   connection
>>>                   PDF
>>>               </result>
>>> </action>
>>>
>>> And I'm trying to test with JUnit 4 this action by using
>>> BaseStrutsTestCase class (
>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>>> ). But I have a problem because JasperReportsResult is trying to find
>>> location of my report by using finalLocation parameter of its
>>> doExecute(...) method. The problem is that this file is not found during
>>> test, while, when application is running on server IT IS found. So, how
>>> can I solve this problem, i.e., how to pass correct location to
>>> doExecute
>>> method of JasperReportsResult during Junit test, or maybe I can pass
>>> this
>>> somehow ?
>>>
>>> --
>>> Thx, M.
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21056441.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Milan,
are You running your app from war file?
If yes, servletContext.getRealPath(...) might not work,
if i remember it correct, it is in servlet specification.

Best greetings,
Paweł Wielgus.

2008/12/17 Milan Milanovic <mi...@yahoo.com>:
>
> I tried to set location programatically, and from my test I tried to set
> different paths, e.g.: "WebContent/reports/" and "\\WebContet\\reports\\",
> but every time I get FileNotFoundException from
> servletContext.getRealPath(...) method.
>
>
> Milan Milanovic wrote:
>>
>> Hi,
>>
>> I have defined a following Struts 2 action which show one simple PDF
>> report:
>>
>> <action name="showReport" method="showReport" class="ReportAction">
>>               <result name="success" type="jasper">
>>                     /reports/MainReport.jasper
>>                   parameters
>>                   connection
>>                   PDF
>>               </result>
>> </action>
>>
>> And I'm trying to test with JUnit 4 this action by using
>> BaseStrutsTestCase class (
>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
>> ). But I have a problem because JasperReportsResult is trying to find
>> location of my report by using finalLocation parameter of its
>> doExecute(...) method. The problem is that this file is not found during
>> test, while, when application is running on server IT IS found. So, how
>> can I solve this problem, i.e., how to pass correct location to doExecute
>> method of JasperReportsResult during Junit test, or maybe I can pass this
>> somehow ?
>>
>> --
>> Thx, M.
>>
>
> --
> View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Problem with testing S2 Action when JasperResult type is used

Posted by Milan Milanovic <mi...@yahoo.com>.
I tried to set location programatically, and from my test I tried to set
different paths, e.g.: "WebContent/reports/" and "\\WebContet\\reports\\",
but every time I get FileNotFoundException from
servletContext.getRealPath(...) method.


Milan Milanovic wrote:
> 
> Hi,
> 
> I have defined a following Struts 2 action which show one simple PDF
> report: 
> 
> <action name="showReport" method="showReport" class="ReportAction">
> 	      	<result name="success" type="jasper">
>                     /reports/MainReport.jasper
> 	            parameters
> 	            connection
> 	            PDF
> 	        </result>
> </action>
> 
> And I'm trying to test with JUnit 4 this action by using
> BaseStrutsTestCase class (
> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
> http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
> ). But I have a problem because JasperReportsResult is trying to find
> location of my report by using finalLocation parameter of its
> doExecute(...) method. The problem is that this file is not found during
> test, while, when application is running on server IT IS found. So, how
> can I solve this problem, i.e., how to pass correct location to doExecute
> method of JasperReportsResult during Junit test, or maybe I can pass this
> somehow ?
> 
> --
> Thx, M.
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-with-testing-S2-Action-when-JasperResult-type-is-used-tp21037498p21054572.html
Sent from the Struts - User mailing list archive at Nabble.com.


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