KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > test > BaseScarabTestCase


1 package org.tigris.scarab.test;
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.io.File JavaDoc;
50
51 import org.apache.torque.om.NumberKey;
52 import org.tigris.scarab.om.ActivitySet;
53 import org.tigris.scarab.om.ActivitySetManager;
54 import org.tigris.scarab.om.ActivitySetTypePeer;
55 import org.tigris.scarab.om.Attachment;
56 import org.tigris.scarab.om.Attribute;
57 import org.tigris.scarab.om.AttributeManager;
58 import org.tigris.scarab.om.Issue;
59 import org.tigris.scarab.om.IssueManager;
60 import org.tigris.scarab.om.IssueType;
61 import org.tigris.scarab.om.IssueTypeManager;
62 import org.tigris.scarab.om.Module;
63 import org.tigris.scarab.om.ModuleManager;
64 import org.tigris.scarab.om.ScarabUser;
65 import org.tigris.scarab.om.ScarabUserManager;
66
67 /**
68  * Test case that provides scaffolding for other Scarab test cases.
69  *
70  * @author <a HREF="mailto:epugh@opensourceconnections.com">Eric Pugh </a>
71  * @version $Id: BaseScarabTestCase.java 9446 2005-03-12 11:59:50Z jorgeuriarte $
72  */

73 public class BaseScarabTestCase extends BaseTurbineTestCase
74 {
75     private static Module module = null;
76     private static IssueType defaultIssueType = null;
77     protected static int nbrDfltModules = 7;
78     protected static int nbrDfltIssueTypes = 5;
79     private ScarabUser user0 = null;
80     private ScarabUser user1 = null;
81     private ScarabUser user2 = null;
82
83     private Issue issue0 = null;
84     private Attribute platformAttribute = null;
85     private Attribute assignAttribute = null;
86     private Attribute ccAttribute = null;
87
88     private static boolean initialized = false;
89
90     public BaseScarabTestCase()
91     {
92         System.setProperty("applicationRoot", "./src/webapp");
93         System.setProperty("urn:avalon:home", "./src/webapp");
94     }
95
96     public BaseScarabTestCase(String JavaDoc name) throws Exception JavaDoc
97     {
98         super(name);
99     }
100
101     /*
102      * @see TestCase#setUp()
103      */

104     protected void setUp() throws Exception JavaDoc
105     {
106         super.setUp();
107         if (!initialized)
108         {
109             initScarab();
110             initialized = true;
111         }
112     }
113
114     /*
115      * @see TestCase#tearDown()
116      */

117     protected void tearDown() throws Exception JavaDoc
118     {
119         super.tearDown();
120     }
121
122     /**
123      * Grab Module #5 for testing. This is the same as what the web application
124      * does and this is setup in ScarabPage.tempWorkAround()
125      */

126     private void initScarab() throws Exception JavaDoc
127     {
128         module = ModuleManager.getInstance(new NumberKey(5), false);
129         defaultIssueType = IssueTypeManager
130                 .getInstance(new NumberKey(1), false);
131     }
132
133     protected ScarabUser getUser1() throws Exception JavaDoc
134     {
135         if (user1 == null)
136         {
137             user1 = ScarabUserManager.getInstance(new NumberKey(1), false);
138         }
139         return user1;
140     }
141
142     protected ScarabUser getUser2() throws Exception JavaDoc
143     {
144         if (user2 == null)
145         {
146             user2 = ScarabUserManager.getInstance(new NumberKey(2), false);
147
148         }
149         return user2;
150     }
151
152     protected ScarabUser getUser5() throws Exception JavaDoc
153     {
154         if (user0 == null)
155         {
156             user0 = ScarabUserManager.getInstance(new NumberKey(5), false);
157         }
158         return user0;
159     }
160
161     protected Issue getIssue0() throws Exception JavaDoc
162     {
163         if (issue0 == null)
164         {
165             issue0 = IssueManager.getInstance(new NumberKey(1), false);
166         }
167         return issue0;
168     }
169
170     protected Attribute getPlatformAttribute() throws Exception JavaDoc
171     {
172         if (platformAttribute == null)
173         {
174             platformAttribute = AttributeManager.getInstance(new NumberKey(5));
175         }
176         return platformAttribute;
177     }
178
179     protected ActivitySet getEditActivitySet() throws Exception JavaDoc
180     {
181         Attachment attach = new Attachment();
182         attach.setTextFields(getUser1(), getIssue0(),
183                 Attachment.MODIFICATION__PK);
184         attach.setName("commenttest");
185         attach.save();
186
187         ActivitySet trans = ActivitySetManager.getInstance(
188                 ActivitySetTypePeer.EDIT_ISSUE__PK, getUser1(), attach);
189         trans.save();
190         return trans;
191     }
192
193     /**
194      * If something like an Issue needs a mapping to a Module, then this is
195      * Module #5 that you can use. For example, you should call:
196      * issue.setModule(getModule()) in your Test before you use any of the rest
197      * of the methods on the Issue object.
198      */

199     protected Module getModule()
200     {
201         return BaseScarabTestCase.module;
202     }
203
204     protected IssueType getDefaultIssueType()
205     {
206         return BaseScarabTestCase.defaultIssueType;
207     }
208     protected Attribute getAssignAttribute() throws Exception JavaDoc
209     {
210         if (assignAttribute == null)
211         {
212             assignAttribute = AttributeManager.getInstance(new NumberKey(2));
213         }
214         return assignAttribute;
215     }
216
217     protected Attribute getCcAttribute() throws Exception JavaDoc
218     {
219         if (ccAttribute == null)
220         {
221             ccAttribute = AttributeManager.getInstance(new NumberKey(13));
222         }
223         return ccAttribute;
224     }
225
226 }
Popular Tags