You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Niklas Lindholm <ca...@nilin.se> on 2005/08/11 23:41:22 UTC

How to assert forwards?

Hi!

I am writing a web application that is using an MVC design. This means 
that at the end of almost every servlet I do a 

request.getRequestDispatcher("foo.jsp").forward(request, response)


I some cases the servlet makes a choice between two (or more) different 
targets to forward() to. Something like:

if(somethingIsTrue)
  request.getRequestDispatcher("foo.jsp").forward(request, response);
else
  request.getRequestDispatcher("bar.jsp").forward(request, response);

Is there a way to make a Cactus test case that asserts that the forward is 
being done to the correct target? I can't find any way to get information 
about what forward that has been done. (Except trying to find out by 
looking at the resulting HTML is endXXXX(), but that doesn't seem like a 
good idea..)

/Niklas

Re: ServletRedirector context

Posted by David Turley <sy...@synath.com>.
Pedro,

Thanks for the suggestion.  That will help a lot with some of the other 
issues I'm having.  It turns out that the problem was with my 
server.xml.  I shouldn't really say it's "my" server.xml because someone 
else wrote it, hence the problem, but I should have caught it much 
earlier.  They set the context docBase to a full path instead of a 
relative path, so it wasn't using the temp directory created by the 
cactus task.  The context.xml suggestion will be very helpful because 
most of my coworkers use Windows and I use Linux, so everything is in 
different places.

Thanks again for your help!
--David

Pedro Nevado wrote:

