KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > om > security > TurbineUserTest


1 package org.apache.turbine.om.security;
2
3 /*
4  * Copyright 2001-2004 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 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.cactus.ServletTestCase;
23 import org.apache.turbine.Turbine;
24 import java.util.*;
25
26 /**
27  * Test the TurbineUser
28  *
29  * This tests that we can use the TurbineUser classes. Note, this can be very dependent
30  * on various configuration values.
31  *
32  * @author <a HREF="mailto:epugh@upstate.com">Eric Pugh</a>
33  * @version $Id: TurbineUserTest.java,v 1.2.2.2 2004/05/20 03:33:44 seade Exp $
34  */

35 public class TurbineUserTest extends ServletTestCase
36 {
37
38     Turbine turbine = null;
39
40     /**
41      * Constructor for TurbineUserTest.
42      * @param arg0
43      */

44     public TurbineUserTest(String JavaDoc name)
45     {
46         super(name);
47     }
48
49     /**
50      * This will setup an instance of turbine to use when testing
51      * @exception if an exception occurs.
52      */

53
54     protected void setUp() throws Exception JavaDoc
55     {
56         super.setUp();
57
58         config.setInitParameter("properties", "/WEB-INF/conf/TurbineComplete.properties");
59         turbine = new Turbine();
60         turbine.init(config);
61     }
62
63     /**
64      * Shut down our turbine servlet and let our parents clean up also.
65      *
66      * @exception Exception if an error occurs
67      */

68     protected void tearDown() throws Exception JavaDoc
69     {
70         turbine.destroy();
71         super.tearDown();
72     }
73
74     /**
75      * Return a test suite of all our tests.
76      *
77      * @return a <code>Test</code> value
78      */

79     public static Test suite()
80     {
81         return new TestSuite(TurbineUserTest.class);
82     }
83
84     /**
85      * Tests if a TurbineUser can be created. This seemed to cause
86      * errors at one point.
87      */

88     public void testCreatingTurbineUser() throws Exception JavaDoc
89     {
90         TurbineUser user = null;
91
92         user = new TurbineUser();
93
94         assertNotNull(user);
95     }
96
97     public void testSavingAndStoringTemporaryValues() throws Exception JavaDoc
98     {
99         TurbineUser user = new TurbineUser();
100         user.setTemp("test", "value");
101         assertEquals("value", user.getTemp("test"));
102
103         assertNull(user.getTemp("nonexistentvalue"));
104         assertEquals("defaultvalue", user.getTemp("nonexistentvalues", "defaultvalue"));
105         Hashtable htTemp = new Hashtable();
106         htTemp.put("test1", "value1");
107         htTemp.put("test2", new Integer JavaDoc(5));
108
109         user.setTempStorage(htTemp);
110         assertEquals("value1", user.getTemp("test1"));
111         Integer JavaDoc retVal = (Integer JavaDoc) user.getTemp("test2");
112         assertTrue(retVal.intValue() == 5);
113         assertNull(user.getTemp("test"));
114     }
115
116     public void testSavingAndStoringPermValues() throws Exception JavaDoc
117     {
118         TurbineUser user = new TurbineUser();
119         user.setPerm("test", "value");
120         assertEquals("value", user.getPerm("test"));
121
122         assertNull(user.getPerm("nonexistentvalue"));
123         assertEquals("defaultvalue", user.getPerm("nonexistentvalues", "defaultvalue"));
124
125         Hashtable htPerm = new Hashtable();
126         htPerm.put("test1", "value1");
127         htPerm.put("test2", new Integer JavaDoc(5));
128
129         user.setPermStorage(htPerm);
130         assertEquals("value1", user.getPerm("test1"));
131         Integer JavaDoc retVal = (Integer JavaDoc) user.getPerm("test2");
132         assertTrue(retVal.intValue() == 5);
133         assertNull(user.getPerm("test"));
134     }
135 }
136
Popular Tags