You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ezgi <ez...@hotmail.com> on 2008/06/26 13:41:26 UTC

jUnit Testing Problem with Tiles

I want to test an action with jUnit. I have found a way to test Struts2 from
http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit 
this  tutorial. I set the configuration file to struts.xml file. It works as
expected if I do not include tiles. 
My test class extends BaseStrutsTestCase, and the place where I set the
configuration file is 
private static final String CONFIG_LOCATIONS = "file:src/struts.xml" ;


------------struts.xml ----------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

<package name="pack" namespace = "/" extends="struts-default">

 	
 	<result-types>
  		<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
	</result-types>
	
	<action name="Name">
           <result  type="tiles"> tvq.NameCollector </result>
        </action>

	<action name="HelloWorld"   class = "pack.HelloWorld">
            <result name = "SUCCESS"  type="tiles" >tvq.ListTasks</result>
            
             <result name = "ERROR"  >/error.jsp</result> 
            
        </action>
    <action name="AddTask">
    	<result  type="tiles"> tvq.addTask</result>
    	</action>


    </package>
 
</struts>


If I include the tiles part in struts.xml, it gives a NullPointerException :

java.lang.NullPointerException
	at
org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
	at
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
	at
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:355)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:259)
	at
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:141)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:248)
	at
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:49)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:124)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:170)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:170)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:104)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:84)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:208)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:88)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:130)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:137)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:130)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
	at
com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
	at
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
	at
com.opensymphony.xwork2.DefaultActionProxy.execute(DefaultActionProxy.java:130)
	at pack.HelloWorldTest.testHelloWorldAction(HelloWorldTest.java:38)
	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:597)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:228)
	at junit.framework.TestSuite.run(TestSuite.java:223)
	at
org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
	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)

If you look at the tutorial I refer, you can understand that I am not the
only one who have this problem. I try to set the configuration file to
tiles.defs.xml  as suggested, but it gave an XML parse exception. What can
be the solution;?

Thanks
jUnit newbie Ezgi :)

-- 
View this message in context: http://www.nabble.com/jUnit-Testing-Problem-with-Tiles-tp18131822p18131822.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: [OT] Re: jUnit Testing Problem with Tiles

Posted by Al Sutton <al...@alsutton.com>.
At least they made it to the tournament :(

Dave Newton wrote:
> --- On Thu, 6/26/08, Antonio Petrelli <an...@gmail.com> wrote:
>   
>> Eh? I know I am supposed to laugh, but since I am Italian
>> could you explain it a little ;-)
>>     
>
> Or cry; Spain whupped ya' 4-2.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   


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


[OT] Re: jUnit Testing Problem with Tiles

Posted by Dave Newton <ne...@yahoo.com>.
--- On Thu, 6/26/08, Antonio Petrelli <an...@gmail.com> wrote:
> Eh? I know I am supposed to laugh, but since I am Italian
> could you explain it a little ;-)

Or cry; Spain whupped ya' 4-2.

Dave


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


Re: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 Dave Newton <ne...@yahoo.com>:
> --- On Thu, 6/26/08, Antonio Petrelli <an...@gmail.com> wrote:
>> The problem is that you are using StrutsTilesListener (that
>> loads /WEB-INF/tiles.xml by default), TilesServlet and
>> TilesFilter at the same time.
>
> Two is one, one is none! Three is... three is right out.
>
> You're just mad because of that whole Spain thing.

Eh? I know I am supposed to laugh, but since I am Italian could you
explain it a little ;-)

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by Dave Newton <ne...@yahoo.com>.
--- On Thu, 6/26/08, Antonio Petrelli <an...@gmail.com> wrote:
> The problem is that you are using StrutsTilesListener (that
> loads /WEB-INF/tiles.xml by default), TilesServlet and
> TilesFilter at the same time.

Two is one, one is none! Three is... three is right out.

You're just mad because of that whole Spain thing.

Dave


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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
Thank you very much, but they also seem not to find the solution.

Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>>
>> How can I initialize tiles in this context?
> 
> In some ways, you have to manage to put StrutsTilesListener, or at
> least its code, but I don't really know how to do it.
> I suggest to ask the BaseStrutsTestCase developers.
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18134225.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
>
> How can I initialize tiles in this context?