>David,
>
>I do not use server.xml for my datasource connection: you can define it in a
>context.xml file (ROOT.xml, p.e); so you do not need to change your
>server.xml, or work with an ad-hoc server.xml, either.
>
>The URL I use for see test results in my browser is something like:
>
>http://localhost:8080/mycontext/ServletTestRunner?suite=com.myclassactiontes
>t.
>
>In case you may find it useful, this is my ant script:
>
><!-- ======================================================= -->
>    <!-- TARGETS: RUN CACTUS TESTS                               -->
>    <!-- ======================================================= -->
>    <!-- ......... Cactus taskdef ............-->
>    <taskdef name="runservertests"
>classname="org.apache.cactus.integration.ant.RunServerTestsTask"
>             classpathref="cactus.tasks.path"/>
>
>    <target name="run_tests" depends="new_context">
>        <runservertests
>            testurl="${cactus.contextURL}"
>            starttarget="start.tomcat5"
>            stoptarget="stop.tomcat5"
>            testtarget="testCactus"/>
>    </target>
>
>    <target name="testCactus" depends="clean_reports">
>        <mkdir dir="${tests.reports.dir}"/>
>        <junit printsummary="false" haltonerror="false"
>haltonfailure="false"
>               fork="${junit.fork}"
>               errorproperty="test.failed"
>               failureproperty="test.failed"
>            >
>            <formatter type="plain" usefile="false" />
>            <formatter type="xml" />
>            <classpath>
>                <pathelement path="${web_comp.path}"/>
>                <pathelement location="${junit.jar}"/>
>                <pathelement location="${httpclient.jar}"/>
>                <pathelement location="${cactus.jar}"/>
>                <pathelement location="${cactus_ant.jar}"/>
>                <pathelement location="${aspectjrt.jar}"/>
>                <pathelement location="${httpunit.jar}"/>
>                <pathelement location="${nekohtml.jar}"/>
>                <pathelement location="${tidy.jar}"/>
>            </classpath>
>            <batchtest todir="${tests.reports.dir}" unless="testClass" >
>               <fileset dir="${tests.class.dir}"  includes="**/*Test.class"
>/>
>            </batchtest>
>        </junit>
>        <junitreport todir="${tests.reports.dir}">
>            <fileset dir="${tests.reports.dir}" includes="TEST-*.xml"/>
>            <report todir="${tests.reports.dir}/html" format="frames"/>
>        </junitreport>
>        <fail if="test.failed">At least one test failed after making
>report!</fail>
>    </target>
>
>    <target name="start.tomcat5">
>        <java classname="org.apache.catalina.startup.Bootstrap"
>            failonerror="yes" fork="true">
>            <jvmarg value="-Dcatalina.home=${env.CATALINA_HOME}"/>
>            <jvmarg value="-Dcatalina.base=${env.CATALINA_HOME}"/>
>            <arg value="-config"/>
>            <arg value="${env.CATALINA_HOME}/conf/server.xml"/>
>            <arg value="start"/>
>            <classpath>
>              <pathelement path="${java_comp.path}"/>
>              <fileset dir="${env.CATALINA_HOME}"
>includes="bin/bootstrap.jar"/>
>            </classpath>
>        </java>
>    </target>
>    <target name="stop.tomcat5">
>        <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
>            <jvmarg value="-Dcatalina.home=${env.CATALINA_HOME}"/>
>            <jvmarg value="-Dcatalina.base=${env.CATALINA_HOME}"/>
>            <arg value="-config"/>
>            <arg value="${env.CATALINA_HOME}/conf/server.xml"/>
>            <arg value="stop"/>
>            <classpath>
>              <pathelement path="${java_comp.path}"/>
>              <fileset dir="${env.CATALINA_HOME}">
>                  <include name="bin/bootstrap.jar"/>
>              </fileset>
>            </classpath>
>        </java>
>    </target>
>
>-----Mensaje original-----
>De: David Turley [mailto:synath@synath.com]
>Enviado el: martes, 16 de agosto de 2005 16:33
>Para: Cactus Users List
>Asunto: Re: ServletRedirector context
>
>
>Update:
>
>In the cactus ant task, I was specifying a server.xml file instead of
>using the default.  I did this because if I don't, I get the following
>complaint:
>
>   [cactus] java.lang.RuntimeException: Exception looking up data
>source: Name jdbc is not bound in this Context
>
>But then the test redirectors initialize correctly and everything.  It's
>as if I have a choice between my jdbc connection and the test
>redirectors working.  What do I need to do to get both to work?  By the
>way, where is the "default" server.xml located?  The server.xml I
>specify is in TOMCAT_HOME/conf/...  At first I thought that would be the
>default, but apparently not.
>
>Once again, any help on this would be appreciated.  The lack of help
>thusfar has been discouraging, but I understand that you all have your
>own lives and your own projects and don't give a rats behind about my
>project ;-).
>
>Thanks,
>David
>
>
>David Turley wrote:
>
>  
>
>>Correction:
>>"I have tried to browse to that location and I get 404'd.  If I browse
>>to
>>http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST,
>>however, I get a blank page. "  I meant when I browse to
>>http://localhost:8081/ServletRedirector?Cactus_Service=RUN_TEST, which
>>lacks the /app, which is the context my application runs under.
>>
>>David Turley wrote:
>>
>>    
>>
>>>More information about the problem:
>>>
>>>When trying to run the ant cactus task with ant debug mode on, after
>>>the Tomcat starts up, I get the following repeatedly until it times out.
>>>
>>>  [cactus] Checking if server is up ...
>>>  [cactus] Failed to connect to
>>>[http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST]
>>>(Connection refused)
>>>
>>>Then I get the timeout message:
>>>Failed to start the container after more than [180000] ms. Trying to
>>>connect to the
>>>[http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST]
>>>test URL yielded a [-1] error code. Please run in debug mode for more
>>>details about the error.
>>>
>>>I have tried to browse to that location and I get 404'd.  If I browse
>>>to
>>>http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST,
>>>however, I get a blank page.
>>>
>>>I turned on cactus logging but didn't see anything new about the error.
>>>
>>>Anyone have any clues for me?  Do you need more information to help
>>>me?  Let me know.
>>>
>>>Thanks,
>>>David Turley
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>  
>

RE: ServletRedirector context

Posted by Pedro Nevado <pn...@javato.com>.
David,

I do not use server.xml for my datasource connection: you can define it in a
context.xml file (ROOT.xml, p.e); so you do not need to change your
server.xml, or work with an ad-hoc server.xml, either.

The URL I use for see test results in my browser is something like:

http://localhost:8080/mycontext/ServletTestRunner?suite=com.myclassactiontes
t.

In case you may find it useful, this is my ant script:

