jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pandu.Yelamanch...@co.hennepin.mn.us
Subject RE: Maintaing session between 2 cactus test cases.
Date Fri, 28 Jan 2005 19:19:40 GMT
Maintaining session between some tests will help us also, since we have to
keep some things in session. These items are valid for the entire session.
What we notice that in our unit tests when we run them like they should be
, each test goes to the db every time to keep those needed items in
session. This creates lots of overhead for us. I guess one way would to use
mock objects for that . Any suggestions Vincent ??
Regards
Pandu


|---------+---------------------------->
|         |           "Vincent Massol" |
|         |           <vmassol@pivolis.|
|         |           com>             |
|         |                            |
|         |           01/28/2005 01:06 |
|         |           PM               |
|         |           Please respond to|
|         |           "Cactus Users    |
|         |           List"            |
|---------+---------------------------->
  >--------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                       |
  |       To:       "'Venu Sunil Boyireddy'" <venub@aztec.soft.net>, "'Cactus Users
List'"                       |
  |        <cactus-user@jakarta.apache.org>                                        
                             |
  |       cc:                                                                            
                       |
  |       Subject:  RE: Maintaing session between 2 cactus test cases.                   
                       |
  >--------------------------------------------------------------------------------------------------------------|




Hi Sunil,

I've taken some time to write a test to prove that it works. Here it is:

public class TestHttpSession extends ServletTestCase
{
    private HttpSessionCookie sessionCookie;
    private TestHttpSession dependentTest;

    public TestHttpSession(String name)
    {
        super(name);
    }

    public TestHttpSession(String name, TestHttpSession test)
    {
        super(name);
        this.dependentTest = test;
    }

    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        TestHttpSession test = new
TestHttpSession("testDependentTestUsingSession");
        suite.addTest(test);
        suite.addTest(new TestHttpSession("testDependentTestUsingSession2",
test));

        return suite;
    }

    public void beginDependentTestUsingSession(WebRequest theRequest)
    {
        this.sessionCookie = theRequest.getSessionCookie();
        assertNotNull("Session cookie should not be null", sessionCookie);
        theRequest.addCookie(sessionCookie);
        System.out.println("cookie = " + this.sessionCookie);
    }

    public void testDependentTestUsingSession()
    {
        session.setAttribute("dependentTestId", "dependentTestValue");
    }

    public void beginDependentTestUsingSession2(WebRequest theRequest)
    {
        assertNotNull(this.dependentTest.sessionCookie);
        theRequest.addCookie(this.dependentTest.sessionCookie);
    }

    public void testDependentTestUsingSession2()
    {
        assertEquals("dependentTestValue",
session.getAttribute("dependentTestId"));
    }
}

Please note that making test dependent on each other is strongly
discouraged
as this is not unit testing. I just wanted to show you it is possible but I
would advise you to set up the session with the right value for each test.

Thanks
-Vincent

> -----Original Message-----
> From: Venu Sunil Boyireddy [mailto:venub@aztec.soft.net]
> Sent: vendredi 28 janvier 2005 17:33
> To: Cactus Users List
> Cc: vmassol@pivolis.com
> Subject: RE: Maintaing session between 2 cactus test cases.
>
> Hi Vincent,
>
> I have used the other also.
>
>
>
>            theRequest.setAutomaticSession(false);
>       HttpSessionCookie sessionCookie = theRequest.getSessionCookie();
>       assertNotNull("Session cookie should not be null", sessionCookie);
>            theRequest.addCookie(sessionCookie);
>
> these are the entries in my beginXXX method. But still I was getting new
> session every time.
>
> I tested AbstractWebTestController.java. I found it still creating new
> session before every test case?
>
> Is cactus any where removing sessions?
>
> Any help is greatly appreciated.
>
> Thanks and Regards
>
> Sunil
>
>
>
> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@pivolis.com]
> Sent: Thursday, January 27, 2005 7:17 PM
> To: Venu Sunil Boyireddy; 'Cactus Users List'
> Subject: RE: Maintaing session between 2 cactus test cases.
>
>
> Hi Sunil,
>
> > -----Original Message-----
> > From: Venu Sunil Boyireddy [mailto:venub@aztec.soft.net]
> > Sent: jeudi 27 janvier 2005 14:29
> > To: Cactus Users List
> > Cc: vmassol@pivolis.com
> > Subject: RE: Maintaing session between 2 cactus test cases.
> >
> > Hi Vincent,
> >
> > Thanks for your help.
> > I'm using cactus, strutsTest to test my action classes. Its working
fine
> > with individual Action Clases.
> >
> > We have a generic test case which takes parameters such as Action name,
> > Request parameters, actionforward Name, action forward path etc. from
> xml
> > file and test that action class.
> >
> > So, with this I am able to test multiple actions. And Thanks for your
> help
> > in getting this work done.
> >
> > But, to complete testing our functionality I need to test 3 action
> > classes.
> > As I'm using generic Testcase which tests one action class at a time, I
> > need
> > to run 3 testcases (or the generic test case thrice with different
> > parameters) to test these action classes. For this I need session alive
> in
> > between, so first action class keep some values in session and the
other
> > Action classes needs. So, All these 3 test cases needs to share same
> > session.
> >
> > Hope I'm clear in explaining my problem.
>
> Yes, that's what I had understood.
>
> >
> > I tried with WebRequest.setAutomaticSession(false). that didn't work.
>
> Have you tried the second point I mentioned below?
>
> Thanks
> -Vincent
>
> >
> > Any help is greatly appreciated.
> >
> > Thanks and Regards
> >
> > Sunil
> >
> >
> >
> > -----Original Message-----
> > From: Vincent Massol [mailto:vmassol@pivolis.com]
> > Sent: Wednesday, January 26, 2005 7:22 PM
> > To: cactus-user@jakarta.apache.org
> > Subject: RE: Maintaing session between 2 cactus test cases.
> >
> >
> > Hi Sunil,
> >
> > - You can use WebRequest.setAutomaticSession(false) to tell Cactus not
> to
> > create a new HTTP session, but that may or may not help you.
> >
> > - You can also use WebRequest.getSessionCookie() if you wish to get the
> > session cookie created in order to reuse it in another test
> >
> > See http://tinyurl.com/4qeeb for the test file used by Cactus to test
> > these
> > features.
> >
> > -Vincent
> >
> > > -----Original Message-----
> > > From: Venu Sunil Boyireddy [mailto:venub@aztec.soft.net]
> > > Sent: lundi 24 janvier 2005 06:53
> > > To: cactus-dev@jakarta.apache.org; cactus-user@jakarta.apache.org
> > > Subject: Maintaing session between 2 cactus test cases.
> > >
> > > Hi,
> > >
> > >
> > > I have a requirement where I need to maintain the session alive
> between
> > > the
> > > test cases.
> > >
> > > How can I do it. I know that cactus wont support it by default as its
> a
> > > unit
> > > test framework.
> > >
> > > Any help is greatly appreciated.
> > >
> > > Thanks in advance.
> > >
> > > Sunil
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: cactus-dev-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




Mime
View raw message