KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > ScarabModuleTest


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.Date JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Map JavaDoc;
53
54 import org.apache.torque.om.NumberKey;
55 import org.tigris.scarab.services.security.ScarabSecurity;
56 import org.tigris.scarab.test.BaseScarabTestCase;
57
58 /**
59  * A Testing Suite for the om.ScarabModule class.
60  *
61  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
62  * @version $Id: ScarabModuleTest.java 9276 2004-11-23 14:02:30Z dep4b $
63  */

64 public class ScarabModuleTest extends BaseScarabTestCase
65 {
66     ScarabModule newModule;
67     public void setUp() throws Exception JavaDoc{
68         super.setUp();
69         newModule = (ScarabModule)ModuleManager.getInstance();
70         Date JavaDoc d = new Date JavaDoc();
71         newModule.setRealName("Test Module " + d.getTime());
72         newModule.setOwnerId(new Integer JavaDoc(1));
73         newModule.setParentId(new Integer JavaDoc(1));
74         newModule.setDescription("This is the new module description");
75         
76      
77         newModule.save();
78         
79     }
80     
81
82     public void testGetParents() throws Exception JavaDoc
83     {
84         Module module = ModuleManager
85             .getInstance(new NumberKey(7), false);
86         List JavaDoc parents = module.getAncestors();
87         Iterator JavaDoc itr = parents.iterator();
88         while (itr.hasNext())
89         {
90             Module me = (Module) itr.next();
91             System.out.println (me.getName());
92         }
93         System.out.println ("parents=" + parents.size());
94     }
95    
96
97     public void testIssueTypes() throws Exception JavaDoc
98     {
99         List JavaDoc issueTypes = newModule.getRModuleIssueTypes();
100         for (int i = 0;i<issueTypes.size();i++)
101         {
102             IssueType issueType = ((RModuleIssueType)issueTypes
103                   .get(i)).getIssueType();
104             System.out.println("ISSUE TYPE = " + issueType.getName());
105             Issue issue = new Issue();
106             issue.setModule(newModule);
107             issue.setIssueType(issueType);
108
109             testGetAllAttributeValuesMap(issue);
110             testGetAttributeGroups(issueType);
111             testGetUserAttributes(issueType);
112         }
113     }
114
115     public void testGetAttributeGroups(IssueType issueType)
116         throws Exception JavaDoc
117     {
118         System.out.println ("testGetAttributeGroups()");
119         List JavaDoc attrGroups = issueType.getAttributeGroups(newModule, true);
120         for (int i=0;i<attrGroups.size(); i++)
121         {
122             AttributeGroup group = (AttributeGroup)attrGroups.get(i);
123             System.out.println("attribute group = " + group.getName());
124         }
125     }
126
127
128     public void testGetUsers() throws Exception JavaDoc
129     {
130         ScarabUser[] users = newModule.getUsers(ScarabSecurity.ISSUE__VIEW);
131         System.out.println(users);
132     }
133
134     public void testGetAllAttributeValuesMap(Issue issue) throws Exception JavaDoc
135     {
136         System.out.println ("testGetAllAttributeValuesMap()");
137         Map JavaDoc attrMap = issue.getAllAttributeValuesMap();
138         System.out.println ("getAllAttributeValuesMap().size(): "
139                              + attrMap.size());
140         assertEquals (getExpectedSize(issue.getIssueType()), attrMap.size());
141         Iterator JavaDoc iter = attrMap.keySet().iterator();
142         Attribute attr = null;
143         while (iter.hasNext())
144         {
145             attr = ((AttributeValue)attrMap.get(iter.next()))
146                              .getAttribute();
147             if (attr.isOptionAttribute())
148             {
149                 int expectedSize = 0;
150                 switch (Integer.parseInt(attr.getAttributeId().toString()))
151                 {
152                     case 3: expectedSize = 7;break;
153                     case 4: expectedSize = 8;break;
154                     case 5: expectedSize = 8;break;
155                     case 6: expectedSize = 52;break;
156                     case 7: expectedSize = 4;break;
157                     case 8: expectedSize = 4;break;
158                     case 9: expectedSize = 10;break;
159                     case 12: expectedSize = 3;break;
160                 }
161                 assertTrue(expectedSize >0);
162             }
163         }
164     }
165
166     public void testGetUserAttributes(IssueType issueType)
167         throws Exception JavaDoc
168     {
169         System.out.println ("testGetUserAttributes");
170         List JavaDoc attrs = newModule.getUserAttributes(issueType);
171         assertEquals (2, attrs.size());
172     }
173
174              
175     private int getExpectedSize(IssueType issueType) throws Exception JavaDoc
176
177     {
178         int expectedSize = 0;
179         switch (Integer.parseInt(issueType.getIssueTypeId().toString()))
180         {
181             case 1: expectedSize = 12;break;
182             case 3: expectedSize = 11;break;
183             case 5: expectedSize = 9;break;
184             case 7: expectedSize = 9;break;
185             case 9: expectedSize = 9;break;
186         }
187         return expectedSize;
188     }
189     
190     
191 }
192
Popular Tags