In some ways, you have to manage to put StrutsTilesListener, or at
least its code, but I don't really know how to do it.
I suggest to ask the BaseStrutsTestCase developers.

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
How can I initialize tiles in this context? 

Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>> If you look at the link, you can understand the problem. Whose
>> initialization is the one that you can't understand?
> 
> I see, but I am sorry, without initialization Tiles won't work.
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18133946.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> If you look at the link, you can understand the problem. Whose
> initialization is the one that you can't understand?

I see, but I am sorry, without initialization Tiles won't work.

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
This is the action class:
public class HelloWorldTest extends BaseStrutsTestCase {
	
	HelloWorld	hello;
	Map testSession;
	@Before
	public void setUp() throws Exception {
		super.setUp();
	       hello = createAction( HelloWorld.class, "/","HelloWorld" );
		testSession = new HashMap();
		testSession.put("username", "admin");
		testSession.put("password", "sifre");
		proxy.getInvocation().getInvocationContext().setParameters(testSession);
		
	}

	@Test
	public void testHelloWorldAction() throws Exception {
		
		
		assertTrue("SUCCESS".equals(proxy.execute())); 
		
	}

If you look at the link, you can understand the problem. Whose
initialization is the one that you can't understand?

Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>>
>> In my action, I have a reference to Http request and it requires to
>> access
>> the HttpServletRequest object, so I can not easily test the action with
>> just
>> calling the execute method and comparing the result. So, I have found out
>> a
>> solution from the link that I refere before, I did not write the
>> BaseStrutsTestCase, I modified the class. It creates mock objects and
>> helps
>> to test my action outside of the server environment. It takes the
>> advantage
>> of the  ActionProxy. All I did was to simulate some user input, and
>> remaining part is handled by this helper class.
> 
> And the initialization? I still cannot understand.
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18133751.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
>
> In my action, I have a reference to Http request and it requires to access
> the HttpServletRequest object, so I can not easily test the action with just
> calling the execute method and comparing the result. So, I have found out a
> solution from the link that I refere before, I did not write the
> BaseStrutsTestCase, I modified the class. It creates mock objects and helps
> to test my action outside of the server environment. It takes the advantage
> of the  ActionProxy. All I did was to simulate some user input, and
> remaining part is handled by this helper class.

And the initialization? I still cannot understand.

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
In my action, I have a reference to Http request and it requires to access
the HttpServletRequest object, so I can not easily test the action with just
calling the execute method and comparing the result. So, I have found out a
solution from the link that I refere before, I did not write the
BaseStrutsTestCase, I modified the class. It creates mock objects and helps
to test my action outside of the server environment. It takes the advantage
of the  ActionProxy. All I did was to simulate some user input, and
remaining part is handled by this helper class.


Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>> If I add the location of web.xml or any other thing to here
>> private static final String CONFIG_LOCATIONS = "file:src/struts.xml" ;
>> I got a parsing error. I am not very experienced with tiles, I just test
>> the
>> code in a big project. The problem is , if I do not include tiles, my
>> unit
>> test works perfectly. If you did not look at the BaseStrutsTEstCase
>> class,
>> it is a helper class to create an artificial environment for requests and
>> interceptors. May be my problem is related to the jUnit part, but why I
>> can't test with tiles?
> 
> Just one question: how are you configuring the "artificial environment"?
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18133546.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> If I add the location of web.xml or any other thing to here
> private static final String CONFIG_LOCATIONS = "file:src/struts.xml" ;
> I got a parsing error. I am not very experienced with tiles, I just test the
> code in a big project. The problem is , if I do not include tiles, my unit
> test works perfectly. If you did not look at the BaseStrutsTEstCase class,
> it is a helper class to create an artificial environment for requests and
> interceptors. May be my problem is related to the jUnit part, but why I
> can't test with tiles?

Just one question: how are you configuring the "artificial environment"?

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
If I add the location of web.xml or any other thing to here  
private static final String CONFIG_LOCATIONS = "file:src/struts.xml" ;
I got a parsing error. I am not very experienced with tiles, I just test the
code in a big project. The problem is , if I do not include tiles, my unit
test works perfectly. If you did not look at the BaseStrutsTEstCase class,
it is a helper class to create an artificial environment for requests and
interceptors. May be my problem is related to the jUnit part, but why I
can't test with tiles?


Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>> I have just replaced the code with the new one, isn't it the one you
>> suggested?
> 
> Yes, but you had to adapt it to your needs.
> By the way, do you still receive a parsing error, at startup?
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18133212.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> I have just replaced the code with the new one, isn't it the one you
> suggested?

Yes, but you had to adapt it to your needs.
By the way, do you still receive a parsing error, at startup?

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
I have loaded the Tiles listener and run the jUnit test and it gave the same
NullPointer Exception. Moreover, the trace is same as before.
Then, I tried to load tiles servlet, and it gave the same error. Lastly, I
loaded the tiles filter and it gave ther same NPE. 
I have already tried three of them so I can't figure out what the problem
is. Did I load them wrongly?

I have just replaced the code with the new one, isn't it the one you
suggested? 

Modified web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>TVQ</display-name>


	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.FilterDispatcher
		</filter-class>
	</filter>
	<!-- Add the filter mapping after all filters -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>


