001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.core;
043:
044: import org.netbeans.modules.uml.core.configstringframework.AllConfigStringFrameworkTests;
045: import org.netbeans.modules.uml.core.coreapplication.AllCoreApplicationTests;
046: import org.netbeans.modules.uml.core.generativeframework.AllGenerativeFrameworkTests;
047: import org.netbeans.modules.uml.core.metamodel.basic.basicactions.AllBasicActionsTests;
048: import org.netbeans.modules.uml.core.metamodel.behavior.AllBehaviorTests;
049: import org.netbeans.modules.uml.core.metamodel.common.commonactions.AllCommonActionsTests;
050: import org.netbeans.modules.uml.core.metamodel.common.commonactivities.AllCommonActivitiesTests;
051: import org.netbeans.modules.uml.core.metamodel.common.commonstatemachines.AllCommonStateMachineTests;
052: import org.netbeans.modules.uml.core.metamodel.core.constructs.AllConstructsTests;
053: import org.netbeans.modules.uml.core.metamodel.dynamics.AllDynamicsTests;
054: import org.netbeans.modules.uml.core.metamodel.infrastructure.AllInfrastructureTests;
055: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.AllCoreInfraTests;
056: import org.netbeans.modules.uml.core.metamodel.modelanalysis.AllModelAnalysisTests;
057: import org.netbeans.modules.uml.core.metamodel.profiles.AllProfilesTests;
058: import org.netbeans.modules.uml.core.metamodel.structure.AllStructureTests;
059: import org.netbeans.modules.uml.core.reverseengineering.parsers.umlparser.AllUMLParserTestSuite;
060: import org.netbeans.modules.uml.core.reverseengineering.reframework.AllREFrameworkTests;
061: import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.AllParsingFrameworkTests;
062: import org.netbeans.modules.uml.core.reverseengineering.reintegration.AllREIntegrationTests;
063: import org.netbeans.modules.uml.core.roundtripframework.requestprocessors.javarpcomponent.AllJavaRPComponentTests;
064: import org.netbeans.modules.uml.core.roundtripframework.roundtripevents.AllRoundtripEventsTests;
065: import org.netbeans.modules.uml.core.support.umlmessagingcore.AllMessagingCoreTests;
066: import org.netbeans.modules.uml.core.typemanagement.TypeManagerTestCase;
067: import org.netbeans.modules.uml.core.eventframework.EventFrameworkTests;
068: import org.netbeans.modules.uml.UMLCoreModule;
069: import java.io.BufferedInputStream;
070: import java.io.BufferedOutputStream;
071: import java.io.File;
072: import java.io.FileOutputStream;
073: import java.io.InputStream;
074: import java.util.Enumeration;
075: import java.util.zip.ZipEntry;
076: import java.util.zip.ZipFile;
077: import junit.framework.Test;
078: import junit.framework.TestSuite;
079:
080: /**
081: *
082: */
083: public class ModuleUnitTestSuiteBuilder {
084: public static Test suite() {
085: File deleteDir = createTempDotUmlDir();
086: TestSuite suite = new TestSuite("UML Core Module Unit Tests"); // NOI18N
087:
088: //$JUnit-BEGIN$
089: suite.addTest(AllJavaRPComponentTests.suite());
090: suite.addTest(AllREFrameworkTests.suite());
091: suite.addTest(AllGenerativeFrameworkTests.suite());
092: suite.addTest(AllConfigStringFrameworkTests.suite());
093: suite.addTest(AllParsingFrameworkTests.suite());
094: suite.addTest(AllBehaviorTests.suite());
095: suite.addTest(AllDynamicsTests.suite());
096: suite.addTest(new TestSuite(TypeManagerTestCase.class));
097: suite.addTest(new TestSuite(QueryManagerTestCase.class));
098: suite.addTest(new TestSuite(WorkspaceTestCase.class));
099: suite.addTest(AllStructureTests.suite());
100: suite.addTest(AllInfrastructureTests.suite());
101: suite.addTest(AllConstructsTests.suite());
102: suite.addTest(AllCommonActionsTests.suite());
103: suite.addTest(AllCommonActivitiesTests.suite());
104: suite.addTest(AllCoreInfraTests.suite());
105: suite.addTest(AllCommonStateMachineTests.suite());
106: suite.addTest(AllBasicActionsTests.suite());
107: suite.addTest(AllProfilesTests.suite());
108: suite.addTest(AllModelAnalysisTests.suite());
109: suite.addTest(AllREIntegrationTests.suite());
110: suite.addTest(AllMessagingCoreTests.suite());
111: suite.addTest(AllUMLParserTestSuite.suite());
112: suite.addTest(EventFrameworkTests.suite());
113: suite.addTest(AllRoundtripEventsTests.suite());
114:
115: // This needs to be last, since these test cases destroy the
116: // CoreProductManager.
117: suite.addTest(AllCoreApplicationTests.suite());
118:
119: //$JUnit-END$
120: return suite;
121: }
122:
123: public static void main(String args[]) {
124: junit.textui.TestRunner.run(suite());
125: }
126:
127: private static File createTempDotUmlDir() {
128: File tempDotUmlDir = null;
129:
130: try {
131: File javaTempDir = new File(System
132: .getProperty("java.io.tmpdir")); // NOI18N
133:
134: File temp = new File(javaTempDir, "dotuml.zip"); // NOI18N
135:
136: tempDotUmlDirName = javaTempDir + File.separator + ".uml"; // NOI18N
137:
138: // check to see if a temp .uml dir already exists
139: tempDotUmlDir = new File(tempDotUmlDirName);
140:
141: // if it already exists, it could be old and corrupted, so delete
142: // to be on the safe side
143: if (tempDotUmlDir.exists()) {
144: recursiveDelete(tempDotUmlDir);
145: }
146:
147: BufferedOutputStream dest = null;
148: BufferedInputStream is = null;
149: ZipEntry entry;
150:
151: ClassLoader loader = UMLCoreModule.class.getClassLoader();
152: InputStream in = null;
153:
154: if (loader != null) {
155: in = loader
156: .getResourceAsStream("org/netbeans/modules/uml/dotuml.zip"); // NOI18N
157: }
158:
159: else {
160: return null;
161: }
162:
163: if (in == null) {
164: return null;
165: }
166:
167: byte[] b = new byte[BUFFER];
168: int c = 0;
169:
170: FileOutputStream out = new FileOutputStream(temp);
171:
172: while ((c = in.read(b, 0, BUFFER)) != -1) {
173: out.write(b, 0, c);
174: }
175:
176: out.flush();
177: out.close();
178:
179: ZipFile zipfile = new ZipFile(temp); //NO I18n
180: Enumeration e = zipfile.entries();
181:
182: while (e.hasMoreElements()) {
183: entry = (ZipEntry) e.nextElement();
184: is = new BufferedInputStream(zipfile
185: .getInputStream(entry));
186: int count;
187: byte data[] = new byte[BUFFER];
188:
189: if (entry.isDirectory()) {
190: File f1 = new File(javaTempDir + File.separator
191: + entry.getName());
192:
193: f1.mkdirs();
194: }
195:
196: else {
197: FileOutputStream fos = new FileOutputStream(
198: javaTempDir + File.separator
199: + entry.getName());
200:
201: dest = new BufferedOutputStream(fos, BUFFER);
202:
203: while ((count = is.read(data, 0, BUFFER)) != -1) {
204: dest.write(data, 0, count);
205: }
206:
207: dest.flush();
208: dest.close();
209: is.close();
210: }
211: }
212:
213: temp.deleteOnExit();
214: javaTempDir.deleteOnExit();
215: }
216:
217: catch (Exception e) {
218: e.printStackTrace();
219: }
220:
221: return tempDotUmlDir;
222: }
223:
224: private static void recursiveDelete(File target) {
225: if (target.exists() == true) {
226: if (target.isDirectory() == true) {
227: File[] children = target.listFiles();
228:
229: for (int index = 0; index < children.length; index++) {
230: recursiveDelete(children[index]);
231: }
232: }
233:
234: target.delete();
235: }
236: }
237:
238: public static String tempDotUmlDirName = "";
239: static final int BUFFER = 2048;
240: }
|