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 an...@yahoo.fr on 2005/03/05 11:29:40 UTC

Reproductible double call behavior / Cookies problems

Hi, after dealing some time with double calls on beginXXX and endXXX I've setup a  
minimal test suite which reproduce the behavior. The problem was caused by the fact  
I used a ServletTestSuite instead of a TestSuite : 

public class TestCactus extends ServletTestCase 
{ 
    public static Test suite() 
    {         
        //ServletTestSuite suite = new ServletTestSuite(); 
        TestSuite suite = new TestSuite(); 
        suite.addTestSuite(TestCactus.class);         
        return suite; 
    } 
     
    public void beginTest(WebRequest wr) 
    {         
        log.info("Client in beginTest"); 
        wr.addCookie("cookme","cooked"); 
    } 
     
    public void testTest() 
    { 
        log.info("Request cookies " + this.request.getCookies()); 
        log.info("Server in testTest"); 
    } 
     
    public void endTest(WebResponse wr) 
    { 
        log.info("Client in endTest"); 
        log.info("cookme is " + wr.getCookieIgnoreCase("cookme")); 
    } 
} 

Replacing TestSuite suite = new TestSuite(); with ServletTestSuite suite = new  
ServletTestSuite(); produce double calls on beginXXX & endXXX methods. I presume  
that ServletTestSuite are intended to be used with JUnit test cases ONLY, now I know  
;-) 

BUT, in the example above the cookies "cookme" is not available on testTest and  
endTest methods as show in this log... I don't see the reason why. I've searched all  
the documentation on Cactus website and didn't found a reason for this code to fail. 

The test is run with  
http://devserver:8080/ServletTestRunner?suite=blogger.test.TestCactus&xsl=cactus- 
report.xsl 

Is there something else I must do if I want to use cookies on my tests ? If I rely on this  
page http://jakarta.apache.org/cactus/writing/howto_testcase_servlet.html, I don't see  
something special about cookies... 

Thank you 

11:17:12,781  INFO      TestCactus:  62 - Client in beginTest 
11:17:12,796  INFO      TestCactus:  68 - Request cookies null 
11:17:12,796  INFO      TestCactus:  69 - Server in testTest 
11:17:12,812  INFO      TestCactus:  74 - Client in endTest 
11:17:12,812  INFO      TestCactus:  75 - cookme is null 




RE: Reproductible double call behavior / Cookies problems

Posted by Vincent Massol <vm...@pivolis.com>.

> -----Original Message-----
> From: anaema_ml@yahoo.fr [mailto:anaema_ml@yahoo.fr]
> Sent: samedi 5 mars 2005 11:30
> To: cactus-user@jakarta.apache.org
> Subject: Reproductible double call behavior / Cookies problems
> 
> Hi, after dealing some time with double calls on beginXXX and endXXX I've
> setup a
> minimal test suite which reproduce the behavior. The problem was caused by
> the fact
> I used a ServletTestSuite instead of a TestSuite :

[snip]

> Replacing TestSuite suite = new TestSuite(); with ServletTestSuite suite =
> new
> ServletTestSuite(); produce double calls on beginXXX & endXXX methods. I
> presume
> that ServletTestSuite are intended to be used with JUnit test cases ONLY,
> now I know
> ;-)

Yes, when you use ServletTestSuite your class must extend TestCase or some
extension (but not a Cactus extension).

However, I had never tried to use both ServletTestSuite and ServletTestCase
myself so I was not aware of the pb you mention. I guess we could report a
warning or even an execution error if the user uses both. This is a good
candidate for raising a JIRA issue if you wish.

BTW, do you know that you can remove completely your suite() method and
it'll work the same (JUnit creates a default TestSuite with all methods
starting with "test")?

> 
> BUT, in the example above the cookies "cookme" is not available on
> testTest and
> endTest methods as show in this log... 

The cookie is sent to the server so it's normal it's not available in
endXXX. You would need to generate a cookie in your testXXX method and send
it in the response for it to be available in endXXX.

As for your testTest method, it should not report a null for
request.getCookies(). I don't know why it does. Check the TestCookie class
in the servlet sample in the Cactus distribution. It tests for this.

[snip]

Thanks
-Vincent