	<listener>
		<listener-class>
			org.apache.tiles.web.startup.TilesListener
		</listener-class>
	</listener>

		<context-param>
			<param-name>
				org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
			</param-name>
			<param-value>
				/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
			</param-value>
		</context-param>

	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>


Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>> I tried three of them seperatley, but it did not work.
> 
> Please clarify, what do you mean with "it did not work"? Do you
> receive an exception at startup?
> 
>> Should I modify the configuration variable in the BaseStrutsTestCase? I
>> did not add there
>> web.xml and tiles-defs.xml.
> 
> Sincerely I am not into BaseStrutsTestCase, so I cannot help in this case
> 
>>                        <param-value>
>>                               
>> /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
>>                        </param-value>
> 
> Have you got a "classpath-defs.xml" anywhere in your code? If not, remove
> it.
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18132968.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> I tried three of them seperatley, but it did not work.

Please clarify, what do you mean with "it did not work"? Do you
receive an exception at startup?

> Should I modify the configuration variable in the BaseStrutsTestCase? I did not add there
> web.xml and tiles-defs.xml.

Sincerely I am not into BaseStrutsTestCase, so I cannot help in this case

>                        <param-value>
>                                /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
>                        </param-value>

Have you got a "classpath-defs.xml" anywhere in your code? If not, remove it.

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
I tried three of them seperatley, but it did not work. Should I modify the
configuration variable in the BaseStrutsTestCase? I did not add there
web.xml and tiles-defs.xml.
As you suggested, I add this code into web.xml.

<listener>
		<listener-class>
			org.apache.tiles.web.startup.TilesListener
		</listener-class>
	</listener>