<!-- ======================================================= -->
    <!-- TARGETS: RUN CACTUS TESTS                               -->
    <!-- ======================================================= -->
    <!-- ......... Cactus taskdef ............-->
    <taskdef name="runservertests"
classname="org.apache.cactus.integration.ant.RunServerTestsTask"
             classpathref="cactus.tasks.path"/>

    <target name="run_tests" depends="new_context">
        <runservertests
            testurl="${cactus.contextURL}"
            starttarget="start.tomcat5"
            stoptarget="stop.tomcat5"
            testtarget="testCactus"/>
    </target>

    <target name="testCactus" depends="clean_reports">
        <mkdir dir="${tests.reports.dir}"/>
        <junit printsummary="false" haltonerror="false"
haltonfailure="false"
               fork="${junit.fork}"
               errorproperty="test.failed"
               failureproperty="test.failed"
            >
            <formatter type="plain" usefile="false" />
            <formatter type="xml" />
            <classpath>
                <pathelement path="${web_comp.path}"/>
                <pathelement location="${junit.jar}"/>
                <pathelement location="${httpclient.jar}"/>
                <pathelement location="${cactus.jar}"/>
                <pathelement location="${cactus_ant.jar}"/>
                <pathelement location="${aspectjrt.jar}"/>
                <pathelement location="${httpunit.jar}"/>
                <pathelement location="${nekohtml.jar}"/>
                <pathelement location="${tidy.jar}"/>
            </classpath>
            <batchtest todir="${tests.reports.dir}" unless="testClass" >
               <fileset dir="${tests.class.dir}"  includes="**/*Test.class"
/>
            </batchtest>
        </junit>
        <junitreport todir="${tests.reports.dir}">
            <fileset dir="${tests.reports.dir}" includes="TEST-*.xml"/>
            <report todir="${tests.reports.dir}/html" format="frames"/>
        </junitreport>
        <fail if="test.failed">At least one test failed after making
report!</fail>
    </target>

    <target name="start.tomcat5">
        <java classname="org.apache.catalina.startup.Bootstrap"
            failonerror="yes" fork="true">
            <jvmarg value="-Dcatalina.home=${env.CATALINA_HOME}"/>
            <jvmarg value="-Dcatalina.base=${env.CATALINA_HOME}"/>
            <arg value="-config"/>
            <arg value="${env.CATALINA_HOME}/conf/server.xml"/>
            <arg value="start"/>
            <classpath>
              <pathelement path="${java_comp.path}"/>
              <fileset dir="${env.CATALINA_HOME}"
includes="bin/bootstrap.jar"/>
            </classpath>
        </java>
    </target>
    <target name="stop.tomcat5">
        <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
            <jvmarg value="-Dcatalina.home=${env.CATALINA_HOME}"/>
            <jvmarg value="-Dcatalina.base=${env.CATALINA_HOME}"/>
            <arg value="-config"/>
            <arg value="${env.CATALINA_HOME}/conf/server.xml"/>
            <arg value="stop"/>
            <classpath>
              <pathelement path="${java_comp.path}"/>
              <fileset dir="${env.CATALINA_HOME}">
                  <include name="bin/bootstrap.jar"/>
              </fileset>
            </classpath>
        </java>
    </target>

-----Mensaje original-----
De: David Turley [mailto:synath@synath.com]
Enviado el: martes, 16 de agosto de 2005 16:33
Para: Cactus Users List
Asunto: Re: ServletRedirector context


Update:

In the cactus ant task, I was specifying a server.xml file instead of
using the default.  I did this because if I don't, I get the following
complaint:

   [cactus] java.lang.RuntimeException: Exception looking up data
source: Name jdbc is not bound in this Context

But then the test redirectors initialize correctly and everything.  It's
as if I have a choice between my jdbc connection and the test
redirectors working.  What do I need to do to get both to work?  By the
way, where is the "default" server.xml located?  The server.xml I
specify is in TOMCAT_HOME/conf/...  At first I thought that would be the
default, but apparently not.

Once again, any help on this would be appreciated.  The lack of help
thusfar has been discouraging, but I understand that you all have your
own lives and your own projects and don't give a rats behind about my
project ;-).

Thanks,
David


David Turley wrote:

> Correction:
> "I have tried to browse to that location and I get 404'd.  If I browse
> to
> http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST,
> however, I get a blank page. "  I meant when I browse to
> http://localhost:8081/ServletRedirector?Cactus_Service=RUN_TEST, which
> lacks the /app, which is the context my application runs under.
>
> David Turley wrote:
>
>> More information about the problem:
>>
>> When trying to run the ant cactus task with ant debug mode on, after
>> the Tomcat starts up, I get the following repeatedly until it times out.
>>
>>   [cactus] Checking if server is up ...
>>   [cactus] Failed to connect to
>> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST]
>> (Connection refused)
>>
>> Then I get the timeout message:
>> Failed to start the container after more than [180000] ms. Trying to
>> connect to the
>> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST]
>> test URL yielded a [-1] error code. Please run in debug mode for more
>> details about the error.
>>
>> I have tried to browse to that location and I get 404'd.  If I browse
>> to
>> http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST,
>> however, I get a blank page.
>>
>> I turned on cactus logging but didn't see anything new about the error.
>>
>> Anyone have any clues for me?  Do you need more information to help
>> me?  Let me know.
>>
>> Thanks,
>> David Turley
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>

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




Re: ServletRedirector context

Posted by David Turley <sy...@synath.com>.
Update:

In the cactus ant task, I was specifying a server.xml file instead of 
using the default.  I did this because if I don't, I get the following 
complaint:

   [cactus] java.lang.RuntimeException: Exception looking up data 
source: Name jdbc is not bound in this Context

But then the test redirectors initialize correctly and everything.  It's 
as if I have a choice between my jdbc connection and the test 
redirectors working.  What do I need to do to get both to work?  By the 
way, where is the "default" server.xml located?  The server.xml I 
specify is in TOMCAT_HOME/conf/...  At first I thought that would be the 
default, but apparently not.

Once again, any help on this would be appreciated.  The lack of help 
thusfar has been discouraging, but I understand that you all have your 
own lives and your own projects and don't give a rats behind about my 
project ;-).

Thanks,
David


David Turley wrote:

> Correction:
> "I have tried to browse to that location and I get 404'd.  If I browse 
> to 
> http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST, 
> however, I get a blank page. "  I meant when I browse to 
> http://localhost:8081/ServletRedirector?Cactus_Service=RUN_TEST, which 
> lacks the /app, which is the context my application runs under.
>
> David Turley wrote:
>
>> More information about the problem:
>>
>> When trying to run the ant cactus task with ant debug mode on, after 
>> the Tomcat starts up, I get the following repeatedly until it times out.
>>
>>   [cactus] Checking if server is up ...
>>   [cactus] Failed to connect to 
>> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
>> (Connection refused)
>>
>> Then I get the timeout message:
>> Failed to start the container after more than [180000] ms. Trying to 
>> connect to the 
>> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
>> test URL yielded a [-1] error code. Please run in debug mode for more 
>> details about the error.
>>
>> I have tried to browse to that location and I get 404'd.  If I browse 
>> to 
>> http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST, 
>> however, I get a blank page.
>>
>> I turned on cactus logging but didn't see anything new about the error.
>>
>> Anyone have any clues for me?  Do you need more information to help 
>> me?  Let me know.
>>
>> Thanks,
>> David Turley
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>

Re: ServletRedirector context

Posted by David Turley <sy...@synath.com>.
Correction:
"I have tried to browse to that location and I get 404'd.  If I browse 
to http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST, 
however, I get a blank page. "  I meant when I browse to 
http://localhost:8081/ServletRedirector?Cactus_Service=RUN_TEST, which 
lacks the /app, which is the context my application runs under.

David Turley wrote:

> More information about the problem:
>
> When trying to run the ant cactus task with ant debug mode on, after 
> the Tomcat starts up, I get the following repeatedly until it times out.
>
>   [cactus] Checking if server is up ...
>   [cactus] Failed to connect to 
> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
> (Connection refused)
>
> Then I get the timeout message:
> Failed to start the container after more than [180000] ms. Trying to 
> connect to the 
> [http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
> test URL yielded a [-1] error code. Please run in debug mode for more 
> details about the error.
>
> I have tried to browse to that location and I get 404'd.  If I browse 
> to 
> http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST, 
> however, I get a blank page.
>
> I turned on cactus logging but didn't see anything new about the error.
>
> Anyone have any clues for me?  Do you need more information to help 
> me?  Let me know.
>
> Thanks,
> David Turley
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>

Re: ServletRedirector context

Posted by David Turley <sy...@synath.com>.
More information about the problem:

When trying to run the ant cactus task with ant debug mode on, after the 
Tomcat starts up, I get the following repeatedly until it times out.

   [cactus] Checking if server is up ...
   [cactus] Failed to connect to 
[http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
(Connection refused)

Then I get the timeout message:
 Failed to start the container after more than [180000] ms. Trying to 
connect to the 
[http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST] 
test URL yielded a [-1] error code. Please run in debug mode for more 
details about the error.

I have tried to browse to that location and I get 404'd.  If I browse to 
http://localhost:8081/app/ServletRedirector?Cactus_Service=RUN_TEST, 
however, I get a blank page.

I turned on cactus logging but didn't see anything new about the error.

Anyone have any clues for me?  Do you need more information to help me?  
Let me know.

Thanks,
David Turley

ServletRedirector context

Posted by David Turley <sy...@synath.com>.
My cactus.contextURL is set to /app, but for some reason the servlet 
redirector is being mapped to /ServletRedirector .  So when I run the 
Ant Cactus task, it tries to find it at /app/ServletRedirector, but it 
isn't there.  I tried putting the servletredirector tag into the 
cactifywar task and setting the mapping to /app/ServletRedirector, but 
then the cactus task looked for it at /app/app/ServletRedirector.  I 
guess I'm just missing something.  Any help would be appreciated.

Thanks,
David

Re: How to assert forwards?

Posted by Niklas Lindholm <ca...@nilin.se>.
Hi!

Yes, separating the forwarding from the rest is definitely a solution. 
Thanks very much for the help Kazuhito and Nicolas!

/Niklas

On Mon, 15 Aug 2005, Kazuhito SUGURI wrote:

> Hi Niklas,
> 
> In article <Pi...@schlager.nilin.se>,
> Sat, 13 Aug 2005 12:24:54 +0200 (CEST),
> Niklas Lindholm <ca...@nilin.se> wrote: 
> cactuslist> > response.getWebRequest().getURL();
> cactuslist> 
> cactuslist> I have done a simple test and in that test the getURL() method returns 
> cactuslist> null. So I get this failure:
> cactuslist> 
> cactuslist> junit.framework.AssertionFailedError: expected:<unit.jsp> but was:<null>
> cactuslist> 
> cactuslist> I have a servlet that ends with this line:
> cactuslist> 
> cactuslist> req.getRequestDispatcher("unit.jsp").forward(req, res);
> cactuslist> 
> cactuslist> And in my endXXX() method I have this assertion:
> cactuslist> 
> cactuslist> assertEquals("unit.jsp", response.getWebRequest().getURL());
> cactuslist> 
> cactuslist> The endXXX() method is run on the client side. Will the client side really 
> cactuslist> have information about what forward that has been done since this typs of 
> cactuslist> forward is done entirely on the server side? I would imagine that this 
> cactuslist> kind of assertion would have to go into the testXXX() method.
> 
> AFAIK, the getURL() method returns a simulated URL
> which is specified by WebRequest#setURL method.
> So, you cannot know a forwarded URL by using the method.
> 
> 
> cactuslist> > Why ?? It seems a great solution : you can check more ie that there is
> cactuslist> > no error message in the page code...
> cactuslist> 
> cactuslist> Well.. in this case I don't want to verify the content of the resulting 
> cactuslist> page. Only the logic of the servlet. And it could be pretty difficult to 
> cactuslist> figure out from the resulting HTML which jsp page that actually has been 
> cactuslist> invoked. (Unless I code some comment into it telling which jsp page it 
> cactuslist> is.. hmm.. that might be a solution..)
> 
> If you are interested in the servlet logic, you might separate
> the logic into some methods to make your test easier. For your case:
> - a method returns String as a resource name to be forwarded
> - a method forward the request to the selected resource
> 
> For example, the code will be like as follows:
>     public String getForwardTo() {
>         // resource selection logic
>         return resourceName;
>     }
>     ...
>         req.getRequestDispatcher(getForwardTo()).forward(req, res);
> 
> You can write tests for the getForwardTo() method to verify
> the selection has been done properly.
> 
> If you want the forward is been done properly,
> you have to verify the resulting HTML in endXXX().
> To make it easier, you might insert ID string as a HTML comment
> in every JSPs.
> 
> Hope this helps,
> ----
> Kazuhito SUGURI
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 

Re: How to assert forwards?

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Niklas,

In article <Pi...@schlager.nilin.se>,
Sat, 13 Aug 2005 12:24:54 +0200 (CEST),
Niklas Lindholm <ca...@nilin.se> wrote: 
cactuslist> > response.getWebRequest().getURL();
cactuslist> 
cactuslist> I have done a simple test and in that test the getURL() method returns 
cactuslist> null. So I get this failure:
cactuslist> 
cactuslist> junit.framework.AssertionFailedError: expected:<unit.jsp> but was:<null>
cactuslist> 
cactuslist> I have a servlet that ends with this line:
cactuslist> 
cactuslist> req.getRequestDispatcher("unit.jsp").forward(req, res);
cactuslist> 
cactuslist> And in my endXXX() method I have this assertion:
cactuslist> 
cactuslist> assertEquals("unit.jsp", response.getWebRequest().getURL());
cactuslist> 
cactuslist> The endXXX() method is run on the client side. Will the client side really 
cactuslist> have information about what forward that has been done since this typs of 
cactuslist> forward is done entirely on the server side? I would imagine that this 
cactuslist> kind of assertion would have to go into the testXXX() method.

AFAIK, the getURL() method returns a simulated URL
which is specified by WebRequest#setURL method.
So, you cannot know a forwarded URL by using the method.


cactuslist> > Why ?? It seems a great solution : you can check more ie that there is
cactuslist> > no error message in the page code...
cactuslist> 
cactuslist> Well.. in this case I don't want to verify the content of the resulting 
cactuslist> page. Only the logic of the servlet. And it could be pretty difficult to 
cactuslist> figure out from the resulting HTML which jsp page that actually has been 
cactuslist> invoked. (Unless I code some comment into it telling which jsp page it 
cactuslist> is.. hmm.. that might be a solution..)

If you are interested in the servlet logic, you might separate
the logic into some methods to make your test easier. For your case:
- a method returns String as a resource name to be forwarded
- a method forward the request to the selected resource

For example, the code will be like as follows:
    public String getForwardTo() {
        // resource selection logic
        return resourceName;
    }
    ...
        req.getRequestDispatcher(getForwardTo()).forward(req, res);

You can write tests for the getForwardTo() method to verify
the selection has been done properly.

If you want the forward is been done properly,
you have to verify the resulting HTML in endXXX().
To make it easier, you might insert ID string as a HTML comment
in every JSPs.

Hope this helps,
----
Kazuhito SUGURI

Re: Connection Refused Error.

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi,

In article <11...@linux.site>,
Wed, 14 Sep 2005 08:57:36 +0530,
Aruna Ponnusamy <ar...@igate.com> wrote: 
aruna.ponnusamy> My contextURL is http://localhost:8080/detailapp
aruna.ponnusamy> I'm using my localhost.

OK.
Then...

In article <11...@linux.site>,
Mon, 12 Sep 2005 14:18:03 +0530,
Aruna Ponnusamy <ar...@igate.com> wrote: 
aruna> My Tomcat is up and the application works perfectly, but cactus throws
aruna> errors when run.

One cause I know is that the AP server is not running
(or is not listening a port that is spedified by contextURL)
when Cactus runs.
If this isn't the cause, we need more information about your case.


aruna> testControlStatus(test.TestLogonPage)java.net.ConnectException:
aruna> Connection refused
aruna> 	at java.net.PlainSocketImpl.socketConnect(Native Method)
[snip]
aruna> 	at
aruna> org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
aruna> 	at test.TestLogonPage.main(TestLogonPage.java:60)

How did you run the test? `java test.TestLogonPage`?
Could you try `java junit.textui.TestRunner test.TestLogonPage`?


Regards,
----
Kazuhito SUGURI

Cactus JBoss-2.2.X support (was: Re: Connection Refused Error.)

Posted by Nicolas Chalumeau <ni...@gmail.com>.
The ant integration only support the 3.X version of JBoss...
Cactus "will" use Cargo to start/stop container but actually Cargo
support 3.X and 4.X and I don't think 2.2.X is a priority but you can
ask for this at http://jira.codehaus.org/browse/CARGO

Nicolas

2005/9/14, Duque <aa...@gmail.com>:
> Hi buddies,
>  Somebody use Jakarta Cactus with JBOSS 2.2.6 e 2.2.7 ?
>  Att,
> Andre L. Amram Duque
> 
>  On 9/13/05, Kazuhito SUGURI <su...@lab.ntt.co.jp> wrote:
> >
> > Hi Aruna,
> >
> > In article <11...@linux.site>,
> > Mon, 12 Sep 2005 14:18:03 +0530,
> > Aruna Ponnusamy <ar...@igate.com> wrote:
> > aruna> When I try running my cactus testcase it is throwing the following
> > aruna> error:
> > aruna>
> > aruna> testControlStatus(test.TestLogonPage)java.net.ConnectException:
> > aruna> Connection refused
> >
> > As the error message informs...
> >
> >
> > aruna> I've put my cactus.properties file also in src and classes folder.
> > [snip]
> > aruna> My Tomcat is up and the application works perfectly, but cactus
> > throws
> > aruna> errors when run.
> >
> > What's your cactus.contextURL?
> > Can you access to the host:port by using telnet?
> > ----
> > Kazuhito SUGURI
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> >
> >
> 
> 
> --
> Kol tov,
> André L. A. Duque
> 
>

Re: Connection Refused Error.

Posted by Duque <aa...@gmail.com>.
Hi buddies,
 Somebody use Jakarta Cactus with JBOSS 2.2.6 e 2.2.7 ?
 Att,
Andre L. Amram Duque

 On 9/13/05, Kazuhito SUGURI <su...@lab.ntt.co.jp> wrote: 
> 
> Hi Aruna,
> 
> In article <11...@linux.site>,
> Mon, 12 Sep 2005 14:18:03 +0530,
> Aruna Ponnusamy <ar...@igate.com> wrote:
> aruna> When I try running my cactus testcase it is throwing the following
> aruna> error:
> aruna>
> aruna> testControlStatus(test.TestLogonPage)java.net.ConnectException:
> aruna> Connection refused
> 
> As the error message informs...
> 
> 
> aruna> I've put my cactus.properties file also in src and classes folder.
> [snip]
> aruna> My Tomcat is up and the application works perfectly, but cactus 
> throws
> aruna> errors when run.
> 
> What's your cactus.contextURL?
> Can you access to the host:port by using telnet?
> ----
> Kazuhito SUGURI
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 


-- 
Kol tov,
André L. A. Duque

Re: Connection Refused Error.

Posted by Aruna Ponnusamy <ar...@igate.com>.
Hi Kazuhito,
My contextURL is http://localhost:8080/detailapp
I'm using my localhost.

Thanks,
Aruna

On Tue, 2005-09-13 at 23:40 +0900, Kazuhito SUGURI wrote:

> Hi Aruna,
> 
> In article <11...@linux.site>,
> Mon, 12 Sep 2005 14:18:03 +0530,
> Aruna Ponnusamy <ar...@igate.com> wrote: 
> aruna> When I try running my cactus testcase it is throwing the following
> aruna> error:
> aruna> 
> aruna> testControlStatus(test.TestLogonPage)java.net.ConnectException:
> aruna> Connection refused
> 
> As the error message informs...
> 
> 
> aruna> I've put my cactus.properties file also in src and classes folder.
> [snip]
> aruna> My Tomcat is up and the application works perfectly, but cactus throws
> aruna> errors when run.
> 
> What's your cactus.contextURL?
> Can you access to the host:port by using telnet?
> ----
> Kazuhito SUGURI
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 

Re: Connection Refused Error.

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Aruna,

In article <11...@linux.site>,
Mon, 12 Sep 2005 14:18:03 +0530,
Aruna Ponnusamy <ar...@igate.com> wrote: 
aruna> When I try running my cactus testcase it is throwing the following
aruna> error:
aruna> 
aruna> testControlStatus(test.TestLogonPage)java.net.ConnectException:
aruna> Connection refused

As the error message informs...


aruna> I've put my cactus.properties file also in src and classes folder.
[snip]
aruna> My Tomcat is up and the application works perfectly, but cactus throws
aruna> errors when run.

What's your cactus.contextURL?
Can you access to the host:port by using telnet?
----
Kazuhito SUGURI

Connection Refused Error.

Posted by Aruna Ponnusamy <ar...@igate.com>.
Hi all,
When I try running my cactus testcase it is throwing the following
error:

testControlStatus(test.TestLogonPage)java.net.ConnectException:
Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
	at java.net.Socket.connect(Socket.java:452)
	at java.net.Socket.connect(Socket.java:402)
	at java.net.Socket.<init>(Socket.java:309)
	at java.net.Socket.<init>(Socket.java:124)
	at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:105)
	at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:663)
	at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:661)
	at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:558)
	at
