KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestHttpSession


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.sample.servlet.unit;
21
22 import org.apache.cactus.HttpSessionCookie;
23 import org.apache.cactus.ServletTestCase;
24 import org.apache.cactus.WebRequest;
25 import org.apache.cactus.WebResponse;
26
27 /**
28  * Tests that manipulates the HTTP Session.
29  *
30  * @version $Id: TestHttpSession.java,v 1.3 2004/02/29 16:36:44 vmassol Exp $
31  */

32 public class TestHttpSession extends ServletTestCase
33 {
34     /**
35      * Verify that it is possible to ask for no automatic session creation in
36      * the <code>beginXXX()</code> method.
37      *
38      * @param theRequest the request object that serves to initialize the
39      * HTTP connection to the server redirector.
40      */

41     public void beginNoAutomaticSessionCreation(WebRequest theRequest)
42     {
43         theRequest.setAutomaticSession(false);
44     }
45
46     /**
47      * Verify that it is possible to ask for no automatic session creation in
48      * the <code>beginXXX()</code> method.
49      */

50     public void testNoAutomaticSessionCreation()
51     {
52         assertNull("A valid session has been found when no session should "
53             + "exist", session);
54     }
55
56     //-------------------------------------------------------------------------
57

58     /**
59      * Verify that we can get hold of the jsessionid cookie returned by the
60      * server.
61      */

62     public void testVerifyJsessionid()
63     {
64         // By default, Cactus will create an HTTP session.
65
}
66     
67     /**
68      * Verify that we can get hold of the jsessionid cookie returned by the
69      * server.
70      *
71      * @param theResponse the response from the server side.
72      */

73     public void endVerifyJsessionid(WebResponse theResponse)
74     {
75         assertNotNull(theResponse.getCookieIgnoreCase("jsessionid"));
76     }
77
78     //-------------------------------------------------------------------------
79

80     /**
81      * Verify that Cactus can provide us with a real HTTP session cookie.
82      *
83      * @param theRequest the request object that serves to initialize the
84      * HTTP connection to the server redirector.
85      */

86     public void beginCreateSessionCookie(WebRequest theRequest)
87     {
88         HttpSessionCookie sessionCookie = theRequest.getSessionCookie();
89         assertNotNull("Session cookie should not be null", sessionCookie);
90         theRequest.addCookie(sessionCookie);
91     }
92
93     /**
94      * Verify that Cactus can provide us with a real HTTP session cookie.
95      */

96     public void testCreateSessionCookie()
97     {
98         assertTrue("A session should have been created prior to "
99             + "this request", !session.isNew());
100     }
101
102 }
103
Popular Tags