001: package org.tigris.scarab.test;
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.io.File;
050:
051: import org.apache.torque.om.NumberKey;
052: import org.tigris.scarab.om.ActivitySet;
053: import org.tigris.scarab.om.ActivitySetManager;
054: import org.tigris.scarab.om.ActivitySetTypePeer;
055: import org.tigris.scarab.om.Attachment;
056: import org.tigris.scarab.om.Attribute;
057: import org.tigris.scarab.om.AttributeManager;
058: import org.tigris.scarab.om.Issue;
059: import org.tigris.scarab.om.IssueManager;
060: import org.tigris.scarab.om.IssueType;
061: import org.tigris.scarab.om.IssueTypeManager;
062: import org.tigris.scarab.om.Module;
063: import org.tigris.scarab.om.ModuleManager;
064: import org.tigris.scarab.om.ScarabUser;
065: import org.tigris.scarab.om.ScarabUserManager;
066:
067: /**
068: * Test case that provides scaffolding for other Scarab test cases.
069: *
070: * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh </a>
071: * @version $Id: BaseScarabTestCase.java 9966 2005-11-27 22:10:05Z jorgeuriarte $
072: */
073: public class BaseScarabTestCase extends BaseTurbineTestCase {
074: private static Module module = null;
075: private static IssueType defaultIssueType = null;
076: protected static int nbrDfltModules = 7;
077: protected static int nbrDfltIssueTypes = 5;
078: private ScarabUser user0 = null;
079: private ScarabUser user1 = null;
080: private ScarabUser user2 = null;
081:
082: private Issue issue0 = null;
083: private Attribute platformAttribute = null;
084: private Attribute voteAttribute = null;
085: private Attribute assignAttribute = null;
086: private Attribute ccAttribute = null;
087:
088: private static boolean initialized = false;
089:
090: public BaseScarabTestCase() {
091: System.setProperty("applicationRoot", "./src/webapp");
092: System.setProperty("urn:avalon:home", "./src/webapp");
093: }
094:
095: public BaseScarabTestCase(String name) throws Exception {
096: super (name);
097: }
098:
099: /*
100: * @see TestCase#setUp()
101: */
102: protected void setUp() throws Exception {
103: super .setUp();
104: if (!initialized) {
105: initScarab();
106: initialized = true;
107: }
108: }
109:
110: /*
111: * @see TestCase#tearDown()
112: */
113: protected void tearDown() throws Exception {
114: super .tearDown();
115: }
116:
117: /**
118: * Grab Module #5 for testing. This is the same as what the web application
119: * does and this is setup in ScarabPage.tempWorkAround()
120: */
121: private void initScarab() throws Exception {
122: module = ModuleManager.getInstance(new NumberKey(5), false);
123: defaultIssueType = IssueTypeManager.getInstance(
124: new NumberKey(1), false);
125: }
126:
127: protected ScarabUser getUser1() throws Exception {
128: if (user1 == null) {
129: user1 = ScarabUserManager.getInstance(new NumberKey(1),
130: false);
131: }
132: return user1;
133: }
134:
135: protected ScarabUser getUser2() throws Exception {
136: if (user2 == null) {
137: user2 = ScarabUserManager.getInstance(new NumberKey(2),
138: false);
139:
140: }
141: return user2;
142: }
143:
144: protected ScarabUser getUser5() throws Exception {
145: if (user0 == null) {
146: user0 = ScarabUserManager.getInstance(new NumberKey(5),
147: false);
148: }
149: return user0;
150: }
151:
152: protected Issue getIssue0() throws Exception {
153: if (issue0 == null) {
154: issue0 = IssueManager.getInstance(new NumberKey(1), false);
155: }
156: return issue0;
157: }
158:
159: protected Attribute getPlatformAttribute() throws Exception {
160: if (platformAttribute == null) {
161: platformAttribute = AttributeManager
162: .getInstance(new NumberKey(5));
163: }
164: return platformAttribute;
165: }
166:
167: protected Attribute getVoteAttribute() throws Exception {
168: if (voteAttribute == null) {
169: voteAttribute = AttributeManager.getInstance(new NumberKey(
170: 8));
171: }
172: return voteAttribute;
173: }
174:
175: protected ActivitySet getEditActivitySet() throws Exception {
176: Attachment attach = new Attachment();
177: attach.setTextFields(getUser1(), getIssue0(),
178: Attachment.MODIFICATION__PK);
179: attach.setName("commenttest");
180: attach.save();
181:
182: ActivitySet trans = ActivitySetManager.getInstance(
183: ActivitySetTypePeer.EDIT_ISSUE__PK, getUser1(), attach);
184: trans.save();
185: return trans;
186: }
187:
188: /**
189: * If something like an Issue needs a mapping to a Module, then this is
190: * Module #5 that you can use. For example, you should call:
191: * issue.setModule(getModule()) in your Test before you use any of the rest
192: * of the methods on the Issue object.
193: */
194: protected Module getModule() {
195: return BaseScarabTestCase.module;
196: }
197:
198: protected IssueType getDefaultIssueType() {
199: return BaseScarabTestCase.defaultIssueType;
200: }
201:
202: protected Attribute getAssignAttribute() throws Exception {
203: if (assignAttribute == null) {
204: assignAttribute = AttributeManager
205: .getInstance(new NumberKey(2));
206: }
207: return assignAttribute;
208: }
209:
210: protected Attribute getCcAttribute() throws Exception {
211: if (ccAttribute == null) {
212: ccAttribute = AttributeManager
213: .getInstance(new NumberKey(13));
214: }
215: return ccAttribute;
216: }
217:
218: }
|