001: package org.tigris.scarab.om;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import java.util.Date;
050: import java.util.Iterator;
051: import java.util.List;
052: import java.util.Map;
053:
054: import org.apache.torque.om.NumberKey;
055: import org.tigris.scarab.services.security.ScarabSecurity;
056: import org.tigris.scarab.test.BaseScarabTestCase;
057:
058: /**
059: * A Testing Suite for the om.ScarabModule class.
060: *
061: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
062: * @version $Id: ScarabModuleTest.java 9276 2004-11-23 14:02:30Z dep4b $
063: */
064: public class ScarabModuleTest extends BaseScarabTestCase {
065: ScarabModule newModule;
066:
067: public void setUp() throws Exception {
068: super .setUp();
069: newModule = (ScarabModule) ModuleManager.getInstance();
070: Date d = new Date();
071: newModule.setRealName("Test Module " + d.getTime());
072: newModule.setOwnerId(new Integer(1));
073: newModule.setParentId(new Integer(1));
074: newModule.setDescription("This is the new module description");
075:
076: newModule.save();
077:
078: }
079:
080: public void testGetParents() throws Exception {
081: Module module = ModuleManager.getInstance(new NumberKey(7),
082: false);
083: List parents = module.getAncestors();
084: Iterator itr = parents.iterator();
085: while (itr.hasNext()) {
086: Module me = (Module) itr.next();
087: System.out.println(me.getName());
088: }
089: System.out.println("parents=" + parents.size());
090: }
091:
092: public void testIssueTypes() throws Exception {
093: List issueTypes = newModule.getRModuleIssueTypes();
094: for (int i = 0; i < issueTypes.size(); i++) {
095: IssueType issueType = ((RModuleIssueType) issueTypes.get(i))
096: .getIssueType();
097: System.out.println("ISSUE TYPE = " + issueType.getName());
098: Issue issue = new Issue();
099: issue.setModule(newModule);
100: issue.setIssueType(issueType);
101:
102: testGetAllAttributeValuesMap(issue);
103: testGetAttributeGroups(issueType);
104: testGetUserAttributes(issueType);
105: }
106: }
107:
108: public void testGetAttributeGroups(IssueType issueType)
109: throws Exception {
110: System.out.println("testGetAttributeGroups()");
111: List attrGroups = issueType.getAttributeGroups(newModule, true);
112: for (int i = 0; i < attrGroups.size(); i++) {
113: AttributeGroup group = (AttributeGroup) attrGroups.get(i);
114: System.out.println("attribute group = " + group.getName());
115: }
116: }
117:
118: public void testGetUsers() throws Exception {
119: ScarabUser[] users = newModule
120: .getUsers(ScarabSecurity.ISSUE__VIEW);
121: System.out.println(users);
122: }
123:
124: public void testGetAllAttributeValuesMap(Issue issue)
125: throws Exception {
126: System.out.println("testGetAllAttributeValuesMap()");
127: Map attrMap = issue.getAllAttributeValuesMap();
128: System.out.println("getAllAttributeValuesMap().size(): "
129: + attrMap.size());
130: assertEquals(getExpectedSize(issue.getIssueType()), attrMap
131: .size());
132: Iterator iter = attrMap.keySet().iterator();
133: Attribute attr = null;
134: while (iter.hasNext()) {
135: attr = ((AttributeValue) attrMap.get(iter.next()))
136: .getAttribute();
137: if (attr.isOptionAttribute()) {
138: int expectedSize = 0;
139: switch (Integer.parseInt(attr.getAttributeId()
140: .toString())) {
141: case 3:
142: expectedSize = 7;
143: break;
144: case 4:
145: expectedSize = 8;
146: break;
147: case 5:
148: expectedSize = 8;
149: break;
150: case 6:
151: expectedSize = 52;
152: break;
153: case 7:
154: expectedSize = 4;
155: break;
156: case 8:
157: expectedSize = 4;
158: break;
159: case 9:
160: expectedSize = 10;
161: break;
162: case 12:
163: expectedSize = 3;
164: break;
165: }
166: assertTrue(expectedSize > 0);
167: }
168: }
169: }
170:
171: public void testGetUserAttributes(IssueType issueType)
172: throws Exception {
173: System.out.println("testGetUserAttributes");
174: List attrs = newModule.getUserAttributes(issueType);
175: assertEquals(2, attrs.size());
176: }
177:
178: private int getExpectedSize(IssueType issueType) throws Exception
179:
180: {
181: int expectedSize = 0;
182: switch (Integer.parseInt(issueType.getIssueTypeId().toString())) {
183: case 1:
184: expectedSize = 12;
185: break;
186: case 3:
187: expectedSize = 11;
188: break;
189: case 5:
190: expectedSize = 9;
191: break;
192: case 7:
193: expectedSize = 9;
194: break;
195: case 9:
196: expectedSize = 9;
197: break;
198: }
199: return expectedSize;
200: }
201:
202: }
|