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.componentdiagram;
043:
044: import java.awt.event.InputEvent;
045: import java.awt.event.KeyEvent;
046: import java.io.File;
047: import java.io.FileNotFoundException;
048: import java.io.FileReader;
049: import java.io.IOException;
050: import org.netbeans.jellytools.ProjectsTabOperator;
051: import org.netbeans.jellytools.nodes.Node;
052: import org.netbeans.jellytools.properties.PropertySheetOperator;
053: import org.netbeans.jemmy.EventTool;
054: import org.netbeans.jemmy.JemmyProperties;
055: import org.netbeans.jemmy.Timeouts;
056: import org.netbeans.jemmy.operators.JButtonOperator;
057: import org.netbeans.jemmy.operators.JDialogOperator;
058: import org.netbeans.jemmy.operators.JTreeOperator;
059:
060: import org.netbeans.junit.NbTestSuite;
061:
062: import org.netbeans.test.umllib.DiagramElementOperator;
063: import org.netbeans.test.umllib.DiagramOperator;
064: import org.netbeans.test.umllib.DrawingAreaOperator;
065: import org.netbeans.test.umllib.ExpandedElementTypes;
066: import org.netbeans.test.umllib.LinkOperator;
067: import org.netbeans.test.umllib.LinkTypes;
068: import org.netbeans.test.umllib.UMLPaletteOperator;
069: import org.netbeans.test.umllib.exceptions.NotFoundException;
070: import org.netbeans.test.umllib.testcases.UMLMultiTestCase;
071: import org.netbeans.test.umllib.testcases.UMLMultiTestSuite;
072: import org.netbeans.test.umllib.testcases.UMLTestCase;
073: import org.netbeans.test.umllib.util.LibProperties;
074:
075: /**
076: *
077: * @author psb
078: */
079: public class ComDPlaceAllLinks extends UMLMultiTestSuite {
080:
081: private static String[] Test_Cases = { "PlaceLinks" };
082:
083: private static boolean makeScreen = false;
084:
085: protected UMLMultiTestCase[] cases() {
086: return new UMLMultiTestCase[] { new PlaceLinks() };
087: }
088:
089: //common test properties
090: private static String prName = "componentDiagramProjectLinks";
091: private static String lastPrName = null;
092: private static String project = prName + "|Model";
093: private static String lastProject = lastPrName + "|Model";
094: private static String sourceProject = "source";
095: private static boolean codeSync = false;
096: private ProjectsTabOperator pto = null;
097: private Node lastDiagramNode = null;
098: private JTreeOperator prTree = null;
099: private static String workdir = System.getProperty("xtest.workdir");
100: private String lastTestCase = null;
101: //
102: private static PlaceLinks testClass = null;
103: //--
104: private static long testCounter = 0;
105: private static String componentDiagramName = "cpD";
106: private static String workPkg = "pkg";
107: private static LinkTypes[] allLinkTypes = {
108: LinkTypes.GENERALIZATION, LinkTypes.IMPLEMENTATION,
109: LinkTypes.NESTED_LINK, LinkTypes.DELEGATE, LinkTypes.USAGE,
110: LinkTypes.DERIVATION_EDGE, LinkTypes.ASSOCIATION,
111: LinkTypes.COMPOSITION, LinkTypes.NAVIGABLE_COMPOSITION,
112: LinkTypes.AGGREGATION, LinkTypes.NAVIGABLE_AGGREGATION,
113: LinkTypes.NAVIGABLE_ASSOCIATION,
114: LinkTypes.ASSOCIATION_CLASS, LinkTypes.ROLE_BINDING,
115: LinkTypes.COMMENT };
116: private static ExpandedElementTypes[] allElementTypes = {
117: ExpandedElementTypes.COMPONENT, ExpandedElementTypes.CLASS,
118: ExpandedElementTypes.INTERFACE,
119: ExpandedElementTypes.PACKAGE,
120: ExpandedElementTypes.ARTIFACT,
121: ExpandedElementTypes.ASSEMBLY_CONNECTOR,
122: ExpandedElementTypes.TEMPLATE_CLASS,
123: ExpandedElementTypes.DERIVATION_CLASSIFIER,
124: ExpandedElementTypes.DESIGN_PATTERN,
125: ExpandedElementTypes.ROLE,
126: ExpandedElementTypes.INTERFACE_ROLE,
127: ExpandedElementTypes.ACTOR_ROLE,
128: ExpandedElementTypes.CLASS_ROLE,
129: ExpandedElementTypes.USE_CASE_ROLE,
130: ExpandedElementTypes.ROLE_BINDING,
131: ExpandedElementTypes.COMMENT,
132: ExpandedElementTypes.LINK_COMMENT };
133:
134: /** Need to be defined because of JUnit */
135: public ComDPlaceAllLinks(String name) {
136: super (name);
137: }
138:
139: public static NbTestSuite suite() {
140: return new ComDPlaceAllLinks("PlaceLinks");
141: }
142:
143: ////////////////////////
144: public void setUp0() {
145: makeScreen = true;
146: //
147: File store = new File(
148: workdir
149: + "/user/org.netbeans.test.uml.componentdiagram.ComDPlaceAllLinks$PlaceLinks/store.txt");
150: if (store.exists()) {
151: try {
152: FileReader read = new FileReader(store);
153: } catch (FileNotFoundException ex) {
154: ex.printStackTrace();
155: }
156: } else {
157: try {
158: store.createNewFile();
159: } catch (IOException ex) {
160: ex.printStackTrace();
161: }
162: }
163: //
164: int testNum = l + t * allLinkTypes.length + f
165: * allLinkTypes.length * allElementTypes.length;
166: testCounter = testNum;
167: if (((testCounter - 1) % 15) == 0) {
168: lastPrName = prName + testNum;
169: lastProject = lastPrName + "|Model";
170: org.netbeans.test.uml.componentdiagram.utils.Utils
171: .commonComponentDiagramSetup(workdir, lastPrName);
172: }
173: }
174:
175: public void tearDown0(PlaceLinks tc) {
176: if (makeScreen)
177: org.netbeans.test.umllib.util.Utils
178: .makeScreenShot(
179: "org.netbeans.test.uml.componentdiagram.ComDPlaceAllLinks$PlaceLinks",
180: this .getName());
181: //tc.closeAllModal();
182: long tmp = JemmyProperties
183: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
184: long tmp2 = JemmyProperties
185: .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
186: JemmyProperties.setCurrentTimeout(
187: "DialogWaiter.WaitDialogTimeout", 1000);
188: JemmyProperties.setCurrentTimeout(
189: "ComponentOperator.WaitComponentTimeout", 1000);
190: org.netbeans.test.umllib.util.Utils.saveAll();
191: try {
192: DiagramOperator d = new DiagramOperator(
193: componentDiagramName);
194: DrawingAreaOperator drAr = d.getDrawingArea();
195: drAr.pushKey(KeyEvent.VK_ESCAPE);
196: java.awt.Point a = drAr.getFreePoint();
197: drAr.clickMouse(a.x, a.y, 1, InputEvent.BUTTON3_MASK);
198: drAr.pushKey(KeyEvent.VK_ESCAPE);
199: new Thread(new Runnable() {
200: public void run() {
201: try {
202: Thread.sleep(1000);
203: } catch (Exception ex) {
204: }
205: new JButtonOperator(new JDialogOperator(
206: "Save Diagram"), "Discard").push();
207: }
208: }).start();
209: d.closeAllDocuments();
210: } catch (Exception ex) {
211: }
212: ;
213: //closeAllModal();
214: JemmyProperties.setCurrentTimeout(
215: "ComponentOperator.WaitComponentTimeout", tmp2);
216: JemmyProperties.setCurrentTimeout(
217: "DialogWaiter.WaitDialogTimeout", tmp);
218: //
219: if (lastDiagramNode != null) {
220: Node pkgN = new Node(prTree, lastDiagramNode
221: .getParentPath());
222: pkgN.performPopupActionNoBlock("Delete");
223: JDialogOperator dlg = new JDialogOperator(
224: "Confirm Object Deletion");
225: new JButtonOperator(dlg, "Yes").pushNoBlock();
226: dlg.waitClosed();
227: //dlg=new JDialogOperator("Deleting a Package");
228: //new JButtonOperator(dlg,"Yes").pushNoBlock();
229: //dlg.waitClosed();
230: pkgN.waitNotPresent();
231: }
232: //
233: if ((testCounter % 15) == 0) {
234: Node root = new Node(prTree, lastPrName);
235: root.performPopupAction("Close");
236: try {
237: Thread.sleep(1000);
238: } catch (Exception ex) {
239: }
240: System.gc();
241: try {
242: Thread.sleep(15000);
243: } catch (Exception ex) {
244: }
245: } else {
246: try {
247: Thread.sleep(1000);
248: } catch (Exception ex) {
249: }
250: System.gc();
251: try {
252: Thread.sleep(1000);
253: } catch (Exception ex) {
254: }
255: }
256: //
257: //tc.closeAllModal();
258: }
259:
260: ////////////////////////
261: //
262: private int f = 0, t = 0, l = 0;
263:
264: public class PlaceLinks extends UMLMultiTestCase {
265: ExpandedElementTypes elFrom;
266: ExpandedElementTypes elTo;
267: LinkTypes lnk;
268:
269: PlaceLinks() {
270:
271: }
272:
273: private void setParams(ExpandedElementTypes elFrom,
274: ExpandedElementTypes elTo, LinkTypes lnk) {
275: this .elFrom = elFrom;
276: this .elTo = elTo;
277: this .lnk = lnk;
278: }
279:
280: public void prepare() {
281: makeScreen = true;
282: testClass = new PlaceLinks();
283: //org.netbeans.test.uml.componentdiagram.utils.Utils.commonComponentDiagramSetup(workdir,prName);
284: }
285:
286: //
287: public void setUp() {
288: setUp0();
289: }
290:
291: public UMLMultiTestCase create() {
292: if (f < allElementTypes.length
293: && t < allElementTypes.length
294: && l < allLinkTypes.length) {
295: testClass.setParams(allElementTypes[f],
296: allElementTypes[t], allLinkTypes[l]);
297: testClass.setName("test" + allLinkTypes[l] + "LinkOn"
298: + allElementTypes[f] + "To"
299: + allElementTypes[t]);
300: } else
301: testClass = null;
302: l++;
303: if (l >= allLinkTypes.length) {
304: l = 0;
305: t++;
306: }
307: if (t >= allElementTypes.length) {
308: t = 0;
309: f++;
310: }
311: //
312: return testClass;
313: }
314:
315: //
316: public void execute() {
317: int testNum = l + t * allLinkTypes.length + f
318: * allLinkTypes.length * allElementTypes.length;
319: testLinkPlace(this , workPkg + testNum, componentDiagramName
320: + testNum, elFrom, elTo, lnk, lnk.toString(), false);
321: makeScreen = false;
322: }
323:
324: //
325: public void tearDown() {
326: tearDown0(this );
327: }
328:
329: //
330: public void cleanup() {
331: org.netbeans.test.umllib.util.Utils.tearDown();
332: }
333:
334: }
335:
336: private DiagramOperator createOrOpenDiagram(UMLTestCase tc,
337: String project, String workPkg, String diagram) {
338: org.netbeans.test.umllib.Utils.RetAll rt = org.netbeans.test.umllib.Utils
339: .createOrOpenDiagram(
340: project,
341: workPkg,
342: diagram,
343: org.netbeans.test.umllib.NewDiagramWizardOperator.COMPONENT_DIAGRAM);
344: pto = rt.pto;
345: prTree = new JTreeOperator(pto);
346: lastDiagramNode = rt.lastDiagramNode;
347: return rt.dOp;
348: }
349:
350: private void testLinkPlace(UMLTestCase tc, String workPkg,
351: String diagramName, ExpandedElementTypes fromType,
352: ExpandedElementTypes toType, LinkTypes lnkType,
353: String treeNode, boolean useIO) {
354: String localElName1 = "El1";
355: String localElName2 = "El2";
356: String newName = "LinkName";
357: //workaround for nested linkd
358: if (lnkType.equals(LinkTypes.NESTED_LINK))
359: lnkType = LinkTypes.NESTED_LINK.NESTED_LINK(toType
360: .toString());
361: //
362: String linkInPalette = LibProperties
363: .getCurrentToolName(lnkType);
364: String defaultLinkName = LibProperties
365: .getCurrentDefaultName(lnkType);
366: //
367: DiagramOperator d = createOrOpenDiagram(tc, lastProject,
368: workPkg, diagramName);
369: //
370: Node pkgNode = new Node(prTree, lastDiagramNode.getParentPath());
371: int numChild = pkgNode.getChildren().length;
372: //
373: UMLPaletteOperator pl = new UMLPaletteOperator();
374: DrawingAreaOperator drAr = d.getDrawingArea();
375: //
376: java.awt.Point a = drAr.getFreePoint();
377: DiagramElementOperator dE1 = null, dE2 = null;
378: try {
379: dE1 = d.putElementOnDiagram(localElName1, fromType, a.x,
380: a.y);
381: a = drAr.getFreePoint(200);
382: dE2 = d.putElementOnDiagram(localElName2, toType, a.x, a.y);
383: } catch (Exception ex) {
384: tc.fail("Element placement error: " + ex);
385: }
386: //
387: try {
388: pl.selectTool(linkInPalette);
389: } catch (NotFoundException ex) {
390: tc.fail("BLOCKING: Can't find '" + linkInPalette
391: + "' in paletter");
392: }
393: //
394: drAr.clickMouse(dE1.getCenterPoint().x, dE1.getCenterPoint().y,
395: 1);
396: drAr.clickMouse(dE2.getCenterPoint().x, dE2.getCenterPoint().y,
397: 1);
398: //
399: new EventTool().waitNoEvent(2000);
400: //
401: LinkOperator testedlink = null;
402: LinkOperator altLink = null;
403: Timeouts t = JemmyProperties.getCurrentTimeouts();
404: long waitLinkOld = t.getTimeout("LinkOperator.WaitLinkTime");
405: t.setTimeout("LinkOperator.WaitLinkTime", 5000);
406: try {
407: testedlink = LinkOperator.waitForLink(dE1, dE2,
408: new LinkOperator.LinkByTypeChooser(lnkType), 0);
409: } catch (Exception ex) {
410: //tc.fail(linkInPalette+" of type "+lnkType+" wasn't added to diagram:"+ex);
411: }
412: if (testedlink == null) {
413: try {
414: altLink = LinkOperator.waitForLink(dE1, dE2,
415: new LinkOperator.LinkByTypeChooser(
416: LinkTypes.ANY), 0);
417: } catch (Exception ex) {
418: //tc.fail("any link find failed.");
419: }
420: }
421: t.setTimeout("LinkOperator.WaitLinkTime", waitLinkOld);
422: boolean shouldBe = true;
423: //***
424: if (lnkType.equals(LinkTypes.DERIVATION_EDGE)
425: && !(fromType
426: .equals(ExpandedElementTypes.DERIVATION_CLASSIFIER) && toType
427: .equals(ExpandedElementTypes.COMPONENT)))
428: shouldBe = false;
429: else if (lnkType.equals(LinkTypes.ROLE_BINDING)
430: && (!(fromType
431: .equals(ExpandedElementTypes.DESIGN_PATTERN) && toType
432: .name().indexOf("ROLE") > -1) || !(toType
433: .equals(ExpandedElementTypes.DESIGN_PATTERN) && fromType
434: .name().indexOf("ROLE") > -1)))
435: shouldBe = false;
436: //###
437: //next steps are appropriate only if link should exists
438: if (!shouldBe) {
439: if (testedlink != null)
440: tc.fail("There is " + lnkType
441: + " link between elements.");
442: else if (altLink != null)
443: tc.fail("There is " + altLink
444: + " link between elements.");
445: } else {
446: if (testedlink == null && altLink != null)
447: tc.fail("Can't find " + lnkType
448: + " link between elements, but the is "
449: + altLink.getType() + " link.");
450: else if (testedlink == null)
451: tc.fail("There is no link between elements.");
452: PropertySheetOperator ps = null;
453: String propTitlePrefix = lnkType.toString();
454: //***
455: if (lnkType.equals(LinkTypes.NESTED_LINK))
456: propTitlePrefix = localElName2;
457: //###
458: try {
459: ps = new PropertySheetOperator(propTitlePrefix
460: + " - Properties");
461: } catch (org.netbeans.jemmy.TimeoutExpiredException ex) {
462: ps = new PropertySheetOperator();
463: throw ex;
464: }
465: org.netbeans.test.uml.componentdiagram.utils.Utils
466: .setTextProperty("Name", newName);
467: new EventTool().waitNoEvent(500);
468: //check link after renaming
469: testedlink = null;
470: altLink = null;
471: try {
472: testedlink = LinkOperator.findLink(dE1, dE2,
473: new LinkOperator.LinkByTypeChooser(lnkType), 0);
474: } catch (Exception ex) {
475: //tc.fail(linkInPalette+" of type "+lnkType+" wasn't added to diagram:"+ex);
476: }
477: if (testedlink == null) {
478: try {
479: altLink = LinkOperator.findLink(dE1, dE2,
480: new LinkOperator.LinkByTypeChooser(
481: LinkTypes.ANY), 0);
482: } catch (Exception ex) {
483: //tc.fail("any link find failed.");
484: }
485: }
486: if (testedlink == null && altLink != null)
487: tc
488: .fail("Can't find "
489: + lnkType
490: + " link between elements after renaming, but the is "
491: + altLink.getType() + " link.");
492: else if (testedlink == null)
493: tc
494: .fail("There is no link between elements after renaming.");
495: //***
496: if (!LinkTypes.DERIVATION_EDGE.equals(lnkType))
497: tc
498: .assertTrue("Link name isn't correct: "
499: + testedlink.getName()
500: + ", should be: " + newName, newName
501: .equals(testedlink.getName()));
502: //###
503: //***
504: if (lnkType.equals(LinkTypes.NESTED_LINK)) {
505: Node n2 = new Node(pkgNode, localElName2);
506: Node n1 = new Node(n2, localElName1);
507: } else if (lnkType.equals(LinkTypes.ROLE_BINDING)) {
508:
509: } else {
510: Node n1 = new Node(pkgNode, localElName1);
511: Node n2 = new Node(pkgNode, localElName2);
512: Node rel1 = new Node(n1, "Relationships");
513: Node rel2 = new Node(n2, "Relationships");
514: new EventTool().waitNoEvent(500);
515: if (useIO) {
516: Node nI = new Node(rel1, "Outgoing Edges");
517: Node nO = new Node(rel2, "Incoming Edges");
518: tc
519: .assertTrue(
520: "There should be only one node within Outgoing Edges node",
521: nO.getChildren().length == 1);
522: tc
523: .assertTrue(
524: "There should be only one node within Incoming Edges node",
525: nI.getChildren().length == 1);
526: tc.assertTrue("There should be " + newName
527: + " node within Outgoing Edges node", nO
528: .getChildren()[0].equals(newName));
529: tc.assertTrue("There should be " + newName
530: + " node within Incoming Edges node", nI
531: .getChildren()[0].equals(newName));
532: Node nMO = new Node(nO, newName.toString());
533: Node nMI = new Node(nI, newName.toString());
534: new EventTool().waitNoEvent(500);
535: tc
536: .assertTrue(
537: "There should be only one node within "
538: + newName
539: + " node within Outgoing Edges node",
540: nMO.getChildren().length == 1);
541: tc
542: .assertTrue(
543: "There should be only one node within "
544: + newName
545: + " node within Incoming Edges node",
546: nMI.getChildren().length == 1);
547: tc
548: .assertTrue(
549: "There should be "
550: + localElName2
551: + " node within flow node within Outgoing Edges node",
552: nMO.isChildPresent(localElName2));
553: tc
554: .assertTrue(
555: "There should be "
556: + localElName1
557: + " node within flow node within Incoming Edges node",
558: nMI.isChildPresent(localElName1));
559: } else {
560: tc.assertTrue("There should be " + newName
561: + " node within Relationships node of "
562: + localElName1, rel1.getChildren()[0]
563: .equals(newName));
564: tc.assertTrue("There should be " + newName
565: + " node within Relationships node of "
566: + localElName2, rel2.getChildren()[0]
567: .equals(newName));
568: Node rn1 = new Node(rel1, newName);
569: Node rn2 = new Node(rel2, newName);
570: new EventTool().waitNoEvent(500);
571: if (LinkTypes.DELEGATE.equals(lnkType)) {
572: tc
573: .assertTrue(
574: 86374,
575: "there is no nodes within delegate node",
576: rn1.getChildren().length > 0);
577: tc
578: .assertTrue(
579: 86374,
580: "there is no nodes within delegate node",
581: rn2.getChildren().length > 0);
582: }
583: tc.assertTrue(
584: "There should be only one node within "
585: + newName + " node, now: "
586: + rn1.getChildren().length, rn1
587: .getChildren().length == 1);
588: tc.assertTrue(
589: "There should be only one node within "
590: + newName + " node, now: "
591: + rn2.getChildren().length, rn2
592: .getChildren().length == 1);
593: Node de1 = new Node(rn1, localElName2);
594: Node de2 = new Node(rn2, localElName1);
595: }
596: }
597: //###
598: }
599: }
600: }
|