001: package org.apache.turbine.om.security;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.cactus.ServletTestCase;
026: import org.apache.turbine.Turbine;
027: import java.util.*;
028:
029: /**
030: * Test the TurbineUser
031: *
032: * This tests that we can use the TurbineUser classes. Note, this can be very dependent
033: * on various configuration values.
034: *
035: * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
036: * @version $Id: TurbineUserTest.java 534527 2007-05-02 16:10:59Z tv $
037: */
038: public class TurbineUserTest extends ServletTestCase {
039:
040: Turbine turbine = null;
041:
042: /**
043: * Constructor for TurbineUserTest.
044: * @param arg0
045: */
046: public TurbineUserTest(String name) {
047: super (name);
048: }
049:
050: /**
051: * This will setup an instance of turbine to use when testing
052: * @exception if an exception occurs.
053: */
054:
055: protected void setUp() throws Exception {
056: super .setUp();
057:
058: config.setInitParameter("properties",
059: "/WEB-INF/conf/TurbineComplete.properties");
060: turbine = new Turbine();
061: turbine.init(config);
062: }
063:
064: /**
065: * Shut down our turbine servlet and let our parents clean up also.
066: *
067: * @exception Exception if an error occurs
068: */
069: protected void tearDown() throws Exception {
070: turbine.destroy();
071: super .tearDown();
072: }
073:
074: /**
075: * Return a test suite of all our tests.
076: *
077: * @return a <code>Test</code> value
078: */
079: public static Test suite() {
080: return new TestSuite(TurbineUserTest.class);
081: }
082:
083: /**
084: * Tests if a TurbineUser can be created. This seemed to cause
085: * errors at one point.
086: */
087: public void testCreatingTurbineUser() throws Exception {
088: TurbineUser user = null;
089:
090: user = new TurbineUser();
091:
092: assertNotNull(user);
093: }
094:
095: public void testSavingAndStoringTemporaryValues() throws Exception {
096: TurbineUser user = new TurbineUser();
097: user.setTemp("test", "value");
098: assertEquals("value", user.getTemp("test"));
099:
100: assertNull(user.getTemp("nonexistentvalue"));
101: assertEquals("defaultvalue", user.getTemp("nonexistentvalues",
102: "defaultvalue"));
103: Hashtable htTemp = new Hashtable();
104: htTemp.put("test1", "value1");
105: htTemp.put("test2", new Integer(5));
106:
107: user.setTempStorage(htTemp);
108: assertEquals("value1", user.getTemp("test1"));
109: Integer retVal = (Integer) user.getTemp("test2");
110: assertTrue(retVal.intValue() == 5);
111: assertNull(user.getTemp("test"));
112: }
113:
114: public void testSavingAndStoringPermValues() throws Exception {
115: TurbineUser user = new TurbineUser();
116: user.setPerm("test", "value");
117: assertEquals("value", user.getPerm("test"));
118:
119: assertNull(user.getPerm("nonexistentvalue"));
120: assertEquals("defaultvalue", user.getPerm("nonexistentvalues",
121: "defaultvalue"));
122:
123: Hashtable htPerm = new Hashtable();
124: htPerm.put("test1", "value1");
125: htPerm.put("test2", new Integer(5));
126:
127: user.setPermStorage(htPerm);
128: assertEquals("value1", user.getPerm("test1"));
129: Integer retVal = (Integer) user.getPerm("test2");
130: assertTrue(retVal.intValue() == 5);
131: assertNull(user.getPerm("test"));
132: }
133: }
|