001: /**
002: * $Id: FileDynamicCommunityUserTest.java,v 1.3 2007/01/26 03:47:55 portalbld Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.community.mc.test;
014:
015: import java.util.HashSet;
016: import junit.framework.*;
017: import java.util.Set;
018: import com.sun.portal.community.mc.*;
019: import com.sun.portal.community.mc.impl.Debug;
020:
021: public class FileDynamicCommunityUserTest extends
022: FileDynamicCommunityTest {
023: public FileDynamicCommunityUserTest(String testName) {
024: super (testName);
025: }
026:
027: protected void setUp() throws java.lang.Exception {
028: super .setUp();
029: Debug.log("FileDynamicCommunityUserTest", "setUp", "called");
030: }
031:
032: protected void tearDown() throws java.lang.Exception {
033: super .tearDown();
034: Debug.log("FileDynamicCommunityUserTest", "tearDown", "called");
035: }
036:
037: public static junit.framework.Test suite() {
038: junit.framework.TestSuite suite = new junit.framework.TestSuite(
039: FileDynamicCommunityUserTest.class);
040: return suite;
041: }
042:
043: public void testGetUserId() {
044: Debug.log("FileDynamicCommunityUserTest", "testGetUserId",
045: "called");
046:
047: String uid = xUser.getUserId();
048: assertNotNull(uid);
049: assertEquals(xUserName, uid);
050: }
051:
052: public void testGetMembership() {
053: Debug.log("FileDynamicCommunityUserTest", "testGetMembership",
054: "called");
055:
056: try {
057: createNodes();
058: Set all = xUser.getMembership();
059: Debug.log("FileDynamicCommunityUserTest",
060: "testGetMembership", "all=" + all);
061: assertEquals(0, all.size());
062:
063: addUsers();
064:
065: all = xUser.getMembership();
066: assertEquals(1, all.size());
067:
068: addRoles();
069: all = xUser.getMembership();
070: assertEquals(2, all.size());
071:
072: removeNodes();
073: } catch (CMCException ce) {
074: Debug.log("FileDynamicCommunityUserTest",
075: "testGetMembership", ce);
076: fail(ce.getMessage());
077: }
078: }
079:
080: public void testGetMembershipByName() {
081: Debug.log("FileDynamicCommunityUserTest",
082: "testGetMembershipByName", "called");
083:
084: try {
085: createNodes();
086: Set all = xUser.getMembershipByName();
087: Debug.log("FileDynamicCommunityUserTest",
088: "testGetMembershipByName", "all=" + all);
089: assertEquals(0, all.size());
090:
091: addUsers();
092:
093: all = xUser.getMembershipByName();
094: assertEquals(1, all.size());
095:
096: addRoles();
097: all = xUser.getMembershipByName();
098: assertEquals(1, all.size());
099:
100: removeNodes();
101: } catch (CMCException ce) {
102: Debug.log("FileDynamicCommunityUserTest",
103: "testGetMembershipByName", ce);
104: fail(ce.getMessage());
105: }
106: }
107:
108: public void testGetMembershipByRole() {
109: Debug.log("FileDynamicCommunityUserTest",
110: "testGetMembershipByRole", "called");
111:
112: try {
113: createNodes();
114: Set all = xUser.getMembershipByRole();
115: Debug.log("FileDynamicCommunityUserTest",
116: "testGetMembershipByRole", "all=" + all);
117: assertEquals(0, all.size());
118:
119: addUsers();
120:
121: all = xUser.getMembershipByRole();
122: assertEquals(0, all.size());
123:
124: addRoles();
125: all = xUser.getMembershipByRole();
126: assertEquals(1, all.size());
127:
128: removeNodes();
129: } catch (CMCException ce) {
130: Debug.log("FileDynamicCommunityUserTest",
131: "testGetMembershipByRole", ce);
132: fail(ce.getMessage());
133: }
134: }
135:
136: public void testGetAvailable() {
137: Debug.log("FileDynamicCommunityUserTest", "testGetAvailable",
138: "called");
139:
140: try {
141: createNodes();
142: Set avail = xUser.getAvailable();
143: System.out.println("avail=" + avail);
144: assertEquals(2, avail.size());
145: removeNodes();
146: } catch (CMCException ce) {
147: Debug.log("FileDynamicCommunityUserTest",
148: "testGetAvailable", ce);
149: fail(ce.getMessage());
150: }
151: }
152:
153: public void testHasRole() {
154: Debug.log("FileDynamicCommunityUserTest", "testHasRole",
155: "called");
156:
157: try {
158: createNodes();
159:
160: assertFalse(xUser.hasRole(role1Cp,
161: CMCRolePrincipal.VISITOR_ROLE));
162: assertFalse(xUser.hasRole(role1Cp,
163: CMCRolePrincipal.MEMBER_ROLE));
164: assertFalse(xUser.hasRole(role1Cp,
165: CMCRolePrincipal.OWNER_ROLE));
166:
167: addUsers();
168:
169: assertTrue(xUser.hasRole(role1Cp,
170: CMCRolePrincipal.VISITOR_ROLE));
171: assertFalse(xUser.hasRole(role1Cp,
172: CMCRolePrincipal.MEMBER_ROLE));
173: assertFalse(xUser.hasRole(role1Cp,
174: CMCRolePrincipal.OWNER_ROLE));
175:
176: removeNodes();
177:
178: createNodes();
179:
180: assertFalse(xUser.hasRole(role1Cp,
181: CMCRolePrincipal.DISABLED_ROLE));
182:
183: addRoles();
184:
185: assertTrue(xUser.hasRole(role1Cp,
186: CMCRolePrincipal.DISABLED_ROLE));
187: } catch (CMCException ce) {
188: Debug
189: .log("FileDynamicCommunityUserTest", "testHasRole",
190: ce);
191: fail(ce.getMessage());
192: }
193: }
194:
195: public void testGetDPDocuments() {
196: Debug.log("FileDynamicCommunityUserTest", "testGetDPDocuments",
197: "called");
198:
199: try {
200: createNodes();
201: addUsers();
202:
203: ConfigTable lastRead = new ConfigTable();
204: ConfigTable dpDocuments = xUser.getDPDocuments(lastRead);
205: assertEquals(0, dpDocuments.size());
206:
207: setDPDocuments();
208: dpDocuments = xUser.getDPDocuments(lastRead);
209: assertEquals(1, dpDocuments.size());
210:
211: removeNodes();
212: } catch (CMCException ce) {
213: Debug.log("FileDynamicCommunityUserTest",
214: "testGetDPDocuments", ce);
215: fail(ce.getMessage());
216: }
217: }
218: }
|