001: /**
002: * $Id: FileDynamicCommunityNodeTest.java,v 1.4 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.Collections;
016: import java.util.HashSet;
017: import junit.framework.*;
018: import java.util.*;
019: import java.util.regex.*;
020:
021: import com.sun.portal.community.mc.*;
022: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
023: import com.sun.portal.community.mc.impl.Debug;
024:
025: import java.io.UnsupportedEncodingException;
026:
027: public class FileDynamicCommunityNodeTest extends
028: FileDynamicCommunityTest {
029: public FileDynamicCommunityNodeTest(String testName) {
030: super (testName);
031: }
032:
033: protected void setUp() throws java.lang.Exception {
034: super .setUp();
035: Debug.log("FileDynamicCommunityNodeTest", "setUp", "called");
036: }
037:
038: protected void tearDown() throws java.lang.Exception {
039: super .tearDown();
040: Debug.log("FileDynamicCommunityNodeTest", "tearDown", "called");
041: /*
042: try {
043: if (role1Node.exists()) {
044: role1Node.remove();
045: }
046: } catch (CommunityException ce) {
047: Debug.log("FileDynamicCommunityNodeTest", "testGetCommunityPrincipal", ce);
048: fail(ce.getMessage());
049: }
050: */
051: }
052:
053: public static Test suite() {
054: TestSuite suite = new TestSuite(
055: FileDynamicCommunityNodeTest.class);
056: return suite;
057: }
058:
059: public void testGetCommunityPrincipal() {
060: Debug.log("FileDynamicCommunityNodeTest",
061: "testGetCommunityPrincipal", "called");
062:
063: try {
064: CMCPrincipal cp = role1Node.getCMCPrincipal();
065: assertNotNull(cp);
066: assertEquals(role1Cp, cp);
067: } catch (CMCException ce) {
068: Debug.log("FileDynamicCommunityNodeTest",
069: "testGetCommunityPrincipal", ce);
070: fail(ce.getMessage());
071: }
072: }
073:
074: public void testCreate() {
075: Debug.log("FileDynamicCommunityNodeTest", "testCreate",
076: "called");
077:
078: try {
079: createNodes();
080: removeNodes();
081: } catch (CMCException ce) {
082: Debug.log("FileDynamicCommunityNodeTest", "testCreate", ce);
083: fail(ce.getMessage());
084: }
085: }
086:
087: public void testSupportsCreate() {
088: try {
089: Debug.log("FileDynamicCommunityNodeTest",
090: "testSupportsCreate", "called");
091: assertTrue(role1Node.supportsCreate());
092: } catch (CMCException ce) {
093: Debug.log("FileDynamicCommunityNodeTest",
094: "testSupportsCreate", ce);
095: fail(ce.getMessage());
096: }
097: }
098:
099: public void testExists() {
100: Debug.log("FileDynamicCommunityNodeTest", "testExists",
101: "called");
102:
103: try {
104: assertFalse(role1Node.exists());
105: createNodes();
106: assertTrue(role1Node.exists());
107: removeNodes();
108: } catch (CMCException ce) {
109: Debug.log("FileDynamicCommunityNodeTest", "testExists", ce);
110: fail(ce.getMessage());
111: }
112: }
113:
114: public void testAddUsers() {
115: Debug.log("FileDynamicCommunityNodeTest", "testAddUsers",
116: "called");
117:
118: try {
119: createNodes();
120: addUsers();
121: removeNodes();
122: } catch (CMCException ce) {
123: Debug.log("FileDynamicCommunityNodeTest", "testAddUsers",
124: ce);
125: fail(ce.getMessage());
126: }
127: }
128:
129: public void testAddRole() {
130: Debug.log("FileDynamicCommunityNodeTest", "testAddRole",
131: "called");
132:
133: try {
134: createNodes();
135: addRoles();
136: removeNodes();
137: } catch (CMCException ce) {
138: Debug
139: .log("FileDynamicCommunityNodeTest", "testAddRole",
140: ce);
141: fail(ce.getMessage());
142: }
143: }
144:
145: public void testGetUsers() {
146: Debug.log("FileDynamicCommunityNodeTest", "testGetUsers",
147: "called");
148:
149: try {
150: createNodes();
151:
152: Set allUsers = role1Node.getUsers();
153: assertEquals(0, allUsers.size());
154:
155: Set visitorUsers = role1Node.getUsers(Collections
156: .singleton(CMCRolePrincipal.VISITOR_ROLE));
157: assertEquals(0, visitorUsers.size());
158:
159: Set memberUsers = role1Node.getUsers(Collections
160: .singleton(CMCRolePrincipal.MEMBER_ROLE));
161: assertEquals(0, memberUsers.size());
162:
163: Set ownerUsers = role1Node.getUsers(Collections
164: .singleton(CMCRolePrincipal.OWNER_ROLE));
165: assertEquals(0, ownerUsers.size());
166:
167: removeNodes();
168: createNodes();
169: addUsers();
170:
171: allUsers = role1Node.getUsers();
172: assertEquals(3, allUsers.size());
173:
174: visitorUsers = role1Node.getUsers(Collections
175: .singleton(CMCRolePrincipal.VISITOR_ROLE));
176: assertEquals(1, visitorUsers.size());
177:
178: memberUsers = role1Node.getUsers(Collections
179: .singleton(CMCRolePrincipal.MEMBER_ROLE));
180: assertEquals(2, memberUsers.size());
181:
182: ownerUsers = role1Node.getUsers(Collections
183: .singleton(CMCRolePrincipal.OWNER_ROLE));
184: assertEquals(1, ownerUsers.size());
185:
186: removeNodes();
187: } catch (CMCException ce) {
188: Debug.log("FileDynamicCommunityNodeTest", "testGetUsers",
189: ce);
190: fail(ce.getMessage());
191: }
192: }
193:
194: public void testGetUserPatterns() {
195: Debug.log("FileDynamicCommunityNodeTest", "testGetRoles",
196: "called");
197:
198: try {
199: createNodes();
200:
201: Set roles = role1Node.getRoles();
202: assertEquals(0, roles.size());
203:
204: addRoles();
205:
206: roles = role1Node.getRoles();
207: assertEquals(1, roles.size());
208:
209: removeNodes();
210: } catch (CMCException ce) {
211: Debug.log("FileDynamicCommunityNodeTest", "testGetUsers",
212: ce);
213: fail(ce.getMessage());
214: }
215: }
216:
217: public void testSupportsAddUsers() {
218: try {
219: Debug.log("FileDynamicCommunityNodeTest",
220: "testSupportsAddUsers", "called");
221: assertTrue(role1Node.supportsAddUsers());
222: } catch (CMCException ce) {
223: Debug.log("FileDynamicCommunityNodeTest",
224: "testSupportsAddUsers", ce);
225: fail(ce.getMessage());
226: }
227: }
228:
229: public void testSupportsAddRole() {
230: try {
231: Debug.log("FileDynamicCommunityNodeTest",
232: "testSupportsAddRole", "called");
233: assertTrue(role1Node.supportsAddRole());
234: } catch (CMCException ce) {
235: Debug.log("FileDynamicCommunityNodeTest",
236: "testSupportsAddRole", ce);
237: fail(ce.getMessage());
238: }
239: }
240:
241: public void testRemoveUsers() {
242: Debug.log("FileDynamicCommunityNodeTest", "testRemoveUsers",
243: "called");
244:
245: try {
246: createNodes();
247: addUsers();
248:
249: assertEquals(3, role1Node.getUsers().size());
250:
251: Set users = new HashSet();
252: users.add(xUserName);
253:
254: Set rps = new HashSet();
255: rps.add(CMCRolePrincipal.VISITOR_ROLE);
256:
257: role1Node.removeUsers(users, rps);
258: assertEquals(2, role1Node.getUsers().size());
259:
260: rps.add(CMCRolePrincipal.MEMBER_ROLE);
261: role1Node.removeUsers(users, rps);
262:
263: assertEquals(2, role1Node.getUsers().size());
264:
265: users.add(yUserName);
266: role1Node.removeUsers(users, rps);
267: assertEquals(1, role1Node.getUsers().size());
268:
269: users.add(zUserName);
270: role1Node.removeUsers(users, rps);
271: assertEquals(1, role1Node.getUsers().size());
272:
273: rps.add(CMCRolePrincipal.OWNER_ROLE);
274: role1Node.removeUsers(users, rps);
275: assertEquals(0, role1Node.getUsers().size());
276:
277: removeNodes();
278: } catch (CMCException ce) {
279: Debug.log("FileDynamicCommunityNodeTest", "testAddUsers",
280: ce);
281: fail(ce.getMessage());
282: }
283: }
284:
285: public void testRemoveRole() {
286: Debug.log("FileDynamicCommunityNodeTest", "testRemoveRole",
287: "called");
288:
289: try {
290: createNodes();
291: addRoles();
292:
293: assertEquals(1, role1Node.getRoles().size());
294:
295: removeRoles();
296:
297: assertEquals(0, role1Node.getRoles().size());
298:
299: removeNodes();
300: } catch (CMCException ce) {
301: Debug.log("FileDynamicCommunityNodeTest", "testRemoveRole",
302: ce);
303: fail(ce.getMessage());
304: }
305: }
306:
307: public void testSupportsRemoveUsers() {
308: try {
309: Debug.log("FileDynamicCommunityNodeTest",
310: "testSupportsRemoveUsers", "called");
311: assertTrue(role1Node.supportsRemoveUsers());
312: } catch (CMCException ce) {
313: Debug.log("FileDynamicCommunityNodeTest",
314: "testSupportsRemoveUsers", ce);
315: fail(ce.getMessage());
316: }
317: }
318:
319: public void testSupportsRemoveRole() {
320: try {
321: Debug.log("FileDynamicCommunityNodeTest",
322: "testSupportsRemoveRole", "called");
323: assertTrue(role1Node.supportsRemoveRole());
324: } catch (CMCException ce) {
325: Debug.log("FileDynamicCommunityNodeTest",
326: "testSupportsRemoveRole", ce);
327: fail(ce.getMessage());
328: }
329: }
330:
331: public void testSupportsRole() {
332: try {
333: Debug.log("FileDynamicCommunityNodeTest",
334: "testSupportsRole", "called");
335: assertTrue(role1Node
336: .supportsRole(CMCRolePrincipal.VISITOR_ROLE));
337: assertTrue(role1Node
338: .supportsRole(CMCRolePrincipal.MEMBER_ROLE));
339: assertTrue(role1Node
340: .supportsRole(CMCRolePrincipal.OWNER_ROLE));
341: } catch (CMCException ce) {
342: Debug.log("FileDynamicCommunityNodeTest",
343: "testSupportsRole", ce);
344: fail(ce.getMessage());
345: }
346: }
347:
348: public void testRemove() {
349: Debug.log("FileDynamicCommunityNodeTest", "testRemove",
350: "called");
351:
352: try {
353: createNodes();
354: removeNodes();
355: assertFalse(role1Node.exists());
356: } catch (CMCException ce) {
357: Debug.log("FileDynamicCommunityNodeTest", "testRemove", ce);
358: fail(ce.getMessage());
359: }
360: }
361:
362: public void testSupportsRemove() {
363: try {
364: Debug.log("FileDynamicCommunityNodeTest",
365: "testSupportsRemove", "called");
366: assertTrue(role1Node.supportsRemove());
367: } catch (CMCException ce) {
368: Debug.log("FileDynamicCommunityNodeTest",
369: "testSupportsRemove", ce);
370: fail(ce.getMessage());
371: }
372: }
373:
374: public void testSetDPDocuments() {
375: Debug.log("FileDynamicCommunityNodeTest", "testSetDPDocuments",
376: "called");
377:
378: try {
379: createNodes();
380: setDPDocuments();
381: removeNodes();
382: } catch (CMCException ce) {
383: Debug.log("CommunityUserTest", "testSetDPDocuments", ce);
384: fail(ce.getMessage());
385: }
386: }
387:
388: public void testGetDPDocuments() {
389: Debug.log("FileDynamicCommunityNodeTest", "testGetDPDocuments",
390: "called");
391:
392: try {
393: createNodes();
394: setDPDocuments();
395:
396: ConfigTable dpDocuments = role1Node.getDPDocuments();
397:
398: try {
399: byte[] dpv = (byte[]) dpDocuments.get(role1VisitorCk);
400: assertNotNull(dpv);
401: String dpvString = new String(dpv, "UTF-8");
402: assertEquals(ROLE1_VISITOR_DP, dpvString);
403:
404: byte[] dpm = (byte[]) dpDocuments.get(role1MemberCk);
405: assertNotNull(dpm);
406: String dpmString = new String(dpm, "UTF-8");
407: assertEquals(ROLE1_MEMBER_DP, dpmString);
408:
409: byte[] dpo = (byte[]) dpDocuments.get(role1OwnerCk);
410: assertNotNull(dpo);
411: String dpoString = new String(dpo, "UTF-8");
412: assertEquals(ROLE1_OWNER_DP, dpoString);
413: } catch (UnsupportedEncodingException uec) {
414: fail("unsupported encoding exception");
415: }
416: removeNodes();
417: } catch (CMCException ce) {
418: Debug.log("FileDynamicCommunityNodeTest", "testExists", ce);
419: fail(ce.getMessage());
420: }
421: }
422:
423: public void testGetDescription() {
424: Debug.log("FileDynamicCommunityNodeTest", "testGetDescription",
425: "called");
426:
427: try {
428: role1Node.getDescription();
429: fail("getDescription did not fail");
430: } catch (UnsupportedOperationException ce) {
431: // expected
432: } catch (CMCException ce) {
433: Debug.log("FileDynamicCommunityNodeTest",
434: "testGetDescription", ce);
435: fail(ce.getMessage());
436: }
437: }
438:
439: public void testSetDescription() {
440: Debug.log("FileDynamicCommunityNodeTest", "testSetDescription",
441: "called");
442:
443: try {
444: role1Node.setDescription("new test description");
445: fail("setDescription did not fail");
446: } catch (UnsupportedOperationException ce) {
447: // expected
448: } catch (CMCException ce) {
449: Debug.log("FileDynamicCommunityNodeTest",
450: "testSetDescription", ce);
451: fail(ce.getMessage());
452: }
453: }
454:
455: public void testSupportsDescription() {
456: Debug.log("FileDynamicCommunityNodeTest",
457: "testSupportsDescription", "called");
458: try {
459: assertFalse(role1Node.supportsDescription());
460: } catch (CMCException ce) {
461: Debug.log("FileDynamicCommunityNodeTest",
462: "testSupportsDescription", ce);
463: fail(ce.getMessage());
464: }
465: }
466:
467: public void testGetCategory() {
468: Debug.log("FileDynamicCommunityNodeTest", "testGetCategory",
469: "called");
470:
471: try {
472: role1Node.getCategory();
473: fail("getCategory did not fail");
474: } catch (UnsupportedOperationException ce) {
475: // expected
476: } catch (CMCException ce) {
477: Debug.log("FileDynamicCommunityNodeTest",
478: "testGetCategory", ce);
479: fail(ce.getMessage());
480: }
481: }
482:
483: public void testSetCategory() {
484: Debug.log("FileDynamicCommunityNodeTest", "testSetCategory",
485: "called");
486:
487: try {
488: role1Node.setCategory("new test category");
489: fail("setCategory did not fail");
490: } catch (UnsupportedOperationException ce) {
491: // expected
492: } catch (CMCException ce) {
493: Debug.log("FileDynamicCommunityNodeTest",
494: "testSetCategory", ce);
495: fail(ce.getMessage());
496: }
497: }
498:
499: public void testSupportsCategory() {
500: Debug.log("FileDynamicCommunityNodeTest",
501: "testSupportsCategory", "called");
502: try {
503: assertFalse(role1Node.supportsCategory());
504: } catch (CMCException ce) {
505: Debug.log("FileDynamicCommunityNodeTest",
506: "testSupportsCategory", ce);
507: fail(ce.getMessage());
508: }
509: }
510:
511: public void testGetCommunityCreationTime() {
512: Debug.log("FileDynamicCommunityNodeTest",
513: "testGetCommunityCreationTime", "called");
514:
515: try {
516: role1Node.getCommunityCreationTime();
517: fail("getCommunityCreationTime did not fail");
518: } catch (UnsupportedOperationException ce) {
519: // expected
520: } catch (CMCException ce) {
521: Debug.log("FileDynamicCommunityNodeTest",
522: "testCommunityCreationTime", ce);
523: fail(ce.getMessage());
524: }
525: }
526:
527: public void testSupportsCommunityCreationTime() {
528: Debug.log("FileDynamicCommunityNodeTest",
529: "testSupportsCommunityCreationTime", "called");
530: try {
531: assertFalse(role1Node.supportsCommunityCreationTime());
532: } catch (CMCException ce) {
533: Debug.log("FileDynamicCommunityNodeTest",
534: "testSupportsCommunityCreationTime", ce);
535: fail(ce.getMessage());
536: }
537: }
538:
539: public void testIsMembershipRestricted() {
540: Debug.log("FileDynamicCommunityNodeTest",
541: "testIsMembershipRestricted", "called");
542:
543: try {
544: role1Node.isMembershipRestricted();
545: fail("isMembershipRestricted did not fail");
546: } catch (UnsupportedOperationException ce) {
547: // expected
548: } catch (CMCException ce) {
549: Debug.log("FileDynamicCommunityNodeTest",
550: "testIsMembershipRestricted", ce);
551: fail(ce.getMessage());
552: }
553: }
554:
555: public void testSetMembershipRestricted() {
556: Debug.log("FileDynamicCommunityNodeTest",
557: "testSetMembershipRestricted", "called");
558:
559: try {
560: role1Node.setMembershipRestricted(false);
561: fail("setMembershipRestricted did not fail");
562: } catch (UnsupportedOperationException ce) {
563: // expected
564: } catch (CMCException ce) {
565: Debug.log("FileDynamicCommunityNodeTest",
566: "testSetMembershipRestricted", ce);
567: fail(ce.getMessage());
568: }
569: }
570:
571: public void testSupportsMembershipRestriction() {
572: Debug.log("FileDynamicCommunityNodeTest",
573: "testSupportsMembershipRestriction", "called");
574: try {
575: assertFalse(role1Node.supportsMembershipRestriction());
576: } catch (CMCException ce) {
577: Debug.log("FileDynamicCommunityNodeTest",
578: "testSupportsMembershipRestriction", ce);
579: fail(ce.getMessage());
580: }
581: }
582:
583: public void testIsSecure() {
584: Debug.log("FileDynamicCommunityNodeTest", "testIsSecure",
585: "called");
586:
587: try {
588: role1Node.isSecure();
589: fail("isSecure did not fail");
590: } catch (UnsupportedOperationException ce) {
591: // expected
592: } catch (CMCException ce) {
593: Debug.log("FileDynamicCommunityNodeTest", "testIsSecure",
594: ce);
595: fail(ce.getMessage());
596: }
597: }
598:
599: public void testSetSecure() {
600: Debug.log("FileDynamicCommunityNodeTest", "testSetSecure",
601: "called");
602:
603: try {
604: role1Node.setSecure(false);
605: fail("setSecure did not fail");
606: } catch (UnsupportedOperationException ce) {
607: // expected
608: } catch (CMCException ce) {
609: Debug.log("FileDynamicCommunityNodeTest", "testSetSecure",
610: ce);
611: fail(ce.getMessage());
612: }
613: }
614:
615: public void testSupportsSecuring() {
616: Debug.log("FileDynamicCommunityNodeTest",
617: "testSupportsSecuring", "called");
618: try {
619: assertFalse(role1Node.supportsSecuring());
620: } catch (CMCException ce) {
621: Debug.log("FileDynamicCommunityNodeTest",
622: "testSupportsSecuring", ce);
623: fail(ce.getMessage());
624: }
625: }
626:
627: public void testIsListed() {
628: Debug.log("FileDynamicCommunityNodeTest", "testIsListed",
629: "called");
630:
631: try {
632: role1Node.isListed();
633: fail("isListed did not fail");
634: } catch (UnsupportedOperationException ce) {
635: // expected
636: } catch (CMCException ce) {
637: Debug.log("FileDynamicCommunityNodeTest", "testIsListed",
638: ce);
639: fail(ce.getMessage());
640: }
641: }
642:
643: public void testSetListed() {
644: Debug.log("FileDynamicCommunityNodeTest", "testSetListed",
645: "called");
646:
647: try {
648: role1Node.setListed(false);
649: fail("testSetListed did not fail");
650: } catch (UnsupportedOperationException ce) {
651: // expected
652: } catch (CMCException ce) {
653: Debug.log("FileDynamicCommunityNodeTest", "testSetListed",
654: ce);
655: fail(ce.getMessage());
656: }
657: }
658:
659: public void testSupportsListing() {
660: Debug.log("FileDynamicCommunityNodeTest",
661: "testSupportsListing", "called");
662: try {
663: assertFalse(role1Node.supportsListing());
664: } catch (CMCException ce) {
665: Debug.log("FileDynamicCommunityNodeTest",
666: "testSupportsListing", ce);
667: fail(ce.getMessage());
668: }
669: }
670:
671: public void testSupportsRoleCreationTime() {
672: Debug.log("FileDynamicCommunityNodeTest",
673: "testSupportsRoleCreationTime", "called");
674: try {
675: assertFalse(role1Node.supportsRoleCreationTime());
676: } catch (CMCException ce) {
677: Debug.log("FileDynamicCommunityNodeTest",
678: "testSupportsRoleCreationTime", ce);
679: fail(ce.getMessage());
680: }
681: }
682:
683: }
|