		<context-param>
			<param-name>
				org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
			</param-name>
			<param-value>
				/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
			</param-value>
		</context-param>


Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>>
>> This is the tiles.defs.xml :
>>        <listener>
>>                <listener-class>
>>                        org.apache.struts2.tiles.StrutsTilesListener
>>                </listener-class>
>>        </listener>
>>
>>        <servlet>
>>                <servlet-name>tiles</servlet-name>
>>                <servlet-class>
>>                        org.apache.tiles.web.startup.TilesServlet
>>                </servlet-class>
>>                <init-param>
>>                        <param-name>
>>                               
>> org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
>>                        </param-name>
>>                        <param-value>
>>                                /WEB-INF/tiles-defs.xml
>>                        </param-value>
>>                </init-param>
>>                <load-on-startup>2</load-on-startup>
>>        </servlet>
>>
>>
>>        <filter>
>>                <filter-name>Tiles_Filter</filter-name>
>>                <filter-class>
>>                        org.apache.tiles.web.startup.TilesFilter
>>                </filter-class>
>>                <init-param>
>>                        <param-name>
>>                               
>> org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
>>                        </param-name>
>>                        <param-value>
>>                                /WEB-INF/tiles-defs.xml
>>                        </param-value>
>>                </init-param>
>>        </filter>
>>
>>        <filter-mapping>
>>                <filter-name>Tiles_Filter</filter-name>
>>                <url-pattern>/*</url-pattern>
>>                <dispatcher>REQUEST</dispatcher>
>>        </filter-mapping>
> 
> The problem is that you are using StrutsTilesListener (that loads
> /WEB-INF/tiles.xml by default), TilesServlet and TilesFilter at the
> same time.
> Choose one and configure it. I suggest to use StrutsTilesListener
> only. Configuring it means putting a context parameter. See:
> http://tiles.apache.org/tutorial/configuration.html
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18132646.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
>
> This is the tiles.defs.xml :
>        <listener>
>                <listener-class>
>                        org.apache.struts2.tiles.StrutsTilesListener
>                </listener-class>
>        </listener>
>
>        <servlet>
>                <servlet-name>tiles</servlet-name>
>                <servlet-class>
>                        org.apache.tiles.web.startup.TilesServlet
>                </servlet-class>
>                <init-param>
>                        <param-name>
>                                org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
>                        </param-name>
>                        <param-value>
>                                /WEB-INF/tiles-defs.xml
>                        </param-value>
>                </init-param>
>                <load-on-startup>2</load-on-startup>
>        </servlet>
>
>
>        <filter>
>                <filter-name>Tiles_Filter</filter-name>
>                <filter-class>
>                        org.apache.tiles.web.startup.TilesFilter
>                </filter-class>
>                <init-param>
>                        <param-name>
>                                org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
>                        </param-name>
>                        <param-value>
>                                /WEB-INF/tiles-defs.xml
>                        </param-value>
>                </init-param>
>        </filter>
>
>        <filter-mapping>
>                <filter-name>Tiles_Filter</filter-name>
>                <url-pattern>/*</url-pattern>
>                <dispatcher>REQUEST</dispatcher>
>        </filter-mapping>

The problem is that you are using StrutsTilesListener (that loads
/WEB-INF/tiles.xml by default), TilesServlet and TilesFilter at the
same time.
Choose one and configure it. I suggest to use StrutsTilesListener
only. Configuring it means putting a context parameter. See:
http://tiles.apache.org/tutorial/configuration.html

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by ezgi <ez...@hotmail.com>.
This is the tiles.defs.xml :


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

	<definition name="tvq.template.default"	template="/layouts/default.jsp">
		<put-attribute name="title" value="Tiles tutorial homepage" />
		<put-attribute name="header" value="/tiles/header.jsp" />
		<put-attribute name="menu" value="/tiles/menu.jsp" />
		<put-attribute name="content" value="/tiles/content.jsp" />
		<put-attribute name="footer" value="/tiles/footer.jsp" />
	</definition>

	<definition name="tvq.ListTasks" extends="tvq.template.default">
		<put-attribute name="title" value="List Tasks" />
		<put-attribute name="content" value="/jsp/task/ListTasks.jsp" />
	</definition>
	
	<definition name="tvq.addTask" extends="tvq.template.default">
		<put-attribute name="title" value="Add a Task" />
		<put-attribute name="content" value="/jsp/task/addTask.jsp" />
	</definition>

</tiles-definitions>



and this is the web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>TVQ</display-name>

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.FilterDispatcher
		</filter-class>
	</filter>
	<!-- Add the filter mapping after all filters -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>




	<listener>
		<listener-class>
			org.apache.struts2.tiles.StrutsTilesListener
		</listener-class>
	</listener>

	<servlet>
		<servlet-name>tiles</servlet-name>
		<servlet-class>
			org.apache.tiles.web.startup.TilesServlet
		</servlet-class>
		<init-param>
			<param-name>
				org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
			</param-name>
			<param-value>
				/WEB-INF/tiles-defs.xml
			</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>


	<filter>
		<filter-name>Tiles_Filter</filter-name>
		<filter-class>
			org.apache.tiles.web.startup.TilesFilter
		</filter-class>
		<init-param>
			<param-name>
				org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
			</param-name>
			<param-value>
				/WEB-INF/tiles-defs.xml
			</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>Tiles_Filter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
	</filter-mapping>
	

	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>


Antonio Petrelli-3 wrote:
> 
> 2008/6/26 ezgi <ez...@hotmail.com>:
>> If you look at the tutorial I refer, you can understand that I am not the
>> only one who have this problem. I try to set the configuration file to
>> tiles.defs.xml  as suggested, but it gave an XML parse exception.
> 
> Can we see the Tiles definition files that you are using?
> 
> Antonio
> 
> ---------------------------------------------------------------------
> 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/jUnit-Testing-Problem-with-Tiles-tp18131822p18132170.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: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> If you look at the tutorial I refer, you can understand that I am not the
> only one who have this problem. I try to set the configuration file to
> tiles.defs.xml  as suggested, but it gave an XML parse exception.

Can we see the Tiles definition files that you are using?

Antonio

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


Re: jUnit Testing Problem with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2008/6/26 ezgi <ez...@hotmail.com>:
> If I include the tiles part in struts.xml, it gives a NullPointerException :

Did you add the StrutsTilesListener in your web.xml?
http://cwiki.apache.org/confluence/display/WW/Tiles+Plugin
Did you configure Tiles correctly?

Antonio

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