001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015: package org.acegisecurity.acls.domain;
016:
017: import junit.framework.TestCase;
018:
019: import org.acegisecurity.acls.Permission;
020:
021: /**
022: * Tests BasePermission and CumulativePermission.
023: *
024: * @author Ben Alex
025: * @version $Id: PermissionTests.java 1754 2006-11-17 02:01:21Z benalex ${date}
026: */
027: public class PermissionTests extends TestCase {
028: //~ Methods ========================================================================================================
029:
030: public void testExpectedIntegerValues() {
031: assertEquals(1, BasePermission.READ.getMask());
032: assertEquals(16, BasePermission.ADMINISTRATION.getMask());
033: assertEquals(7, new CumulativePermission().set(
034: BasePermission.READ).set(BasePermission.WRITE).set(
035: BasePermission.CREATE).getMask());
036: assertEquals(17, new CumulativePermission().set(
037: BasePermission.READ).set(BasePermission.ADMINISTRATION)
038: .getMask());
039: }
040:
041: public void testFromInteger() {
042: Permission permission = BasePermission.buildFromMask(7);
043: System.out.println("7 = " + permission.toString());
044: permission = BasePermission.buildFromMask(4);
045: System.out.println("4 = " + permission.toString());
046: }
047:
048: public void testStringConversion() {
049: System.out.println("R = " + BasePermission.READ.toString());
050: assertEquals(
051: "BasePermission[...............................R=1]",
052: BasePermission.READ.toString());
053:
054: System.out.println("A = "
055: + BasePermission.ADMINISTRATION.toString());
056: assertEquals(
057: "BasePermission[...........................A....=16]",
058: BasePermission.ADMINISTRATION.toString());
059:
060: System.out.println("R = "
061: + new CumulativePermission().set(BasePermission.READ)
062: .toString());
063: assertEquals(
064: "CumulativePermission[...............................R=1]",
065: new CumulativePermission().set(BasePermission.READ)
066: .toString());
067:
068: System.out.println("A = "
069: + new CumulativePermission().set(
070: BasePermission.ADMINISTRATION).toString());
071: assertEquals(
072: "CumulativePermission[...........................A....=16]",
073: new CumulativePermission().set(
074: BasePermission.ADMINISTRATION).toString());
075:
076: System.out.println("RA = "
077: + new CumulativePermission().set(
078: BasePermission.ADMINISTRATION).set(
079: BasePermission.READ).toString());
080: assertEquals(
081: "CumulativePermission[...........................A...R=17]",
082: new CumulativePermission().set(
083: BasePermission.ADMINISTRATION).set(
084: BasePermission.READ).toString());
085:
086: System.out.println("R = "
087: + new CumulativePermission().set(
088: BasePermission.ADMINISTRATION).set(
089: BasePermission.READ).clear(
090: BasePermission.ADMINISTRATION).toString());
091: assertEquals(
092: "CumulativePermission[...............................R=1]",
093: new CumulativePermission().set(
094: BasePermission.ADMINISTRATION).set(
095: BasePermission.READ).clear(
096: BasePermission.ADMINISTRATION).toString());
097:
098: System.out.println("0 = "
099: + new CumulativePermission().set(
100: BasePermission.ADMINISTRATION).set(
101: BasePermission.READ).clear(
102: BasePermission.ADMINISTRATION).clear(
103: BasePermission.READ).toString());
104: assertEquals(
105: "CumulativePermission[................................=0]",
106: new CumulativePermission().set(
107: BasePermission.ADMINISTRATION).set(
108: BasePermission.READ).clear(
109: BasePermission.ADMINISTRATION).clear(
110: BasePermission.READ).toString());
111: }
112: }
|