001: package com.ecyrd.jspwiki.auth.authorize;
002:
003: import java.security.Principal;
004: import java.util.Properties;
005:
006: import junit.framework.Test;
007: import junit.framework.TestCase;
008: import junit.framework.TestSuite;
009:
010: import com.ecyrd.jspwiki.TestEngine;
011: import com.ecyrd.jspwiki.WikiEngine;
012: import com.ecyrd.jspwiki.auth.WikiPrincipal;
013:
014: public class GroupTest extends TestCase {
015: Group m_group;
016: String m_wiki;
017:
018: public GroupTest(String s) {
019: super (s);
020: }
021:
022: public void setUp() throws Exception {
023: Properties props = new Properties();
024: props.load(TestEngine.findTestProperties());
025: WikiEngine engine = new TestEngine(props);
026: m_wiki = engine.getApplicationName();
027:
028: m_group = new Group("TestGroup", m_wiki);
029: }
030:
031: public void testAdd1() {
032: Principal u1 = new WikiPrincipal("Alice");
033: m_group.add(u1);
034: assertTrue(m_group.isMember(u1));
035: }
036:
037: public void testAdd2() {
038: Principal u1 = new WikiPrincipal("Alice");
039: Principal u2 = new WikiPrincipal("Bob");
040:
041: assertTrue("adding alice", m_group.add(u1));
042:
043: assertTrue("adding bob", m_group.add(u2));
044:
045: assertTrue("Alice", m_group.isMember(u1));
046: assertTrue("Bob", m_group.isMember(u2));
047: }
048:
049: /**
050: * Check that different objects match as well.
051: */
052: public void testAdd3() {
053: Principal u1 = new WikiPrincipal("Alice");
054: Principal u2 = new WikiPrincipal("Bob");
055: Principal u3 = new WikiPrincipal("Bob");
056:
057: assertTrue("adding alice", m_group.add(u1));
058: assertTrue("adding bob", m_group.add(u2));
059:
060: assertTrue("Alice", m_group.isMember(u1));
061: assertTrue("Bob", m_group.isMember(u3));
062: }
063:
064: public void testRemove() {
065: Principal u1 = new WikiPrincipal("Alice");
066: Principal u2 = new WikiPrincipal("Bob");
067: Principal u3 = new WikiPrincipal("Bob");
068:
069: m_group.add(u1);
070: m_group.add(u2);
071:
072: m_group.remove(u3);
073:
074: assertTrue("Alice", m_group.isMember(u1));
075: assertFalse("Bob", m_group.isMember(u2));
076: assertFalse("Bob 2", m_group.isMember(u3));
077: }
078:
079: public void testEquals1() {
080: Principal u1 = new WikiPrincipal("Alice");
081: Principal u2 = new WikiPrincipal("Bob");
082:
083: m_group.add(u1);
084: m_group.add(u2);
085:
086: Group group2 = new Group("TestGroup", m_wiki);
087: Principal u3 = new WikiPrincipal("Alice");
088: Principal u4 = new WikiPrincipal("Bob");
089:
090: group2.add(u3);
091: group2.add(u4);
092:
093: assertTrue(m_group.equals(group2));
094: }
095:
096: public void testEquals2() {
097: Principal u1 = new WikiPrincipal("Alice");
098: Principal u2 = new WikiPrincipal("Bob");
099:
100: m_group.add(u1);
101: m_group.add(u2);
102:
103: Group group2 = new Group("Group2", m_wiki);
104: Principal u3 = new WikiPrincipal("Alice");
105: Principal u4 = new WikiPrincipal("Charlie");
106:
107: group2.add(u3);
108: group2.add(u4);
109:
110: assertFalse(m_group.equals(group2));
111: }
112:
113: public void testEquals3() {
114: Group group1 = new Group("Blib", m_wiki);
115: Principal u1 = new WikiPrincipal("Alice");
116: Principal u2 = new WikiPrincipal("Bob");
117: group1.add(u1);
118: group1.add(u2);
119:
120: Group group2 = new Group("Blib", m_wiki);
121: Principal u3 = new WikiPrincipal("Alice");
122: Principal u4 = new WikiPrincipal("Bob");
123: group2.add(u3);
124: group2.add(u4);
125:
126: assertTrue(group1.equals(group2));
127: }
128:
129: public void testEquals4() {
130: Group group1 = new Group("BlibBlab", m_wiki);
131: Principal u1 = new WikiPrincipal("Alice");
132: Principal u2 = new WikiPrincipal("Bob");
133: group1.add(u1);
134: group1.add(u2);
135:
136: Group group2 = new Group("Blib", m_wiki);
137: Principal u3 = new WikiPrincipal("Alice");
138: Principal u4 = new WikiPrincipal("Bob");
139: group2.add(u3);
140: group2.add(u4);
141:
142: assertFalse(m_group.equals(group2));
143: }
144:
145: public static Test suite() {
146: return new TestSuite(GroupTest.class);
147: }
148:
149: }
|