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.*;
016: import java.util.regex.*;
017:
018: import junit.framework.*;
019: import com.sun.portal.community.mc.*;
020: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
021: import com.sun.portal.community.mc.impl.*;
022: import java.io.*;
023:
024: public abstract class JdoCommunityTest extends TestCase {
025: protected static final String CTY1_VISITOR_DP = "*** cty1 visitor ***";
026: protected static final String CTY1_MEMBER_DP = "*** cty1 member ***";
027: protected static final String CTY1_OWNER_DP = "*** cty1 owner ***";
028: protected static final String CTY1_BANNED_DP = "*** cty1 banned ***";
029: protected static final String CTY1_PENDING_DP = "*** cty1 pending ***";
030: protected static final String CTY1_REJECTED_DP = "*** cty1 rejected ***";
031: protected static final String CTY1_INVITED_DP = "*** cty1 invited ***";
032: protected static final String CTY1_DISABLED_DP = "*** cty1 disabled ***";
033:
034: protected static final String CTY2_VISITOR_DP = "*** cty2 visitor ***";
035: protected static final String CTY2_MEMBER_DP = "*** cty2 member ***";
036: protected static final String CTY2_OWNER_DP = "*** cty2 owner ***";
037: protected static final String CTY2_BANNED_DP = "*** cty2 banned ***";
038: protected static final String CTY2_PENDING_DP = "*** cty2 pending ***";
039: protected static final String CTY2_REJECTED_DP = "*** cty2 rejected ***";
040: protected static final String CTY2_INVITED_DP = "*** cty2 invited ***";
041: protected static final String CTY2_DISABLED_DP = "*** cty2 disabled ***";
042:
043: protected ConfigKey cty1VisitorCk;
044: protected ConfigKey cty1MemberCk;
045: protected ConfigKey cty1OwnerCk;
046: protected ConfigKey cty1RejectedCk;
047: protected ConfigKey cty1InvitedCk;
048: protected ConfigKey cty1BannedCk;
049: protected ConfigKey cty1PendingCk;
050: protected ConfigKey cty1DisabledCk;
051:
052: protected CMCPrincipal cty1Cp;
053: protected CMCNode cty1Node;
054:
055: protected String tUserName;
056: protected String uUserName;
057: protected String vUserName;
058: protected String wUserName;
059: protected String xUserName;
060: protected String yUserName;
061: protected String zUserName;
062:
063: protected CMCUser tUser;
064: protected CMCUser uUser;
065: protected CMCUser vUser;
066: protected CMCUser wUser;
067: protected CMCUser xUser;
068: protected CMCUser yUser;
069: protected CMCUser zUser;
070:
071: public JdoCommunityTest(String testName) {
072: super (testName);
073: }
074:
075: protected void setUp() throws java.lang.Exception {
076: super .setUp();
077: Debug.log("JdoCommunityTest", "setUp", "called");
078:
079: cty1Cp = new CMCPrincipal("jdo", "cty1." + getName());
080:
081: tUserName = "tUser." + getName();
082: tUserName = tUserName.toLowerCase();
083:
084: uUserName = "uUser." + getName();
085: uUserName = uUserName.toLowerCase();
086:
087: vUserName = "vUser." + getName();
088: vUserName = vUserName.toLowerCase();
089:
090: wUserName = "wUser." + getName();
091: wUserName = wUserName.toLowerCase();
092:
093: xUserName = "xUser." + getName();
094: xUserName = xUserName.toLowerCase();
095:
096: yUserName = "yUser." + getName();
097: yUserName = yUserName.toLowerCase();
098:
099: zUserName = "zUser." + getName();
100: zUserName = zUserName.toLowerCase();
101:
102: cty1VisitorCk = new ConfigKey(cty1Cp,
103: CMCRolePrincipal.VISITOR_ROLE);
104: cty1MemberCk = new ConfigKey(cty1Cp,
105: CMCRolePrincipal.MEMBER_ROLE);
106: cty1OwnerCk = new ConfigKey(cty1Cp, CMCRolePrincipal.OWNER_ROLE);
107: cty1PendingCk = new ConfigKey(cty1Cp,
108: CMCRolePrincipal.PENDING_ROLE);
109: cty1RejectedCk = new ConfigKey(cty1Cp,
110: CMCRolePrincipal.REJECTED_ROLE);
111: cty1InvitedCk = new ConfigKey(cty1Cp,
112: CMCRolePrincipal.INVITED_ROLE);
113: cty1BannedCk = new ConfigKey(cty1Cp,
114: CMCRolePrincipal.BANNED_ROLE);
115: cty1DisabledCk = new ConfigKey(cty1Cp,
116: CMCRolePrincipal.DISABLED_ROLE);
117:
118: try {
119: cty1Node = CMCFactory.getInstance().getCMCNode(cty1Cp);
120:
121: tUser = CMCFactory.getInstance().getCMCUser(tUserName);
122: uUser = CMCFactory.getInstance().getCMCUser(uUserName);
123: vUser = CMCFactory.getInstance().getCMCUser(vUserName);
124: wUser = CMCFactory.getInstance().getCMCUser(wUserName);
125: xUser = CMCFactory.getInstance().getCMCUser(xUserName);
126: yUser = CMCFactory.getInstance().getCMCUser(yUserName);
127: zUser = CMCFactory.getInstance().getCMCUser(zUserName);
128: } catch (CMCException ce) {
129: Debug.log("JdoCommunityUserTest", "setUp", ce);
130: fail(ce.getMessage());
131: }
132: }
133:
134: protected void tearDown() throws java.lang.Exception {
135: super .tearDown();
136: Debug.log("JdoCommunityTest", "tearDown", "called");
137: }
138:
139: public void createNodes() throws CMCException {
140: Debug.log("JdoCommunityTest", "createNode", "called");
141: cty1Node.create();
142: }
143:
144: public void addUsers() throws CMCException {
145: Debug.log("JdoCommunityTest", "addUsers", "called");
146:
147: Set users = new HashSet();
148: users.add(xUserName);
149: cty1Node.addUsers(users, CMCRolePrincipal.VISITOR_ROLE);
150:
151: users.clear();
152: users.add(yUserName);
153: users.add(zUserName);
154: cty1Node.addUsers(users, CMCRolePrincipal.MEMBER_ROLE);
155:
156: users.clear();
157: users.add(zUserName);
158: cty1Node.addUsers(users, CMCRolePrincipal.OWNER_ROLE);
159:
160: users.clear();
161: users.add(tUserName);
162: cty1Node.addUsers(users, CMCRolePrincipal.PENDING_ROLE);
163:
164: users.clear();
165: users.add(uUserName);
166: cty1Node.addUsers(users, CMCRolePrincipal.BANNED_ROLE);
167:
168: users.clear();
169: users.add(vUserName);
170: cty1Node.addUsers(users, CMCRolePrincipal.INVITED_ROLE);
171:
172: users.clear();
173: users.add(wUserName);
174: cty1Node.addUsers(users, CMCRolePrincipal.REJECTED_ROLE);
175: }
176:
177: public void addRoles() throws CMCException {
178: Debug.log("JdoCommunityTest", "addRoles", "called");
179: cty1Node.addRole(CMCRolePrincipal.DISABLED_ROLE);
180: }
181:
182: public void removeRoles() throws CMCException {
183: Debug.log("JdoCommunityTest", "removeRoles", "called");
184: cty1Node.removeRole(CMCRolePrincipal.DISABLED_ROLE);
185: }
186:
187: public void removeNodes() throws CMCException {
188: Debug.log("JdoCommunityTest", "testRemove", "called");
189: cty1Node.remove();
190: }
191:
192: public void setDPDocuments() throws CMCException {
193: Debug.log("JdoCommunityTest", "setDPDocuments", "called");
194:
195: ConfigTable dpDocs = new ConfigTable();
196:
197: try {
198: dpDocs
199: .put(cty1VisitorCk, CTY1_VISITOR_DP
200: .getBytes("UTF-8"));
201: dpDocs.put(cty1MemberCk, CTY1_MEMBER_DP.getBytes("UTF-8"));
202: dpDocs.put(cty1OwnerCk, CTY1_OWNER_DP.getBytes("UTF-8"));
203: dpDocs.put(cty1RejectedCk, CTY1_REJECTED_DP
204: .getBytes("UTF-8"));
205: dpDocs
206: .put(cty1PendingCk, CTY1_PENDING_DP
207: .getBytes("UTF-8"));
208: dpDocs
209: .put(cty1InvitedCk, CTY1_INVITED_DP
210: .getBytes("UTF-8"));
211: dpDocs.put(cty1BannedCk, CTY1_BANNED_DP.getBytes("UTF-8"));
212: dpDocs.put(cty1DisabledCk, CTY1_DISABLED_DP
213: .getBytes("UTF-8"));
214: } catch (UnsupportedEncodingException uee) {
215: fail("unsupported encoding");
216: }
217: cty1Node.setDPDocuments(dpDocs);
218: }
219: }
|