001: package org.tigris.scarab.util.xmlissues;
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: import java.util.List;
051:
052: import org.apache.torque.util.Criteria;
053:
054: import org.tigris.scarab.test.BaseScarabTestCase; //import org.tigris.scarab.om.Module;
055: //import org.tigris.scarab.om.IssueType;
056: import org.tigris.scarab.om.ActivityPeer;
057:
058: //import org.tigris.scarab.om.AttributeOptionManager;
059: //import org.tigris.scarab.om.AttributeOption;
060:
061: /**
062: * A Testing Suite for the ImportIssues class.
063: *
064: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
065: * @version $Id: ImportIssuesTest.java 9446 2005-03-12 11:59:50Z jorgeuriarte $
066: */
067: public class ImportIssuesTest extends BaseScarabTestCase {
068: private static final File INPUT_FILE = new File(
069: "src/test/org/tigris/scarab/util/xmlissues/test-issues.xml")
070: .getAbsoluteFile();
071: private static final String INPUT_FILENAME = INPUT_FILE.toString();
072:
073: public void testImportIssuesViaXMLFile() throws Exception {
074:
075: assertTrue("Make sure input file exists at:" + INPUT_FILE,
076: INPUT_FILE.exists());
077:
078: // this is quite a hack, need to modify ImportIssues to work with an
079: // InputStream
080: /*
081: * FIXME: Eric commented out as this doesn't work with file uplaod 1.0
082: *
083: FileItem issuesToImport = new DefaultFileItem()
084: {
085: public InputStream getInputStream() throws RuntimeException
086: {
087: try {
088: return new FileInputStream(INPUT_FILENAME);
089: }
090: catch(Exception e){
091: throw new NestableRuntimeException("Problem reading in file " + INPUT_FILENAME,e);
092: }
093: }
094:
095: public String getName()
096: {
097: return INPUT_FILE.getName();
098: }
099: };
100:
101: assertTrue("Could not locate input file",
102: issuesToImport.getInputStream() != null);
103:
104: ImportIssues importIssues = new ImportIssues();
105: Collection importErrors = importIssues.runImport(issuesToImport);
106: //ScarabIssues si = importIssues.getScarabIssuesBeanReader();
107: // looking at current code importErrors will never be null, so
108: // putting in a test to confirm it
109: assertTrue("importErrors should never be null", importErrors != null);
110: assertTrue(importErrors.toString(), importErrors.isEmpty());
111: */
112: }
113:
114: /**
115: * Earlier versions of xmlimport would combine Activity's from
116: * the xml file with those already in the db, if they shared an
117: * ActivitySet id.
118: * The sample data adds two Activities to PACS1 within
119: * ActivitySet PK=1. The xml also references ActivitySet id=1
120: * Make sure the Activities with ActivitySet = 1 are still only two.
121: *
122: * @exception Exception if an error occurs
123: */
124: public void testActivitySetCorruption() throws Exception {
125: Criteria crit = new Criteria();
126: crit.add(ActivityPeer.TRANSACTION_ID, 1);
127: List activities = ActivityPeer.doSelect(crit);
128: assertTrue("Activites size should be two, it was "
129: + activities.size(), activities.size() == 2);
130: }
131: }
|