001: /**
002: * $Id: JdoCommunityNodeManagerTest.java,v 1.2 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.Set;
017: import java.util.Map;
018: import junit.framework.*;
019: import com.sun.portal.community.mc.impl.Debug;
020: import com.sun.portal.community.mc.*;
021: import java.util.regex.Pattern;
022:
023: public class JdoCommunityNodeManagerTest extends JdoCommunityTest
024: implements CMCNodeManagerTest {
025: public JdoCommunityNodeManagerTest(String testName) {
026: super (testName);
027: }
028:
029: protected void setUp() throws java.lang.Exception {
030: super .setUp();
031: Debug.log("JdoCommunityNodeManagerTest", "setUp", "called");
032: }
033:
034: protected void tearDown() throws java.lang.Exception {
035: super .tearDown();
036: Debug.log("JdoCommunityNodeManagerTest", "tearDown", "called");
037: }
038:
039: public static Test suite() {
040: TestSuite suite = new TestSuite(
041: JdoCommunityNodeManagerTest.class);
042: return suite;
043: }
044:
045: public void testGetUserCounts() {
046: Debug.log("JdoCommunityNodeManagerTest", "testGetUserCounts",
047: "called");
048:
049: try {
050: createNodes();
051: addUsers();
052:
053: Set communityPrincipals = Collections.singleton(cty1Cp);
054: CMCNodeManager cmcnm = CMCFactory.getInstance()
055: .getCMCNodeManager();
056: Map counts = cmcnm.getUserCounts(communityPrincipals);
057:
058: assertEquals(7, ((Integer) counts.get(cty1Cp)).intValue());
059:
060: removeNodes();
061: } catch (CMCException ce) {
062: Debug.log("JdoCommunityNodeManagerTest",
063: "testGetUserCounts", ce);
064: fail(ce.getMessage());
065: }
066: }
067:
068: public void testGetRoleUserCounts() {
069: Debug.log("JdoCommunityNodeManagerTest",
070: "testGetRoleUserCounts", "called");
071:
072: try {
073: createNodes();
074: addUsers();
075:
076: Set communityPrincipals = Collections.singleton(cty1Cp);
077: CMCNodeManager cmcnm = CMCFactory.getInstance()
078: .getCMCNodeManager();
079: Map counts = cmcnm.getRoleUserCounts(communityPrincipals,
080: CMCRolePrincipal.ALL_ROLES);
081:
082: assertEquals(1, ((Integer) counts.get(cty1OwnerCk))
083: .intValue());
084: assertEquals(2, ((Integer) counts.get(cty1MemberCk))
085: .intValue());
086: assertEquals(1, ((Integer) counts.get(cty1VisitorCk))
087: .intValue());
088: assertEquals(1, ((Integer) counts.get(cty1InvitedCk))
089: .intValue());
090: assertEquals(1, ((Integer) counts.get(cty1RejectedCk))
091: .intValue());
092: assertEquals(1, ((Integer) counts.get(cty1PendingCk))
093: .intValue());
094: assertEquals(1, ((Integer) counts.get(cty1BannedCk))
095: .intValue());
096:
097: removeNodes();
098: } catch (CMCException ce) {
099: Debug.log("JdoCommunityNodeManagerTest",
100: "testGetRoleUserCounts", ce);
101: fail(ce.getMessage());
102: }
103: }
104:
105: public void testMatchCommunity() {
106: Debug.log("JdoCommunityNodeManagerTest", "testMatchCommunity",
107: "called");
108:
109: try {
110: CMCNodeManager cmcnm = CMCFactory.getInstance()
111: .getCMCNodeManager();
112: Set principals = cmcnm.match(Pattern.compile(".*"));
113: assertEquals(0, principals.size());
114:
115: createNodes();
116:
117: principals = cmcnm.match(Pattern.compile(".*"));
118: assertEquals(1, principals.size());
119:
120: principals = cmcnm.match(Pattern.compile(".*2.*"));
121: assertEquals(0, principals.size());
122:
123: principals = cmcnm.match(Pattern.compile(".*1.*"));
124: assertEquals(1, principals.size());
125:
126: removeNodes();
127: } catch (CMCException ce) {
128: Debug.log("JdoCommunityNodeManagerTest",
129: "testMatchCommunity", ce);
130: fail(ce.getMessage());
131: }
132: }
133: }
|