01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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 238815 2004-02-29 16:34:44Z vmassol $
29: */
30: public class TestSampleServlet extends ServletTestCase {
31: /**
32: * Verify that <code>isAuthenticated</code> works when the user is
33: * authenticated.
34: */
35: public void testIsAuthenticatedAuthenticated() {
36: SampleServlet servlet = new SampleServlet();
37:
38: session.setAttribute("authenticated", "true");
39:
40: assertTrue(servlet.isAuthenticated(request));
41: }
42:
43: /**
44: * Verify that <code>isAuthenticated</code> works when the user is
45: * not authenticated.
46: */
47: public void testIsAuthenticatedNotAuthenticated() {
48: SampleServlet servlet = new SampleServlet();
49:
50: assertTrue(!servlet.isAuthenticated(request));
51: }
52:
53: /**
54: * Verify that <code>isAuthenticated</code> works when there is no
55: * HTTP Session.
56: *
57: * @param theRequest the Cactus request object
58: */
59: public void beginIsAuthenticatedNoSession(WebRequest theRequest) {
60: theRequest.setAutomaticSession(false);
61: }
62:
63: /**
64: * Verify that <code>isAuthenticated</code> works when there is no
65: * HTTP Session.
66: */
67: public void testIsAuthenticatedNoSession() {
68: SampleServlet servlet = new SampleServlet();
69:
70: assertTrue(!servlet.isAuthenticated(request));
71: }
72: }
|