You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/11/05 16:39:53 UTC
cvs commit: jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/util SecuritySetTest.java GroupSetTest.java
epugh 2003/11/05 07:39:53
Modified: security/src/test/org/apache/fulcrum/security/adapter/osuser
OSUserAdapterTest.java
security/src/test/org/apache/fulcrum/security/spi/hibernate/simple/entity
UserSetTest.java
security/src/java/org/apache/fulcrum/security/util
RoleSet.java GroupSet.java SecuritySet.java
PermissionSet.java
security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity
UserSet.java
security/src/java/org/apache/fulcrum/security/adapter/osuser
FulcrumAccessProvider.java
security/xdocs changes.xml
security/src/test/org/apache/fulcrum/security/util
GroupSetTest.java
Added: security/src/test/org/apache/fulcrum/security/util
SecuritySetTest.java
Log:
Explicitly check for the name when seeing if a securitySet contians somethin...
Revision Changes Path
1.5 +3 -1 jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/adapter/osuser/OSUserAdapterTest.java
Index: OSUserAdapterTest.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/adapter/osuser/OSUserAdapterTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- OSUserAdapterTest.java 30 Oct 2003 14:25:37 -0000 1.4
+++ OSUserAdapterTest.java 5 Nov 2003 15:39:53 -0000 1.5
@@ -145,6 +145,8 @@
acl.hasRole("role1"),
accessProvider.inGroup("Jeannie", "role1"));
+ System.out.println("hi");
+
assertEquals(
"Neither should have role3",
acl.hasRole("role3"),
1.2 +2 -2 jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/spi/hibernate/simple/entity/UserSetTest.java
Index: UserSetTest.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/spi/hibernate/simple/entity/UserSetTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserSetTest.java 4 Nov 2003 16:23:08 -0000 1.1
+++ UserSetTest.java 5 Nov 2003 15:39:53 -0000 1.2
@@ -98,7 +98,7 @@
assertTrue(userSet.contains(user));
assertTrue(userSet.contains((Object) user));
assertTrue(userSet.contains(user2));
- assertFalse(userSet.contains(user3));
+ assertTrue(userSet.contains(user3));
assertTrue(userSet.contains(user));
}
1.4 +2 -2 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/RoleSet.java
Index: RoleSet.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/RoleSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RoleSet.java 26 Aug 2003 01:57:29 -0000 1.3
+++ RoleSet.java 5 Nov 2003 15:39:53 -0000 1.4
@@ -174,7 +174,7 @@
*/
public boolean contains(Role role)
{
- return nameMap.containsValue((Object) role);
+ return super.contains(role);
}
1.4 +2 -2 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/GroupSet.java
Index: GroupSet.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/GroupSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GroupSet.java 26 Aug 2003 01:57:29 -0000 1.3
+++ GroupSet.java 5 Nov 2003 15:39:53 -0000 1.4
@@ -174,7 +174,7 @@
*/
public boolean contains(Group group)
{
- return nameMap.containsValue((Object) group);
+ return super.contains(group);
}
1.5 +122 -120 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/SecuritySet.java
Index: SecuritySet.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/SecuritySet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SecuritySet.java 4 Nov 2003 16:23:08 -0000 1.4
+++ SecuritySet.java 5 Nov 2003 15:39:53 -0000 1.5
@@ -1,56 +1,45 @@
package org.apache.fulcrum.security.util;
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
- * reserved.
- *
+/*
+ * ==================================================================== The
+ * Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if and
+ * wherever such third-party acknowledgments normally appear.
+ * 4. The names "Apache" and "Apache Software Foundation" and "Apache Turbine"
+ * must not be used to endorse or promote products derived from this software
+ * without prior written permission. For written permission, please contact
+ * apache@apache.org.
+ * 5. Products derived from this software may not be called "Apache", "Apache
+ * Turbine", nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/> .
*/
import java.io.Serializable;
import java.util.Collection;
@@ -62,13 +51,11 @@
import org.apache.commons.lang.StringUtils;
import org.apache.fulcrum.security.entity.SecurityEntity;
/**
- * This class represents a set of Security Entities.
- * It makes it easy to build a UI.
- * It wraps a TreeSet object to enforce that only relevant
- * methods are available.
- * TreeSet's contain only unique Objects (no duplicates).
- * Additionally, they must have both a Name and an ID! You can
- * add only one object that has a null of each.
+ * This class represents a set of Security Entities. It makes it easy to build
+ * a UI. It wraps a TreeSet object to enforce that only relevant methods are
+ * available. TreeSet's contain only unique Objects (no duplicates).
+ * Additionally, they must have both a Name and an ID! You can add only one
+ * object that has a null of each.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
@@ -84,99 +71,97 @@
/** Map for "id" -> "security object" */
protected Map idMap = null;
/**
- * Constructs an empty Set
- */
+ * Constructs an empty Set
+ */
public SecuritySet()
{
nameMap = new TreeMap();
idMap = new TreeMap();
}
/**
- * Returns a set of security objects in this object.
- *
- * @return A Set Object
- *
- */
+ * Returns a set of security objects in this object.
+ *
+ * @return A Set Object
+ *
+ */
public Set getSet()
{
return new HashSet(nameMap.values());
}
/**
- * Returns a set of Names in this Object.
- *
- * @return The Set of Names in this Object,
- * backed by the actual data.
- */
+ * Returns a set of Names in this Object.
+ *
+ * @return The Set of Names in this Object, backed by the actual data.
+ */
public Set getNames()
{
return nameMap.keySet();
}
/**
- * Returns a set of Id values in this Object.
- *
- * @return The Set of Ids in this Object,
- * backed by the actual data.
- */
+ * Returns a set of Id values in this Object.
+ *
+ * @return The Set of Ids in this Object, backed by the actual data.
+ */
public Set getIds()
{
return idMap.keySet();
}
/**
- * Removes all Objects from this Set.
- */
+ * Removes all Objects from this Set.
+ */
public void clear()
{
nameMap.clear();
idMap.clear();
}
/**
- * Searches if an Object with a given name is in the
- * Set
- *
- * @param roleName Name of the Security Object.
- * @return True if argument matched an Object in this Set; false
- * if no match.
- */
+ * Searches if an Object with a given name is in the Set
+ *
+ * @param roleName Name of the Security Object.
+ * @return True if argument matched an Object in this Set; false if no
+ * match.
+ */
public boolean containsName(String name)
{
name = name.toLowerCase();
- return (StringUtils.isNotEmpty(name)) ? nameMap.containsKey(name) : false;
+ return (StringUtils.isNotEmpty(name))
+ ? nameMap.containsKey(name)
+ : false;
}
/**
- * Searches if an Object with a given Id is in the
- * Set
- *
- * @param id Id of the Security Object.
- * @return True if argument matched an Object in this Set; false
- * if no match.
- */
+ * Searches if an Object with a given Id is in the Set
+ *
+ * @param id Id of the Security Object.
+ * @return True if argument matched an Object in this Set; false if no
+ * match.
+ */
public boolean containsId(Object id)
{
return (id == null) ? false : idMap.containsKey(id);
}
/**
- * Returns an Iterator for Objects in this Set.
- *
- * @return An iterator for the Set
- */
+ * Returns an Iterator for Objects in this Set.
+ *
+ * @return An iterator for the Set
+ */
public Iterator iterator()
{
return nameMap.values().iterator();
}
/**
- * Returns size (cardinality) of this set.
- *
- * @return The cardinality of this Set.
- */
+ * Returns size (cardinality) of this set.
+ *
+ * @return The cardinality of this Set.
+ */
public int size()
{
return nameMap.size();
}
/**
- * list of role names in this set
- *
- * @return The string representation of this Set.
- */
+ * list of role names in this set
+ *
+ * @return The string representation of this Set.
+ */
public String toString()
{
StringBuffer sbuf = new StringBuffer(12 * size());
@@ -230,37 +215,54 @@
{
throw new RuntimeException("not implemented");
}
- /* (non-Javadoc)
- * @see java.util.Collection#toArray()
- */
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Collection#toArray()
+ */
public Object[] toArray()
{
return getSet().toArray();
}
- /* (non-Javadoc)
- * @see java.util.Collection#add(java.lang.Object)
- */
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Collection#add(java.lang.Object)
+ */
public boolean add(Object o)
{
throw new RuntimeException("not implemented");
}
- /* (non-Javadoc)
- * @see java.util.Collection#contains(java.lang.Object)
- */
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Collection#contains(java.lang.Object)
+ */
public boolean contains(Object o)
{
- return containsName(((SecurityEntity) o).getName());
+ if (o == null)
+ {
+ return false;
+ }
+ else
+ {
+ return containsName(((SecurityEntity) o).getName());
+ }
}
- /* (non-Javadoc)
- * @see java.util.Collection#remove(java.lang.Object)
- */
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Collection#remove(java.lang.Object)
+ */
public boolean remove(Object o)
{
throw new RuntimeException("not implemented");
}
- /* (non-Javadoc)
- * @see java.util.Collection#toArray(java.lang.Object[])
- */
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Collection#toArray(java.lang.Object[])
+ */
public Object[] toArray(Object[] a)
{
throw new RuntimeException("not implemented");
1.4 +2 -2 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/PermissionSet.java
Index: PermissionSet.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/PermissionSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PermissionSet.java 26 Aug 2003 01:57:29 -0000 1.3
+++ PermissionSet.java 5 Nov 2003 15:39:53 -0000 1.4
@@ -176,7 +176,7 @@
*/
public boolean contains(Permission permission)
{
- return nameMap.containsValue((Object) permission);
+ return super.contains(permission);
}
1.4 +4 -3 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity/UserSet.java
Index: UserSet.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity/UserSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserSet.java 26 Aug 2003 21:16:26 -0000 1.3
+++ UserSet.java 5 Nov 2003 15:39:53 -0000 1.4
@@ -163,7 +163,8 @@
}
/**
- * Checks whether this UserSet contains a User.
+ * Checks whether this UserSet contains a User based on the
+ * name of the User.
*
* @param user A User.
* @return True if this UserSet contains the User,
@@ -171,7 +172,7 @@
*/
public boolean contains(User user)
{
- return nameMap.containsValue((Object) user);
+ return super.contains(user);
}
1.3 +5 -2 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumAccessProvider.java
Index: FulcrumAccessProvider.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumAccessProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FulcrumAccessProvider.java 21 Oct 2003 10:16:29 -0000 1.2
+++ FulcrumAccessProvider.java 5 Nov 2003 15:39:53 -0000 1.3
@@ -59,6 +59,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.security.acl.AccessControlList;
+import org.apache.fulcrum.security.entity.Role;
import org.apache.fulcrum.security.entity.User;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.UnknownEntityException;
@@ -110,7 +111,9 @@
User user = getSecurityService().getUserManager().getUser(username);
AccessControlList acl =
getSecurityService().getUserManager().getACL(user);
- return acl.hasRole(acl.getRoles().getRoleByName(groupname));
+ Role role = acl.getRoles().getRoleByName(groupname);
+ boolean result =acl.hasRole(role);
+ return result;
}
catch (UnknownEntityException uee)
{
1.9 +4 -0 jakarta-turbine-fulcrum/security/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/xdocs/changes.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- changes.xml 4 Nov 2003 16:23:08 -0000 1.8
+++ changes.xml 5 Nov 2003 15:39:53 -0000 1.9
@@ -8,6 +8,10 @@
<body>
<release version="1.0-alpha-3" date="in cvs">
<action dev="epugh" type="fix">
+ All the various SecuritySet implementations base their logic off their Name, not the ID, or
+ Object type. Fixes problems with comparisons when you have various subclasses.
+ </action>
+ <action dev="epugh" type="fix">
For a SecurityEntityImpl, if the name is null then throw an InvalidParameterException.
</action>
<action dev="epugh" type="add">
1.2 +113 -83 jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/util/GroupSetTest.java
Index: GroupSetTest.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/util/GroupSetTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GroupSetTest.java 4 Nov 2003 16:23:08 -0000 1.1
+++ GroupSetTest.java 5 Nov 2003 15:39:53 -0000 1.2
@@ -1,74 +1,61 @@
package org.apache.fulcrum.security.util;
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
- * reserved.
- *
+/*
+ * ==================================================================== The
+ * Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-group documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * modification, are permitted provided that the following conditions are met: 1.
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. The end-group documentation
+ * included with the redistribution, if any, must include the following
+ * acknowledgment: "This product includes software developed by the Apache
+ * Software Foundation (http://www.apache.org/)." Alternately, this
+ * acknowledgment may appear in the software itself, if and wherever such
+ * third-party acknowledgments normally appear. 4. The names "Apache" and
+ * "Apache Software Foundation" and "Apache Turbine" must not be used to
+ * endorse or promote products derived from this software without prior written
+ * permission. For written permission, please contact apache@apache.org. 5.
+ * Products derived from this software may not be called "Apache", "Apache
+ * Turbine", nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/> .
*/
import org.apache.fulcrum.security.entity.Group;
import org.apache.fulcrum.security.model.simple.entity.SimpleGroup;
import org.apache.fulcrum.testcontainer.BaseUnitTest;
/**
- *
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id$
*/
public class GroupSetTest extends BaseUnitTest
{
-
+
/**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
+ * Defines the testcase name for JUnit.
+ *
+ * @param name the testcase's name.
+ */
public GroupSetTest(String name)
{
super(name);
@@ -77,31 +64,74 @@
{
junit.textui.TestRunner.run(GroupSetTest.class);
}
+
+ public void testNullGroup() throws Exception {
+ GroupSet groupSet = new GroupSet();
+ assertFalse(groupSet.contains(null));
+ }
- public void testAddGroups() throws Exception
- {
- Group group = new SimpleGroup();
- group.setId(new Integer(1));
- group.setName("Eric");
- GroupSet groupSet = new GroupSet();
- groupSet.add(group);
- assertTrue(groupSet.contains(group));
-
- Group group2 = new SimpleGroup();
- group2.setName("Kate");
- group2.setId(new Integer(2));
- groupSet.add(group2);
-
- Group group3 = new SimpleGroup();
- group3.setId(new Integer(1));
- group3.setName("Eric");
- assertTrue(groupSet.contains(group));
- assertTrue(groupSet.contains((Object) group));
- assertTrue(groupSet.contains(group2));
- assertFalse(groupSet.contains(group3));
- assertTrue(groupSet.contains(group));
-
- }
-
-
+ public void testAddGroups() throws Exception
+ {
+ Group group = new SimpleGroup();
+ group.setId(new Integer(1));
+ group.setName("Eric");
+ GroupSet groupSet = new GroupSet();
+ groupSet.add(group);
+ assertTrue(groupSet.contains(group));
+
+ Group group2 = new SimpleGroup();
+ group2.setName("Kate");
+ group2.setId(new Integer(2));
+ groupSet.add(group2);
+
+ Group group3 = new SimpleGroup();
+ group3.setId(new Integer(1));
+ group3.setName("Eric");
+ groupSet.add(group3);
+ assertTrue(groupSet.contains(group));
+ assertTrue(groupSet.contains((Object) group));
+ assertTrue(groupSet.contains(group2));
+ assertTrue(groupSet.contains(group3));
+ assertTrue(groupSet.contains(group));
+ }
+
+ public void testGroupSetWithSubclass() throws Exception
+ {
+ GroupSet groupSet = new GroupSet();
+ Group group = new GroupSubClass();
+ group.setId(new Integer(1));
+ group.setName("Eric");
+
+ groupSet.add(group);
+ assertTrue(groupSet.contains(group));
+
+ Group group2 = new SimpleGroup();
+ group2.setId(new Integer(1));
+ group2.setName("Eric");
+ assertTrue(groupSet.contains(group2));
+
+ }
+
+ class GroupSubClass extends SimpleGroup
+ {
+ private String extraGroupData;
+
+ /**
+ * @return Returns the extraGroupData.
+ */
+ public String getExtraGroupData()
+ {
+ return extraGroupData;
+ }
+
+ /**
+ * @param extraGroupData The extraGroupData to set.
+ */
+ public void setExtraGroupData(String extraGroupData)
+ {
+ this.extraGroupData = extraGroupData;
+ }
+
+ }
+
}
1.1 jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/util/SecuritySetTest.java
Index: SecuritySetTest.java
===================================================================
package org.apache.fulcrum.security.util;
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: 1.
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. The end-group documentation
* included with the redistribution, if any, must include the following
* acknowledgment: "This product includes software developed by the Apache
* Software Foundation (http://www.apache.org/)." Alternately, this
* acknowledgment may appear in the software itself, if and wherever such
* third-party acknowledgments normally appear. 4. The names "Apache" and
* "Apache Software Foundation" and "Apache Turbine" must not be used to
* endorse or promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org. 5.
* Products derived from this software may not be called "Apache", "Apache
* Turbine", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/> .
*/
import org.apache.fulcrum.testcontainer.BaseUnitTest;
/**
* Test using a securitySet. Useing various subclasses since it is
* Abstract.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id: SecuritySetTest.java,v 1.1 2003/11/05 15:39:53 epugh Exp $
*/
public class SecuritySetTest extends BaseUnitTest
{
/**
* Defines the testcase name for JUnit.
*
* @param name the testcase's name.
*/
public SecuritySetTest(String name)
{
super(name);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(SecuritySetTest.class);
}
public void testNull() throws Exception {
SecuritySet securitySet = new GroupSet();
assertFalse(securitySet.contains(null));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org