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 org.apache.torque.om.NumberKey;
050: import org.tigris.scarab.notification.ActivityType;
051: import org.tigris.scarab.test.BaseScarabTestCase;
052:
053: /**
054: * A Testing Suite for the om.Activity class.
055: *
056: * @author <a href="mailto:mumbly@oneofus.org">Tim McNerney </a>
057: * @version $Id: ActivityTest.java 9875 2005-10-02 20:47:01Z jorgeuriarte $
058: */
059: public class ActivityTest extends BaseScarabTestCase {
060:
061: public void testCreateLong() throws Exception {
062: System.out.println("\ntestCreateLong()");
063: ActivitySet trans = getEditActivitySet();
064: Activity activity = ActivityManager.createNumericActivity(
065: getIssue0(), getPlatformAttribute(), trans, null,
066: new Integer(5), new Integer(6));
067: activity.save();
068: ActivitySet newtrans = activity.getActivitySet();
069: assertEquals("getActivitySet expected: "
070: + trans.getActivitySetId() + " got: "
071: + newtrans.getActivitySetId(), trans.getActivitySetId()
072: .toString(), newtrans.getActivitySetId().toString());
073: Activity retActivity = ActivityManager.getInstance(activity
074: .getActivityId(), false);
075: assertEquals("OldValue", activity.getOldValue(), retActivity
076: .getOldValue());
077: assertEquals("NewValue", activity.getNewValue(), retActivity
078: .getNewValue());
079: assertEquals("Attribute", activity.getAttribute(), retActivity
080: .getAttribute());
081: }
082:
083: public void testCreateShort() throws Exception {
084: System.out.println("\ntestCreateShort()");
085: ActivitySet trans = getEditActivitySet();
086:
087: Activity activity = ActivityManager.createTextActivity(
088: getIssue0(), getPlatformAttribute(), trans,
089: ActivityType.ATTRIBUTE_CHANGED, "oldValue", "newValue");
090: activity.save();
091:
092: ActivitySet newtrans = activity.getActivitySet();
093: assertEquals("getActivitySet expected: "
094: + trans.getActivitySetId() + " got: "
095: + newtrans.getActivitySetId(), trans.getActivitySetId()
096: .toString(), newtrans.getActivitySetId().toString());
097: Activity retActivity = ActivityManager.getInstance(activity
098: .getActivityId(), false);
099: assertEquals("OldValue", activity.getOldValue(), retActivity
100: .getOldValue());
101: assertEquals("NewValue", activity.getNewValue(), retActivity
102: .getNewValue());
103: assertEquals("Attribute", activity.getAttribute(), retActivity
104: .getAttribute());
105: }
106:
107: public void testGetAttribute() throws Exception {
108: System.out.println("\ntestGetAttribute()");
109: Activity retActivity = ActivityManager.getInstance(
110: new NumberKey(1), false);
111: Integer key = retActivity.getAttribute().getAttributeId();
112: assertTrue("AttId expected: 11 got: " + key,
113: key.intValue() == 11);
114: }
115:
116: protected ActivitySet getEditActivitySet() throws Exception {
117: Attachment attach = new Attachment();
118: attach.setTextFields(getUser1(), getIssue0(),
119: Attachment.MODIFICATION__PK);
120: attach.setName("commenttest");
121: attach.save();
122:
123: ActivitySet trans = ActivitySetManager.getInstance(
124: ActivitySetTypePeer.EDIT_ISSUE__PK, getUser1(), attach);
125: trans.save();
126: return trans;
127: }
128:
129: protected Attribute getPlatformAttribute() throws Exception {
130:
131: return AttributeManager.getInstance(new NumberKey(5));
132: }
133: }
|