org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect_aroundBody0(HttpClientConnectionHelper.java:142)
	at
org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect_aroundBody1$advice(HttpClientConnectionHelper.java:206)
	at
org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect(HttpClientConnectionHelper.java)
	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callRunTest(DefaultHttpClient.java:162)
	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:80)
	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:206)
	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:206)
	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
	at
org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
	at
org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
	at
org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
	at test.TestLogonPage.main(TestLogonPage.java:60)


I'm using Tomcat 5.0.28.
I've put my cactus.properties file also in src and classes folder.
I've included servlet mapping for servletredirector and jspredirector in
Web.xml file.
jspRedirector.jsp file is also there under my application.
My Tomcat is up and the application works perfectly, but cactus throws
errors when run.
Am I missing something?
Any hint on this?


Thanks & Regards,
Aruna

Re: How to assert forwards?

Posted by Niklas Lindholm <ca...@nilin.se>.

Hi Nicolas!

> response.getWebRequest().getURL();

I have done a simple test and in that test the getURL() method returns 
null. So I get this failure:

junit.framework.AssertionFailedError: expected:<unit.jsp> but was:<null>

I have a servlet that ends with this line:

req.getRequestDispatcher("unit.jsp").forward(req, res);

And in my endXXX() method I have this assertion:

