KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Map JavaDoc;
53 import java.util.Set JavaDoc;
54
55 import org.apache.torque.om.NumberKey;
56 import org.apache.torque.util.Criteria;
57 import org.tigris.scarab.test.BaseScarabTestCase;
58
59 /**
60  * A Testing Suite for the om.Issue class.
61  *
62  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
63  * @version $Id: IssueTest.java 9271 2004-11-23 08:35:00Z dep4b $
64  */

65 public class IssueTest extends BaseScarabTestCase
66 {
67     private List JavaDoc issueList = new ArrayList JavaDoc();
68     private Map JavaDoc uniqueIDs;
69     protected static int nbrDfltModules = 7;
70     protected static int nbrDfltIssueTypes = 5;
71
72     public void setUp() throws Exception JavaDoc
73     {
74         super.setUp();
75         uniqueIDs = new HashMap JavaDoc();
76         createTestIssues();
77         loopThruTestIssues();
78
79     }
80
81
82     private void createTestIssues() throws Exception JavaDoc
83     {
84         // loops thru module and issue type combinations
85
// creates an issue in each combination
86
for (int i = 1; i < nbrDfltModules + 1; i++)
87         {
88             for (int j = 1; j < nbrDfltIssueTypes + 1; j++)
89             {
90                 Module module =
91                     ScarabModulePeer.retrieveByPK(
92                         new NumberKey(Integer.toString(i)));
93                 IssueType issueType =
94                     IssueTypePeer.retrieveByPK(
95                         new NumberKey(Integer.toString(j)));
96                 Issue issue = Issue.getNewInstance(module, issueType);
97                 issueList.add(issue);
98             }
99         }
100     }
101
102     private void loopThruTestIssues() throws Exception JavaDoc
103     {
104         for (int i = 1; i < issueList.size(); i++)
105         {
106             Issue issue = (Issue) issueList.get(i);
107             System.out.println("MODULE=" + issue.getModule().getName());
108             System.out.println(
109                 "ISSUE TYPE = " + issue.getIssueType().getName());
110             String JavaDoc strUniqueID = issue.getUniqueId();
111             System.out.println("Unique id: " + strUniqueID);
112             runTestGetAllAttributeValuesMap(issue);
113         }
114     }
115
116     private void runTestGetAllAttributeValuesMap(Issue issue) throws Exception JavaDoc
117     {
118         System.out.println("testGetAllAttributeValuesMap()");
119         Map JavaDoc map = issue.getAllAttributeValuesMap();
120         System.out.println("getAllAttributeValuesMap().size(): " + map.size());
121         int expectedSize = 12;
122         switch (Integer.parseInt(issue.getTypeId().toString()))
123         {
124             case 1 :
125                 expectedSize = 12;
126                 break;
127             case 2 :
128                 expectedSize = 12;
129                 break;
130             case 3 :
131                 expectedSize = 11;
132                 break;
133             case 4 :
134                 expectedSize = 11;
135                 break;
136             case 5 :
137                 expectedSize = 9;
138                 break;
139             case 6 :
140                 expectedSize = 9;
141                 break;
142             case 7 :
143                 expectedSize = 9;
144                 break;
145             case 8 :
146                 expectedSize = 9;
147                 break;
148             case 9 :
149                 expectedSize = 9;
150                 break;
151             case 10 :
152                 expectedSize = 9;
153         }
154         //assertEquals("issue.getTypeId():" + issue.getTypeId(),expectedSize, map.size());
155
assertTrue("issue.getTypeId():" + issue.getTypeId(),map.size()>4);
156     }
157
158     private void assignUser() throws Exception JavaDoc
159     {
160         System.out.println("assignUser()");
161         Attribute assignAttr = getAssignAttribute();
162         ScarabUser assigner = getUser1();
163         ScarabUser assignee = getUser2();
164         getIssue0().assignUser(
165             null,
166             assigner,
167             assignee,
168             assignAttr,
169             getAttachment(assigner));
170     }
171
172     public void testGetAssociatedUsers() throws Exception JavaDoc
173     {
174         System.out.println("testAssociatedUsers()");
175         assignUser();
176         assertEquals(getIssue0().getAssociatedUsers().size(), 1);
177         List JavaDoc pair = (List JavaDoc) getIssue0().getAssociatedUsers().iterator().next();
178         assertEquals(pair.get(1), getUser1());
179     }
180
181     public void OFFtestChangeUserAttributeValue() throws Exception JavaDoc
182     {
183         System.out.println("testChangeUserAttributeValue()");
184         assignUser();
185         Attribute assignAttr = getAssignAttribute();
186         Attribute ccAttr = getCcAttribute();
187         ScarabUser assigner = getUser1();
188         ScarabUser assignee = getUser2();
189         AttributeValue attVal = getIssue0().getAttributeValue(assignAttr);
190         getIssue0().changeUserAttributeValue(
191             null,
192             assigner,
193             assignee,
194             attVal,
195             ccAttr,
196             getAttachment(assigner));
197         List JavaDoc pair = (List JavaDoc) getIssue0().getAssociatedUsers().iterator().next();
198         assertEquals(pair.get(0), ccAttr);
199     }
200
201     public void OFFtestDeleteUser() throws Exception JavaDoc
202     {
203         System.out.println("testDeleteUser()");
204         Attribute assignAttr = getAssignAttribute();
205         ScarabUser assigner = getUser1();
206         AttributeValue attVal = getIssue0().getAttributeValue(assignAttr);
207         getIssue0().deleteUser(
208             null,
209             getUser1(),
210             getUser2(),
211             attVal,
212             getAttachment(assigner));
213         assertEquals(getIssue0().getAssociatedUsers().size(), 0);
214     }
215
216     public void testGetUserAttributeValues() throws Exception JavaDoc
217     {
218         System.out.println("testAssociatedUsers()");
219         assignUser();
220         List JavaDoc attVals = getIssue0().getUserAttributeValues();
221         AttributeValue attVal = (AttributeValue) attVals.get(0);
222         assertEquals(attVal.getAttributeId().toString(), "2");
223     }
224
225     public void testGetEligibleUsers() throws Exception JavaDoc
226     {
227         System.out.println("testGetEligibleUsers()");
228         assignUser();
229         List JavaDoc users = getIssue0().getEligibleUsers(getAssignAttribute());
230         assertTrue(users.size()>0);
231     }
232
233     public void testGetUsersToEmail() throws Exception JavaDoc
234     {
235         System.out.println("testGetUsersToEmail()");
236         assignUser();
237         Set JavaDoc users =
238             getIssue0().getUsersToEmail(
239                 AttributePeer.EMAIL_TO,
240                 getIssue0(),
241                 null);
242         assertEquals(users.size(), 2);
243     }
244
245     private Attachment getAttachment(ScarabUser assigner) throws Exception JavaDoc
246     {
247         Attachment attachment = new Attachment();
248         attachment.setData("test reason");
249         attachment.setName("comment");
250         attachment.setTextFields(
251             assigner,
252             getIssue0(),
253             Attachment.MODIFICATION__PK);
254         attachment.save();
255         return attachment;
256     }
257
258     public void testCounts() throws Exception JavaDoc
259     {
260         System.out.println("Testing IssuePeer count methods");
261         assignUser();
262         int count = IssuePeer.count(new Criteria());
263         assertTrue(
264             "IssuePeer.count(new Criteria()) returned " + count,
265             count>0);
266         count = IssuePeer.countDistinct(new Criteria());
267         assertTrue(
268             "IssuePeer.countDistinct(new Criteria()) returned " + count,
269             count>0);
270     }
271     
272     protected ScarabUser getUser2()
273     throws Exception JavaDoc
274     {
275             return ScarabUserManager.getInstance(new NumberKey(2), false);
276      
277     }
278     
279     protected Attribute getAssignAttribute()
280     throws Exception JavaDoc
281     {
282             return AttributeManager.getInstance(new NumberKey(2));
283     }
284         
285     protected Attribute getCcAttribute()
286     throws Exception JavaDoc
287     {
288        
289             return AttributeManager.getInstance(new NumberKey(13));
290         
291     }
292 }
293
Popular Tags