001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.community.mc.test;
014:
015: import java.util.Set;
016: import java.util.HashSet;
017: import junit.framework.*;
018: import com.sun.portal.community.mc.*;
019: import com.sun.portal.community.mc.impl.Debug;
020:
021: public class JdoCommunityUserTest extends JdoCommunityTest {
022: public JdoCommunityUserTest(String testName) {
023: super (testName);
024: }
025:
026: protected void setUp() throws java.lang.Exception {
027: super .setUp();
028: Debug.log("JdoCommunityUserTest", "setUp", "called");
029: }
030:
031: protected void tearDown() throws java.lang.Exception {
032: super .tearDown();
033: Debug.log("JdoCommunityUserTest", "tearDown", "called");
034: }
035:
036: public static junit.framework.Test suite() {
037: junit.framework.TestSuite suite = new junit.framework.TestSuite(
038: JdoCommunityUserTest.class);
039: return suite;
040: }
041:
042: public void testGetUserId() {
043: Debug.log("JdoCommunityUserTest", "testGetUserId", "called");
044:
045: String uid = xUser.getUserId();
046: assertNotNull(uid);
047: assertEquals(xUserName, uid);
048: }
049:
050: public void testGetMembership() {
051: Debug
052: .log("JdoCommunityUserTest", "testGetMembership",
053: "called");
054:
055: try {
056: // basic
057: createNodes();
058: Set all = xUser.getMembership();
059: assertEquals(0, all.size());
060:
061: addUsers();
062:
063: all = xUser.getMembership();
064: assertEquals(1, all.size());
065:
066: removeNodes();
067:
068: // community roles
069:
070: createNodes();
071:
072: all = xUser.getMembership();
073: assertEquals(0, all.size());
074:
075: addRoles();
076:
077: all = xUser.getMembership();
078: assertEquals(0, all.size());
079:
080: addUsers();
081:
082: all = xUser.getMembership();
083: assertEquals(2, all.size());
084:
085: removeNodes();
086: } catch (CMCException ce) {
087: Debug.log("JdoCommunityUserTest", "testGetMembership", ce);
088: fail(ce.getMessage());
089: }
090: }
091:
092: public void testGetAvailable() {
093: Debug.log("JdoCommunityUserTest", "testGetAvailable", "called");
094:
095: try {
096: Set avail = xUser.getAvailable();
097: assertEquals(0, avail.size());
098:
099: createNodes();
100:
101: avail = xUser.getAvailable();
102: assertEquals(1, avail.size());
103:
104: removeNodes();
105: } catch (CMCException ce) {
106: Debug.log("JdoCommunityUserTest", "testGetAvailable", ce);
107: fail(ce.getMessage());
108: }
109: }
110:
111: public void testHasRole() {
112: Debug.log("JdoCommunityUserTest", "testHasRole", "called");
113:
114: try {
115: createNodes();
116:
117: assertFalse(xUser.hasRole(cty1Cp,
118: CMCRolePrincipal.VISITOR_ROLE));
119: assertFalse(xUser.hasRole(cty1Cp,
120: CMCRolePrincipal.MEMBER_ROLE));
121: assertFalse(xUser.hasRole(cty1Cp,
122: CMCRolePrincipal.OWNER_ROLE));
123:
124: addUsers();
125:
126: assertTrue(xUser.hasRole(cty1Cp,
127: CMCRolePrincipal.VISITOR_ROLE));
128: assertFalse(xUser.hasRole(cty1Cp,
129: CMCRolePrincipal.MEMBER_ROLE));
130: assertFalse(xUser.hasRole(cty1Cp,
131: CMCRolePrincipal.OWNER_ROLE));
132:
133: assertTrue(vUser.hasRole(cty1Cp,
134: CMCRolePrincipal.INVITED_ROLE));
135: assertTrue(wUser.hasRole(cty1Cp,
136: CMCRolePrincipal.REJECTED_ROLE));
137: assertTrue(tUser.hasRole(cty1Cp,
138: CMCRolePrincipal.PENDING_ROLE));
139: assertTrue(uUser.hasRole(cty1Cp,
140: CMCRolePrincipal.BANNED_ROLE));
141:
142: removeNodes();
143: } catch (CMCException ce) {
144: Debug.log("JdoCommunityUserTest", "testHasRole", ce);
145: fail(ce.getMessage());
146: }
147: }
148:
149: public void testGetDPDocuments() {
150: Debug.log("JdoCommunityUserTest", "testGetDPDocuments",
151: "called");
152:
153: try {
154: // no-membership argument, basic
155:
156: createNodes();
157: addUsers();
158:
159: ConfigTable lastRead = new ConfigTable();
160: ConfigTable dpDocuments = xUser.getDPDocuments(lastRead);
161: assertEquals(0, dpDocuments.size());
162:
163: setDPDocuments();
164:
165: dpDocuments = xUser.getDPDocuments(lastRead);
166: assertEquals(1, dpDocuments.size());
167:
168: dpDocuments = xUser.getDPDocuments(lastRead);
169: assertEquals(0, dpDocuments.size());
170:
171: lastRead = new ConfigTable();
172: dpDocuments = yUser.getDPDocuments(lastRead);
173: assertEquals(1, dpDocuments.size());
174:
175: dpDocuments = yUser.getDPDocuments(lastRead);
176: assertEquals(0, dpDocuments.size());
177:
178: lastRead = new ConfigTable();
179: dpDocuments = zUser.getDPDocuments(lastRead);
180: assertEquals(2, dpDocuments.size());
181:
182: dpDocuments = zUser.getDPDocuments(lastRead);
183: assertEquals(0, dpDocuments.size());
184:
185: removeNodes();
186:
187: // no-membership argument, community role
188:
189: createNodes();
190:
191: addRoles();
192:
193: dpDocuments = xUser.getDPDocuments(lastRead);
194: assertEquals(0, dpDocuments.size());
195:
196: setDPDocuments();
197:
198: dpDocuments = xUser.getDPDocuments(lastRead);
199: assertEquals(1, dpDocuments.size());
200:
201: removeNodes();
202:
203: // membership argument, basic
204:
205: createNodes();
206: addUsers();
207:
208: setDPDocuments();
209:
210: lastRead = new ConfigTable();
211: Set membership = new HashSet();
212:
213: dpDocuments = xUser.getDPDocuments(lastRead, membership);
214: assertEquals(0, dpDocuments.size());
215:
216: membership = xUser.getMembership();
217: dpDocuments = xUser.getDPDocuments(lastRead, membership);
218: assertEquals(1, dpDocuments.size());
219:
220: dpDocuments = xUser.getDPDocuments(lastRead, membership);
221: assertEquals(0, dpDocuments.size());
222:
223: lastRead = new ConfigTable();
224: membership = yUser.getMembership();
225: dpDocuments = yUser.getDPDocuments(lastRead, membership);
226: assertEquals(1, dpDocuments.size());
227:
228: dpDocuments = yUser.getDPDocuments(lastRead, membership);
229: assertEquals(0, dpDocuments.size());
230:
231: lastRead = new ConfigTable();
232: membership = zUser.getMembership();
233: dpDocuments = zUser.getDPDocuments(lastRead, membership);
234: assertEquals(2, dpDocuments.size());
235:
236: dpDocuments = zUser.getDPDocuments(lastRead, membership);
237: assertEquals(0, dpDocuments.size());
238:
239: removeNodes();
240:
241: // membership argument, community roles
242:
243: createNodes();
244: addRoles();
245:
246: lastRead = new ConfigTable();
247: membership = xUser.getMembership();
248: dpDocuments = xUser.getDPDocuments(lastRead, membership);
249: assertEquals(0, dpDocuments.size());
250:
251: setDPDocuments();
252:
253: lastRead = new ConfigTable();
254: membership = xUser.getMembership();
255: dpDocuments = xUser.getDPDocuments(lastRead, membership);
256: assertEquals(0, dpDocuments.size());
257:
258: addUsers();
259:
260: lastRead = new ConfigTable();
261: membership = xUser.getMembership();
262: dpDocuments = xUser.getDPDocuments(lastRead, membership);
263: assertEquals(2, dpDocuments.size());
264:
265: removeNodes();
266:
267: } catch (CMCException ce) {
268: Debug.log("JdoCommunityUserTest", "testGetDPDocuments", ce);
269: fail(ce.getMessage());
270: }
271: }
272:
273: public void testGetMembershipByName() {
274: Debug.log("JdoCommunityUserTest", "testGetMembershipByName",
275: "called");
276:
277: try {
278: createNodes();
279: Set all = xUser.getMembershipByName();
280: Debug.log("JdoCommunityUserTest",
281: "testGetMembershipByName", "all=" + all);
282: assertEquals(0, all.size());
283:
284: addUsers();
285:
286: all = xUser.getMembershipByName();
287: assertEquals(1, all.size());
288:
289: addRoles();
290:
291: all = xUser.getMembershipByName();
292: assertEquals(1, all.size());
293:
294: removeNodes();
295: } catch (CMCException ce) {
296: Debug.log("JdoCommunityUserTest",
297: "testGetMembershipByName", ce);
298: fail(ce.getMessage());
299: }
300: }
301:
302: public void testGetMembershipByRole() {
303: Debug.log("JdoCommunityUserTest", "testGetMembershipByRole",
304: "called");
305:
306: try {
307: createNodes();
308:
309: Set all = xUser.getMembershipByRole();
310: Debug.log("JdoCommunityUserTest",
311: "testGetMembershipByRole", "all=" + all);
312: assertEquals(0, all.size());
313:
314: addUsers();
315:
316: all = xUser.getMembershipByRole();
317: assertEquals(0, all.size());
318:
319: addRoles();
320:
321: all = xUser.getMembershipByRole();
322: assertEquals(1, all.size());
323:
324: removeNodes();
325: } catch (CMCException ce) {
326: Debug.log("JdoCommunityUserTest",
327: "testGetMembershipByRole", ce);
328: fail(ce.getMessage());
329: }
330: }
331:
332: public void testGetRoleCreationTime() {
333: Debug.log("JdoCommunityUserTest", "testGetRoleCreationTime",
334: "called");
335:
336: try {
337: createNodes();
338: addUsers();
339: long time = zUser.getRoleCreationTime(cty1Cp,
340: CMCRolePrincipal.MEMBER_ROLE);
341: assertTrue(time != -1);
342: assertTrue(time != 0);
343: removeNodes();
344:
345: } catch (UnsupportedOperationException ce) {
346: fail("unsupported testGetRoleCreationTime");
347: } catch (CMCException ce) {
348: Debug.log("JdoCommunityUserTest",
349: "testGetRoleCreationTime", ce);
350: fail(ce.getMessage());
351: }
352: }
353: }
|