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.test.uml.multipleprojects;
043:
044: import java.awt.event.KeyEvent;
045: import java.io.*;
046: import org.netbeans.jellytools.nodes.*;
047: import org.netbeans.jemmy.*;
048: import org.netbeans.jemmy.operators.*;
049: import org.netbeans.junit.NbTestSuite;
050: import org.netbeans.test.uml.multipleprojects.utils.MUPUtils;
051: import org.netbeans.test.umllib.CompartmentOperator;
052: import org.netbeans.test.umllib.CompartmentTypes;
053: import org.netbeans.test.umllib.DiagramElementOperator;
054: import org.netbeans.test.umllib.DiagramOperator;
055: import org.netbeans.test.umllib.ElementTypes;
056: import org.netbeans.test.umllib.NewDiagramWizardOperator;
057: import org.netbeans.test.umllib.Utils;
058: import org.netbeans.test.umllib.testcases.UMLTestCase;
059:
060: /**
061: *
062: * @author yaa
063: * @spec uml/FindReplaceAssociate.xml
064: */
065: public class ProjectLinkage extends UMLTestCase {
066: private static final String workDir = System
067: .getProperty("xtest.workdir");
068: private static String OUT_LOG_FILE = "";
069: private static String ERR_LOG_FILE = "";
070: private static PrintStream myOut = null;
071: private static PrintStream myErr = null;
072: private static BufferedReader myIn = null;
073:
074: private EventTool eventTool = new EventTool();
075:
076: /** Need to be defined because of JUnit */
077: public ProjectLinkage(String name) {
078: super (name);
079: }
080:
081: public static NbTestSuite suite() {
082: NbTestSuite suite = new NbTestSuite(
083: org.netbeans.test.uml.multipleprojects.ProjectLinkage.class);
084: return suite;
085: }
086:
087: public void testMoveElementToTree() {
088: String prName1 = "UMLProject1A";
089: String prName2 = "UMLProject1B";
090: String class1 = "C1";
091:
092: try {
093: Utils.createJavaUMLProject(prName1, workDir);
094: MUPUtils.createElement(prName1, class1, ElementTypes.CLASS
095: .toString());
096: Utils.createJavaUMLProject(prName2, workDir);
097:
098: if (!MUPUtils.moveElementInTree(prName1, prName2, class1)) {
099: fail("Test fails on moving element");
100: }
101: if ((MUPUtils.selectElementInModelTree(prName1, class1) != null)
102: || (MUPUtils.selectElementInModelTree(prName2,
103: class1) == null)) {
104: fail("Checking test results fail");
105: }
106: } catch (Exception e) {
107: fail("Test failed with unknown reason: " + e.getMessage());
108: }
109: }
110:
111: public void testImportElementToTree() {
112: String prName1 = "UMLProject2A";
113: String prName2 = "UMLProject2B";
114: String class1 = "C2";
115:
116: try {
117: Utils.createJavaUMLProject(prName1, workDir);
118: MUPUtils.createElement(prName1, class1, ElementTypes.CLASS
119: .toString());
120: Utils.createJavaUMLProject(prName2, workDir);
121:
122: if (!MUPUtils.importElementInTree(prName1, prName2, class1)) {
123: fail("Test fails on moving element");
124: }
125: if ((MUPUtils.selectElementInModelTree(prName1, class1) == null)
126: || (MUPUtils.selectElementInModelTree(prName2,
127: class1) != null)
128: || (MUPUtils.selectElementInImportTree(prName2,
129: prName1 + "|" + class1) == null)) {
130: fail("Checking test results fail");
131: }
132: } catch (Exception e) {
133: fail("Test failed with unknown reason: " + e.getMessage());
134: }
135: }
136:
137: public void testImportElementToDiagram() {
138: String prName1 = "UMLProject3A";
139: String prName2 = "UMLProject3B";
140: String cld = "CLD3";
141: String class1 = "C3";
142:
143: try {
144: Utils.createJavaUMLProject(prName1, workDir);
145: MUPUtils.createElement(prName1, class1, ElementTypes.CLASS
146: .toString());
147: Utils.createJavaUMLProject(prName2, workDir);
148: DiagramOperator dia = MUPUtils.openDiagram(prName2, cld,
149: NewDiagramWizardOperator.CLASS_DIAGRAM, workDir);
150:
151: if (!MUPUtils.importElementToDiagram(prName1, prName2,
152: class1, cld)) {
153: fail("Test fails on moving element");
154: }
155: DiagramElementOperator el = new DiagramElementOperator(dia,
156: class1);
157: CompartmentOperator co = new CompartmentOperator(el,
158: CompartmentTypes.PACKAGE_IMPORT_COMPARTMENT);
159: if ((MUPUtils.selectElementInModelTree(prName1, class1) == null)
160: || (MUPUtils.selectElementInModelTree(prName2,
161: class1) != null)
162: || (MUPUtils.selectElementInImportTree(prName2,
163: prName1 + "|" + class1) == null)
164: || (!co.getName().equals(
165: "{ Imported from " + prName1 + " }"))) {
166: fail("Checking test results fail");
167: }
168: } catch (Exception e) {
169: fail("Test failed with unknown reason: " + e.getMessage());
170: }
171: }
172:
173: public void testMovePackageToTree() {
174: String prName1 = "UMLProject4A";
175: String prName2 = "UMLProject4B";
176: String pkg = "pkg4";
177:
178: try {
179: Utils.createJavaUMLProject(prName1, workDir);
180: MUPUtils.createPackage(prName1, pkg);
181: Utils.createJavaUMLProject(prName2, workDir);
182:
183: if (!MUPUtils.moveElementInTree(prName1, prName2, pkg)) {
184: fail("Test fails on moving element");
185: }
186: if ((MUPUtils.selectElementInModelTree(prName1, pkg) != null)
187: || (MUPUtils.selectElementInModelTree(prName2, pkg) == null)) {
188: fail("Checking test results fail");
189: }
190: } catch (Exception e) {
191: fail("Test failed with unknown reason: " + e.getMessage());
192: }
193: }
194:
195: public void testImportPackageToTree() {
196: String prName1 = "UMLProject5A";
197: String prName2 = "UMLProject5B";
198: String pkg = "pkg5";
199:
200: try {
201: Utils.createJavaUMLProject(prName1, workDir);
202: MUPUtils.createPackage(prName1, pkg);
203: Utils.createJavaUMLProject(prName2, workDir);
204:
205: if (!MUPUtils.importElementInTree(prName1, prName2, pkg)) {
206: fail("Test fails on moving element");
207: }
208: if ((MUPUtils.selectElementInModelTree(prName1, pkg) == null)
209: || (MUPUtils.selectElementInModelTree(prName2, pkg) != null)
210: || (MUPUtils.selectElementInImportTree(prName2,
211: prName1 + "|" + pkg) == null)) {
212: fail("Checking test results fail");
213: }
214: } catch (Exception e) {
215: fail("Test failed with unknown reason: " + e.getMessage());
216: }
217: }
218:
219: public void testImportPackageToDiagram() {
220: String prName1 = "UMLProject6A";
221: String prName2 = "UMLProject6B";
222: String cld = "CLD6";
223: String pkg = "pkg6";
224:
225: try {
226: Utils.createJavaUMLProject(prName1, workDir);
227: MUPUtils.createPackage(prName1, pkg);
228: Utils.createJavaUMLProject(prName2, workDir);
229: DiagramOperator dia = MUPUtils.openDiagram(prName2, cld,
230: NewDiagramWizardOperator.CLASS_DIAGRAM, workDir);
231:
232: if (!MUPUtils.importElementToDiagram(prName1, prName2, pkg,
233: cld)) {
234: fail("Test fails on moving element");
235: }
236: DiagramElementOperator el = new DiagramElementOperator(dia,
237: pkg);
238: CompartmentOperator co = new CompartmentOperator(el,
239: CompartmentTypes.PACKAGE_IMPORT_COMPARTMENT);
240: if ((MUPUtils.selectElementInModelTree(prName1, pkg) == null)
241: || (MUPUtils.selectElementInModelTree(prName2, pkg) != null)
242: || (MUPUtils.selectElementInImportTree(prName2,
243: prName1 + "|" + pkg) == null)
244: || (!co.getName().equals(
245: "{ Imported from " + prName1 + " }"))) {
246: fail("Checking test results fail");
247: }
248: } catch (Exception e) {
249: fail("Test failed with unknown reason: " + e.getMessage());
250: }
251: }
252:
253: public void testDeleteImportedElementFromTree() {
254: String prName1 = "UMLProject7A";
255: String prName2 = "UMLProject7B";
256: String class1 = "C7";
257:
258: try {
259: Utils.createJavaUMLProject(prName1, workDir);
260: MUPUtils.createElement(prName1, class1, ElementTypes.CLASS
261: .toString());
262: Utils.createJavaUMLProject(prName2, workDir);
263:
264: if (!MUPUtils.importElementInTree(prName1, prName2, class1)) {
265: fail("Test fails on importing element");
266: }
267:
268: Node node = MUPUtils.selectElementInImportTree(prName2,
269: prName1 + "|" + class1);
270: MUPUtils.pushKey(KeyEvent.VK_DELETE);
271: // node.callPopup().pushMenuNoBlock(PopupConstants.DELETE);
272:
273: new JButtonOperator(new JDialogOperator(
274: "Delete Imported Element"), "Yes").pushNoBlock();
275:
276: Thread.sleep(1500);
277:
278: if (MUPUtils.selectElementInModelTree(prName1, class1) == null) {
279: fail("Original element '" + class1
280: + "' not found (only import should be deleted)");
281: }
282: if (MUPUtils.selectElementInImportTree(prName2, prName1
283: + "|" + class1) != null) {
284: fail("Import not deleted");
285: }
286: } catch (Exception e) {
287: fail("Test failed with unknown reason: " + e.getMessage());
288: }
289: }
290:
291: public void testDeleteImportedPackageFromTree() {
292: String prName1 = "UMLProject8A";
293: String prName2 = "UMLProject8B";
294: String pkg = "pkg8";
295:
296: try {
297: Utils.createJavaUMLProject(prName1, workDir);
298: MUPUtils.createPackage(prName1, pkg);
299: Utils.createJavaUMLProject(prName2, workDir);
300:
301: if (!MUPUtils.importElementInTree(prName1, prName2, pkg)) {
302: fail("Test fails on importing package");
303: }
304:
305: Node node = MUPUtils.selectElementInImportTree(prName2,
306: prName1 + "|" + pkg);
307:
308: new Thread(new Runnable() {
309: public void run() {
310: long timeoutValDlg = JemmyProperties
311: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
312: try {
313: JemmyProperties
314: .setCurrentTimeout(
315: "DialogWaiter.WaitDialogTimeout",
316: 10000);
317: new JButtonOperator(new JDialogOperator(
318: "Deleting a Package"), "Yes")
319: .pushNoBlock();
320: } catch (Exception e) {
321: } finally {
322: JemmyProperties.setCurrentTimeout(
323: "DialogWaiter.WaitDialogTimeout",
324: timeoutValDlg);
325: }
326: }
327: }).start();
328:
329: MUPUtils.pushKey(KeyEvent.VK_DELETE);
330: // node.callPopup().pushMenuNoBlock(PopupConstants.DELETE);
331: new JButtonOperator(new JDialogOperator(
332: "Delete Imported Element"), "Yes").pushNoBlock();
333:
334: Thread.sleep(1500);
335:
336: if (MUPUtils.selectElementInModelTree(prName1, pkg) == null) {
337: fail("Original package '" + pkg
338: + "' not found (only import should be deleted)");
339: }
340: if (MUPUtils.selectElementInImportTree(prName2, prName1
341: + "|" + pkg) != null) {
342: fail("Import not deleted");
343: }
344: } catch (Exception e) {
345: fail("Test failed with unknown reason: " + e.getMessage());
346: }
347: }
348:
349: //------------------------------------------------------------------------------
350:
351: public void setUp() throws FileNotFoundException {
352: System.out.println("######## " + getName() + " #######");
353:
354: OUT_LOG_FILE = workDir + File.separator + "jout_" + getName()
355: + ".log";
356: ERR_LOG_FILE = workDir + File.separator + "jerr_" + getName()
357: + ".log";
358:
359: myOut = new PrintStream(new FileOutputStream(OUT_LOG_FILE),
360: true);
361: myErr = new PrintStream(new FileOutputStream(ERR_LOG_FILE),
362: true);
363: JemmyProperties.setCurrentOutput(new TestOut(System.in, myOut,
364: myErr));
365: }
366:
367: public void tearDown() throws FileNotFoundException, IOException,
368: InterruptedException {
369: org.netbeans.test.umllib.util.Utils.tearDown();
370: long timeout = JemmyProperties
371: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
372: try {
373: JemmyProperties.setCurrentTimeout(
374: "DialogWaiter.WaitDialogTimeout", 2000);
375: JDialogOperator dlgError = new JDialogOperator(
376: "Unexpected Exception");
377: JTextAreaOperator textarea = new JTextAreaOperator(dlgError);
378: String str = textarea.getDisplayedText();
379: int pos = str.indexOf("\n");
380: if (pos != -1) {
381: str = str.substring(1, pos - 1);
382: }
383: dlgError.close();
384: fail(" " + str);
385: } catch (TimeoutExpiredException e) {
386: } finally {
387: JemmyProperties.setCurrentTimeout(
388: "DiagramOperator.WaitDiagramOperator", timeout);
389: }
390:
391: myIn = new BufferedReader(new FileReader(ERR_LOG_FILE));
392: String line;
393: do {
394: line = myIn.readLine();
395: if (line != null && line.indexOf("Exception") != -1) {
396: if ((line.indexOf("Unexpected Exception") == -1)
397: && (line.indexOf("TimeoutExpiredException") == -1)) {
398: //fail(line);
399: }
400: }
401: } while (line != null);
402: }
403: }
|