assertEquals("unit.jsp", response.getWebRequest().getURL());

The endXXX() method is run on the client side. Will the client side really 
have information about what forward that has been done since this typs of 
forward is done entirely on the server side? I would imagine that this 
kind of assertion would have to go into the testXXX() method.

> Why ?? It seems a great solution : you can check more ie that there is
> no error message in the page code...

Well.. in this case I don't want to verify the content of the resulting 
page. Only the logic of the servlet. And it could be pretty difficult to 
figure out from the resulting HTML which jsp page that actually has been 
invoked. (Unless I code some comment into it telling which jsp page it 
is.. hmm.. that might be a solution..)

/Niklas

Re: How to assert forwards?

Posted by Nicolas Chalumeau <ni...@gmail.com>.
Salut Niklas,

2005/8/11, Niklas Lindholm <ca...@nilin.se>:
> Hi!
> 
> I am writing a web application that is using an MVC design. This means
> that at the end of almost every servlet I do a
> 
> request.getRequestDispatcher("foo.jsp").forward(request, response)
> 
> 
> I some cases the servlet makes a choice between two (or more) different
> targets to forward() to. Something like:
> 
> if(somethingIsTrue)
>   request.getRequestDispatcher("foo.jsp").forward(request, response);
> else
>   request.getRequestDispatcher("bar.jsp").forward(request, response);
> 
> Is there a way to make a Cactus test case that asserts that the forward is
> being done to the correct target? I can't find any way to get information
> about what forward that has been done. 

response.getWebRequest().getURL();

> (Except trying to find out by
> looking at the resulting HTML is endXXXX(), but that doesn't seem like a
> good idea..)

Why ?? It seems a great solution : you can check more ie that there is
no error message in the page code...

Nicolas,

> 
> /Niklas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
>