KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > cactus > sample > TestSampleServlet


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.maven.cactus.sample;
21
22 import org.apache.cactus.ServletTestCase;
23 import org.apache.cactus.WebRequest;
24
25 /**
26  * Tests of the <code>SampleServlet</code> Servlet class.
27  *
28  * @version $Id: TestSampleServlet.java,v 1.3 2004/02/29 16:34:44 vmassol Exp $
29  */

30 public class TestSampleServlet extends ServletTestCase
31 {
32     /**
33      * Verify that <code>isAuthenticated</code> works when the user is
34      * authenticated.
35      */

36     public void testIsAuthenticatedAuthenticated()
37     {
38         SampleServlet servlet = new SampleServlet();
39
40         session.setAttribute("authenticated", "true");
41         
42         assertTrue(servlet.isAuthenticated(request));
43     }
44
45     /**
46      * Verify that <code>isAuthenticated</code> works when the user is
47      * not authenticated.
48      */

49     public void testIsAuthenticatedNotAuthenticated()
50     {
51         SampleServlet servlet = new SampleServlet();
52
53         assertTrue(!servlet.isAuthenticated(request));
54     }
55
56     /**
57      * Verify that <code>isAuthenticated</code> works when there is no
58      * HTTP Session.
59      *
60      * @param theRequest the Cactus request object
61      */

62     public void beginIsAuthenticatedNoSession(WebRequest theRequest)
63     {
64         theRequest.setAutomaticSession(false);
65     }
66     
67     /**
68      * Verify that <code>isAuthenticated</code> works when there is no
69      * HTTP Session.
70      */

71     public void testIsAuthenticatedNoSession()
72     {
73         SampleServlet servlet = new SampleServlet();
74
75         assertTrue(!servlet.isAuthenticated(request));
76     }
77 }
78
Popular Tags