001: package com.ecyrd.jspwiki.auth.permissions;
002:
003: import junit.framework.TestCase;
004:
005: /**
006: * @author Andrew Jaquith
007: */
008: public class WikiPermissionTest extends TestCase {
009:
010: public void testHashCode() {
011: }
012:
013: public void testWikiPermission() {
014: WikiPermission p = new WikiPermission("*", "createPages");
015: assertEquals("*", p.getName());
016: assertEquals("*", p.getWiki());
017: assertEquals("createpages", p.getActions());
018: }
019:
020: /*
021: * Class under test for boolean equals(Object)
022: */
023: public void testEqualsObject() {
024: WikiPermission p1 = new WikiPermission("*", "createPages");
025: WikiPermission p2 = new WikiPermission("*", "createPages");
026: WikiPermission p3 = new WikiPermission("*", "createGroups");
027: assertTrue(p1.equals(p2));
028: assertTrue(p2.equals(p1));
029: assertFalse(p1.equals(p3));
030: assertFalse(p3.equals(p1));
031: WikiPermission p4 = new WikiPermission("*",
032: "createPages,createGroups");
033: WikiPermission p5 = new WikiPermission("*",
034: "createGroups,createPages");
035: assertTrue(p4.equals(p5));
036: }
037:
038: /*
039: * Class under test for boolean equals(Object)
040: */
041: public void testEqualsObjectNSi() {
042: WikiPermission p1 = new WikiPermission("mywiki", "createPages");
043: WikiPermission p2 = new WikiPermission("*", "createPages");
044: WikiPermission p3 = new WikiPermission("mywiki", "createGroups");
045: assertFalse(p1.equals(p2));
046: assertFalse(p2.equals(p1));
047: assertFalse(p1.equals(p3));
048: assertFalse(p3.equals(p1));
049: WikiPermission p4 = new WikiPermission("mywiki",
050: "createPages,createGroups");
051: WikiPermission p5 = new WikiPermission("*",
052: "createGroups,createPages");
053: assertFalse(p4.equals(p5));
054: }
055:
056: /*
057: * Class under test for String getActions()
058: */
059: public void testGetActions() {
060: WikiPermission p1 = new WikiPermission("*",
061: "createPages,createGroups,editProfile");
062: assertEquals("creategroups,createpages,editprofile", p1
063: .getActions());
064: WikiPermission p2 = new WikiPermission("*",
065: "createGroups,editProfile,createPages");
066: assertEquals("creategroups,createpages,editprofile", p2
067: .getActions());
068: }
069:
070: /*
071: * Class under test for boolean implies(Permission)
072: */
073: public void testImpliesPermission() {
074: // Superset of actions implies all individual actions
075: WikiPermission p1 = new WikiPermission("*",
076: "createPages,createGroups,editProfile");
077: WikiPermission p2 = new WikiPermission("*", "createPages");
078: WikiPermission p3 = new WikiPermission("*", "createGroups");
079: WikiPermission p5 = new WikiPermission("*", "editPreferences");
080: WikiPermission p6 = new WikiPermission("*", "editProfile");
081: assertTrue(p1.implies(p2));
082: assertFalse(p2.implies(p1));
083: assertTrue(p1.implies(p3));
084: assertFalse(p3.implies(p1));
085: assertTrue(p1.implies(p6));
086: assertFalse(p6.implies(p1));
087:
088: // createGroups implies createPages
089: assertTrue(p3.implies(p2));
090: assertFalse(p2.implies(p3));
091:
092: // editProfile implies nothing
093: assertFalse(p6.implies(p5));
094: assertFalse(p6.implies(p3));
095: assertFalse(p6.implies(p3));
096: assertFalse(p6.implies(p1));
097: }
098:
099: /*
100: * Class under test for boolean implies(Permission)
101: */
102: public void testImpliesPermissionNS() {
103: // Superset of actions implies all individual actions
104: WikiPermission p1 = new WikiPermission("*",
105: "createPages,createGroups,editProfile");
106: WikiPermission p2 = new WikiPermission("mywiki", "createPages");
107: WikiPermission p3 = new WikiPermission("mywiki", "createGroups");
108: WikiPermission p4 = new WikiPermission("urwiki", "editProfile");
109: WikiPermission p5 = new WikiPermission("*", "editPreferences");
110: assertTrue(p1.implies(p2));
111: assertFalse(p2.implies(p1));
112: assertTrue(p1.implies(p3));
113: assertFalse(p3.implies(p1));
114: assertTrue(p1.implies(p4));
115: assertFalse(p4.implies(p1));
116:
117: // createGroups implies createPages
118: assertTrue(p3.implies(p2));
119: assertFalse(p2.implies(p3));
120:
121: // editPreferences does not imply editProfile
122: assertFalse(p5.implies(p4));
123: assertFalse(p4.implies(p5));
124: }
125:
126: /*
127: * Class under test for String toString()
128: */
129: public void testToString() {
130: WikiPermission p1 = new WikiPermission("*",
131: "createPages,createGroups,editProfile");
132: String result = "(\"com.ecyrd.jspwiki.auth.permissions.WikiPermission\",\"*\",\"creategroups,createpages,editprofile\")";
133: assertEquals(result, p1.toString());
134: }
135:
136: public void testImpliedMask() {
137: assertEquals(3, WikiPermission.impliedMask(1));
138: assertEquals(2, WikiPermission.impliedMask(2));
139: assertEquals(4, WikiPermission.impliedMask(4));
140: }
141:
142: public void testCreateMask() {
143: assertEquals(1, WikiPermission.createMask("createGroups"));
144: assertEquals(2, WikiPermission.createMask("createPages"));
145: assertEquals(3, WikiPermission
146: .createMask("createGroups,createPages"));
147: assertEquals(4, WikiPermission.createMask("editPreferences"));
148: assertEquals(5, WikiPermission
149: .createMask("createGroups,editPreferences"));
150: assertEquals(6, WikiPermission
151: .createMask("createPages,editPreferences"));
152: assertEquals(7, WikiPermission
153: .createMask("createGroups,createPages,editPreferences"));
154: assertEquals(8, WikiPermission.createMask("editProfile"));
155: assertEquals(9, WikiPermission
156: .createMask("createGroups,editProfile"));
157: assertEquals(16, WikiPermission.createMask("login"));
158: assertEquals(24, WikiPermission.createMask("login,editProfile"));
159: }
160:
161: }
|