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 org.netbeans.jellytools.MainWindowOperator;
047: import org.netbeans.jellytools.ProjectsTabOperator;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jellytools.properties.PropertySheetOperator;
050: import org.netbeans.jemmy.EventTool;
051: import org.netbeans.jemmy.JemmyException;
052: import org.netbeans.jemmy.JemmyProperties;
053: import org.netbeans.jemmy.operators.JButtonOperator;
054: import org.netbeans.jemmy.operators.JDialogOperator;
055: import org.netbeans.jemmy.operators.JMenuItemOperator;
056: import org.netbeans.jemmy.operators.JPopupMenuOperator;
057: import org.netbeans.jemmy.operators.JTreeOperator;
058:
059: import org.netbeans.junit.NbTestSuite;
060: import org.netbeans.test.umllib.DiagramElementOperator;
061: import org.netbeans.test.umllib.DiagramOperator;
062: import org.netbeans.test.umllib.DrawingAreaOperator;
063: import org.netbeans.test.umllib.ElementTypes;
064: import org.netbeans.test.umllib.ExpandedElementTypes;
065: import org.netbeans.test.umllib.LinkOperator;
066: import org.netbeans.test.umllib.LinkTypes;
067: import org.netbeans.test.umllib.NewDiagramWizardOperator;
068: import org.netbeans.test.umllib.UMLPaletteOperator;
069: import org.netbeans.test.umllib.exceptions.NotFoundException;
070: import org.netbeans.test.umllib.testcases.UMLTestCase;
071: import org.netbeans.test.umllib.util.LabelsAndTitles;
072: import org.netbeans.test.umllib.util.LibProperties;
073:
074: /**
075: *
076: * @author psb
077: * @spec UML/ComponentDiagram.xml
078: */
079: public class ComponentDiagramElementsContextMenu extends UMLTestCase {
080:
081: //some system properties
082: private static String contextPropItemName = "Properties";
083: private static String umlPropertyWindowTitle = "Project Properties";
084: private static String umlSourcePackagesLabel = "Source Packages";
085: private static String umlSourcePackagesColumn = "Folder Label";
086: private static String umlSourceUsageColumn = "Model?";
087: private static String mainTreeTabName = "Projects";
088: //common test properties
089: private static String prName = "ComponentDiagramProjectECM";
090: private static String project = prName + "|Model";
091: private static String sourceProject = "source";
092: private static boolean codeSync = false;
093: private static String defaultNewElementName = org.netbeans.test.uml.componentdiagram.utils.Utils.defaultNewElementName;
094: private static String defaultReturnType = org.netbeans.test.uml.componentdiagram.utils.Utils.defaultReturnType;
095: private static String defaultAttributeType = org.netbeans.test.uml.componentdiagram.utils.Utils.defaultAttributeType;
096: private static String defaultAttributeVisibility = org.netbeans.test.uml.componentdiagram.utils.Utils.defaultAttributeVisibility;
097: private static String defaultOperationVisibility = org.netbeans.test.uml.componentdiagram.utils.Utils.defaultOperationVisibility;
098: private ProjectsTabOperator pto = null;
099: private Node lastDiagramNode = null;
100: private String lastTestCase = null;
101: private static String workdir = System.getProperty("xtest.workdir");
102: //
103: private static String activityDiagramName0 = "cpD";
104: private static String workPkg0 = "pkg";
105: private static long counter = 0;
106: //--
107: private static ExpandedElementTypes elementType1 = ExpandedElementTypes.COMPONENT;
108: private static String menuItems1[] = { "Edit|Lock Edit",
109: "Resize Element to Contents", "Reset Edges",
110: "Hide|Parents|One Level", "Hide|Parents|All Levels",
111: "Hide|Children|One Level", "Hide|Children|All Levels",
112: "Show|Parents|One Level", "Show|Parents|All Levels",
113: "Show|Children|One Level", "Show|Children|All Levels",
114: "Generate Dependency Diagram",
115: elementType1.toString() + "|Font",
116: elementType1.toString() + "|Font Color",
117: elementType1.toString() + "|Background Color",
118: elementType1.toString() + "|Border Color" };
119: //--
120: private static ExpandedElementTypes elementType2 = ExpandedElementTypes.CLASS;
121: private static String menuItems2[] = { "Insert Attribute",
122: "Delete Attribute", "Edit|Lock Edit",
123: "Compartment|Customize...", "Resize Element to Contents",
124: "Transform|To Actor", "Transform|To Class",
125: "Transform|To Interface", "Transform|To DataType",
126: "Transform|To Enumeration", "Reset Edges",
127: "Hide|Parents|One Level", "Hide|Parents|All Levels",
128: "Hide|Children|One Level", "Hide|Children|All Levels",
129: "Show|Parents|One Level", "Show|Parents|All Levels",
130: "Show|Children|One Level", "Show|Children|All Levels",
131: "Redefine Operations", "Generate Dependency Diagram",
132: elementType2.toString() + "|Font",
133: elementType2.toString() + "|Font Color",
134: elementType2.toString() + "|Background Color",
135: elementType2.toString() + "|Border Color" };
136: //--
137: private static ExpandedElementTypes elementType3 = ExpandedElementTypes.INTERFACE;
138: private static String menuItems3[] = { "Edit|Lock Edit",
139: "Compartment|Customize...", "Resize Element to Contents",
140: "Transform|To Actor", "Transform|To Class",
141: "Transform|To Interface", "Transform|To DataType",
142: "Transform|To Enumeration", "Reset Edges",
143: "Hide|Parents|One Level", "Hide|Parents|All Levels",
144: "Hide|Children|One Level", "Hide|Children|All Levels",
145: "Show|As Icon", "Show|Parents|One Level",
146: "Show|Parents|All Levels", "Show|Children|One Level",
147: "Show|Children|All Levels", "Redefine Operations",
148: "Generate Dependency Diagram",
149: elementType3.toString() + "|Font",
150: elementType3.toString() + "|Font Color",
151: elementType3.toString() + "|Background Color",
152: elementType3.toString() + "|Border Color" };
153: //--
154: private static ExpandedElementTypes elementType4 = ExpandedElementTypes.PACKAGE;
155: private static String menuItems4[] = { "Edit|Lock Edit",
156: "Resize Element to Contents", "Reset Edges",
157: "Hide|Parents|One Level", "Hide|Parents|All Levels",
158: "Hide|Children|One Level", "Hide|Children|All Levels",
159: "Show|Name in Tab", "Show|Parents|One Level",
160: "Show|Parents|All Levels", "Show|Children|One Level",
161: "Show|Children|All Levels",
162: elementType4.toString() + "|Font",
163: elementType4.toString() + "|Font Color",
164: elementType4.toString() + "|Background Color",
165: elementType4.toString() + "|Border Color" };
166: //--
167: private static ExpandedElementTypes elementType5 = ExpandedElementTypes.ARTIFACT;
168: private static String menuItems5[] = { "Edit|Lock Edit",
169: "Resize Element to Contents", "Reset Edges",
170: "Hide|Parents|One Level", "Hide|Parents|All Levels",
171: "Hide|Children|One Level", "Hide|Children|All Levels",
172: "Show|Parents|One Level", "Show|Parents|All Levels",
173: "Show|Children|One Level", "Show|Children|All Levels",
174: "Generate Dependency Diagram",
175: elementType5.toString() + "|Font",
176: elementType5.toString() + "|Font Color",
177: elementType5.toString() + "|Background Color",
178: elementType5.toString() + "|Border Color" };
179: //--
180: private static ExpandedElementTypes elementType6 = ExpandedElementTypes.TEMPLATE_CLASS;
181: private static String menuItems6[] = { "Insert Attribute",
182: "Delete Attribute", "Edit|Lock Edit",
183: "Compartment|Customize...", "Resize Element to Contents",
184: "Transform|To Actor", "Transform|To Class",
185: "Transform|To Interface", "Transform|To DataType",
186: "Transform|To Enumeration", "Reset Edges",
187: "Hide|Parents|One Level", "Hide|Parents|All Levels",
188: "Hide|Children|One Level", "Hide|Children|All Levels",
189: "Show|Parents|One Level", "Show|Parents|All Levels",
190: "Show|Children|One Level", "Show|Children|All Levels",
191: "Redefine Operations", "Generate Dependency Diagram",
192: elementType6.toString() + "|Font",
193: elementType6.toString() + "|Font Color",
194: elementType6.toString() + "|Background Color",
195: elementType6.toString() + "|Border Color" };
196: //--
197: private static ExpandedElementTypes elementType7 = ExpandedElementTypes.DERIVATION_CLASSIFIER;
198: private static String menuItems7[] = { "Edit|Lock Edit",
199: "Resize Element to Contents", "Reset Edges",
200: "Hide|Parents|One Level", "Hide|Parents|All Levels",
201: "Hide|Children|One Level", "Hide|Children|All Levels",
202: "Show|Parents|One Level", "Show|Parents|All Levels",
203: "Show|Children|One Level", "Show|Children|All Levels",
204: "Generate Dependency Diagram",
205: elementType7.toString() + "|Font",
206: elementType7.toString() + "|Font Color",
207: elementType7.toString() + "|Background Color",
208: elementType7.toString() + "|Border Color" };
209: //--
210: private static ExpandedElementTypes elementType8 = ExpandedElementTypes.DESIGN_PATTERN;
211: private static String menuItems8[] = { "Edit|Lock Edit",
212: "Resize Element to Contents", "Reset Edges",
213: "Hide|Parents|One Level", "Hide|Parents|All Levels",
214: "Hide|Children|One Level", "Hide|Children|All Levels",
215: "Show|Parents|One Level", "Show|Parents|All Levels",
216: "Show|Children|One Level", "Show|Children|All Levels",
217: "Generate Dependency Diagram",
218: elementType8.toString() + "|Font",
219: elementType8.toString() + "|Font Color",
220: elementType8.toString() + "|Background Color",
221: elementType8.toString() + "|Border Color",
222: "Promote Design Pattern..." };
223: //--
224: private static ExpandedElementTypes elementType9 = ExpandedElementTypes.ROLE;
225: private static String menuItems9[] = {
226: "Edit|Lock Edit",
227: "Compartment|Customize...",
228: "Resize Element to Contents",
229: "Reset Edges",
230: "Hide|Parents|One Level",
231: "Hide|Parents|All Levels",
232: "Hide|Children|One Level",
233: "Hide|Children|All Levels",
234: "Show|As Icon",
235: "Show|Parents|One Level",
236: "Show|Parents|All Levels",
237: "Show|Children|One Level",
238: "Show|Children|All Levels",
239: "Generate Dependency Diagram",
240: LibProperties.getCurrentToolName(elementType9) + "|Font",
241: LibProperties.getCurrentToolName(elementType9)
242: + "|Font Color",
243: LibProperties.getCurrentToolName(elementType9)
244: + "|Background Color",
245: LibProperties.getCurrentToolName(elementType9)
246: + "|Border Color" };
247: //--
248: private static ExpandedElementTypes elementType10 = ExpandedElementTypes.CLASS_ROLE;
249: private static String menuItems10[] = {
250: "Edit|Lock Edit",
251: "Compartment|Customize...",
252: "Resize Element to Contents",
253: "Reset Edges",
254: "Hide|Parents|One Level",
255: "Hide|Parents|All Levels",
256: "Hide|Children|One Level",
257: "Hide|Children|All Levels",
258: "Show|As Icon",
259: "Show|Parents|One Level",
260: "Show|Parents|All Levels",
261: "Show|Children|One Level",
262: "Show|Children|All Levels",
263: "Generate Dependency Diagram",
264: LibProperties.getCurrentToolName(elementType10) + "|Font",
265: LibProperties.getCurrentToolName(elementType10)
266: + "|Font Color",
267: LibProperties.getCurrentToolName(elementType10)
268: + "|Background Color",
269: LibProperties.getCurrentToolName(elementType10)
270: + "|Border Color" };
271: //--
272: private static ExpandedElementTypes elementType11 = ExpandedElementTypes.ACTOR_ROLE;
273: private static String menuItems11[] = {
274: "Edit|Lock Edit",
275: "Resize Element to Contents",
276: "Reset Edges",
277: "Hide|Parents|One Level",
278: "Hide|Parents|All Levels",
279: "Hide|Children|One Level",
280: "Hide|Children|All Levels",
281: "Show|Parents|One Level",
282: "Show|Parents|All Levels",
283: "Show|Children|One Level",
284: "Show|Children|All Levels",
285: "Generate Dependency Diagram",
286: LibProperties.getCurrentToolName(elementType11) + "|Font",
287: LibProperties.getCurrentToolName(elementType11)
288: + "|Font Color",
289: LibProperties.getCurrentToolName(elementType11)
290: + "|Background Color",
291: LibProperties.getCurrentToolName(elementType11)
292: + "|Border Color" };
293: //--
294: private static ExpandedElementTypes elementType12 = ExpandedElementTypes.INTERFACE_ROLE;
295: private static String menuItems12[] = {
296: "Edit|Lock Edit",
297: "Compartment|Customize...",
298: "Resize Element to Contents",
299: "Reset Edges",
300: "Hide|Parents|One Level",
301: "Hide|Parents|All Levels",
302: "Hide|Children|One Level",
303: "Hide|Children|All Levels",
304: "Show|As Icon",
305: "Show|Parents|One Level",
306: "Show|Parents|All Levels",
307: "Show|Children|One Level",
308: "Show|Children|All Levels",
309: "Generate Dependency Diagram",
310: LibProperties.getCurrentToolName(elementType12) + "|Font",
311: LibProperties.getCurrentToolName(elementType12)
312: + "|Font Color",
313: LibProperties.getCurrentToolName(elementType12)
314: + "|Background Color",
315: LibProperties.getCurrentToolName(elementType12)
316: + "|Border Color" };
317: //--
318: private static ExpandedElementTypes elementType13 = ExpandedElementTypes.USE_CASE_ROLE;
319: private static String menuItems13[] = {
320: "Edit|Lock Edit",
321: "Resize Element to Contents",
322: "Insert Extension Point",
323: "Reset Edges",
324: "Hide|Parents|One Level",
325: "Hide|Parents|All Levels",
326: "Hide|Children|One Level",
327: "Hide|Children|All Levels",
328: "Show|Parents|One Level",
329: "Show|Parents|All Levels",
330: "Show|Children|One Level",
331: "Show|Children|All Levels",
332: "Generate Dependency Diagram",
333: LibProperties.getCurrentToolName(elementType13) + "|Font",
334: LibProperties.getCurrentToolName(elementType13)
335: + "|Font Color",
336: LibProperties.getCurrentToolName(elementType13)
337: + "|Background Color",
338: LibProperties.getCurrentToolName(elementType13)
339: + "|Border Color" };
340: //--
341: private static ExpandedElementTypes elementType14 = ExpandedElementTypes.COMMENT;
342: private static String menuItems14[] = { "Compartment|Font",
343: "Compartment|Font Color", "Edit|Lock Edit",
344: "Resize Element to Contents", "Reset Edges",
345: elementType14.toString() + "|Font",
346: elementType14.toString() + "|Font Color",
347: elementType14.toString() + "|Background Color",
348: elementType14.toString() + "|Border Color" };
349: //--
350: private static ExpandedElementTypes elementType14_2 = ExpandedElementTypes.LINK_COMMENT;
351: private static String menuItems14_2[] = { "Compartment|Font",
352: "Compartment|Font Color", "Edit|Lock Edit",
353: "Resize Element to Contents", "Reset Edges",
354: elementType14_2.toString() + "|Font",
355: elementType14_2.toString() + "|Font Color",
356: elementType14_2.toString() + "|Background Color",
357: elementType14_2.toString() + "|Border Color" };
358: //--
359: private static LinkTypes elementType15 = LinkTypes.GENERALIZATION;
360: private static ExpandedElementTypes[] elements15 = {
361: ExpandedElementTypes.CLASS, ExpandedElementTypes.CLASS };
362: private static String menuItems15[] = { "Labels|Name",
363: "Labels|Reset Labels", "Find|Source Element",
364: "Find|Target Element",
365: elementType15.toString() + "|Border Color" };
366: //--
367: private static LinkTypes elementType16 = LinkTypes.IMPLEMENTATION;
368: private static ExpandedElementTypes[] elements16 = {
369: ExpandedElementTypes.CLASS, ExpandedElementTypes.INTERFACE };
370: private static String menuItems16[] = { "Labels|Name",
371: "Labels|Reset Labels", "Find|Source Element",
372: "Find|Target Element",
373: elementType16.toString() + "|Border Color" };
374: //common
375: private static String commonMenuItems[] = { "Edit|Copy",
376: "Edit|Cut", "Edit|Delete", "Edit|Paste", "Edit|Select All",
377: "Edit|Invert Selection",
378: "Edit|Select All Similar Elements",
379: "Synchronize Element with Data", "Select in Model",
380: "Properties", "Associate With...",
381: "Apply Design Pattern..." };
382: //
383: JTreeOperator prTree;
384:
385: /** Need to be defined because of JUnit */
386: public ComponentDiagramElementsContextMenu(String name) {
387: super (name);
388: }
389:
390: public static NbTestSuite suite() {
391: NbTestSuite suite = new NbTestSuite(
392: org.netbeans.test.uml.componentdiagram.ComponentDiagramElementsContextMenu.class);
393: return suite;
394: }
395:
396: private DiagramOperator createDiagram(String project,
397: String workPkg, String diagram) {
398: //
399: org.netbeans.test.umllib.Utils.RetAll rt = org.netbeans.test.umllib.Utils
400: .createDiagram(project, workPkg, diagram,
401: NewDiagramWizardOperator.COMPONENT_DIAGRAM);
402: pto = rt.pto;
403: prTree = new JTreeOperator(pto);
404: lastDiagramNode = rt.lastDiagramNode;
405: return rt.dOp;
406: }
407:
408: public void testCreate1() {
409: testElementContext(elementType1, menuItems1);
410: }
411:
412: public void testCreate2() {
413: testElementContext(elementType2, menuItems2);
414: }
415:
416: public void testCreate3() {
417: testElementContext(elementType3, menuItems3);
418: }
419:
420: public void testCreate4() {
421: testElementContext(elementType4, menuItems4);
422: }
423:
424: public void testCreate5() {
425: testElementContext(elementType5, menuItems5);
426: }
427:
428: public void testCreate6() {
429: testElementContext(elementType6, menuItems6);
430: }
431:
432: public void testCreate7() {
433: testElementContext(elementType7, menuItems7);
434: }
435:
436: public void testCreate8() {
437: testElementContext(elementType8, menuItems8);
438: }
439:
440: public void testCreate9() {
441: testElementContext(elementType9, menuItems9);
442: }
443:
444: public void testCreate10() {
445: testElementContext(elementType10, menuItems10);
446: }
447:
448: public void testCreate11() {
449: testElementContext(elementType11, menuItems11);
450: }
451:
452: public void testCreate12() {
453: testElementContext(elementType12, menuItems12);
454: }
455:
456: public void testCreate13() {
457: testElementContext(elementType13, menuItems13);
458: }
459:
460: public void testCreate14() {
461: testElementContext(elementType14, menuItems14);
462: }
463:
464: public void testCreate14_2() {
465: testElementContext(elementType14_2, menuItems14_2);
466: }
467:
468: public void testCreate15() {
469: testLinkContext(elementType15, elements15, menuItems15);
470: }
471:
472: public void testCreate16() {
473: testLinkContext(elementType16, elements16, menuItems16);
474: }
475:
476: public void setUp() {
477: System.out.println("######## " + getName() + " #######");
478: pto = ProjectsTabOperator.invoke();
479: if (!codeSync) {
480: org.netbeans.test.uml.componentdiagram.utils.Utils
481: .commonComponentDiagramSetup(workdir, prName);
482: //
483: codeSync = true;
484: }
485: }
486:
487: public void tearDown() {
488: org.netbeans.test.umllib.util.Utils
489: .makeScreenShot(lastTestCase);
490: //popup protection
491: MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE);
492: new EventTool().waitNoEvent(1000);
493: //
494: closeAllModal();
495: org.netbeans.test.umllib.util.Utils.saveAll();
496: if (lastDiagramNode != null) {
497: lastDiagramNode.collapse();
498: new Node(lastDiagramNode.tree(), lastDiagramNode
499: .getParentPath()).collapse();
500: }
501: try {
502: DiagramOperator d = new DiagramOperator("cpD");
503: d.closeAllDocuments();
504: d.waitClosed();
505: new EventTool().waitNoEvent(1000);
506: } catch (Exception ex) {
507: }
508: ;
509: closeAllModal();
510: //save
511: org.netbeans.test.umllib.util.Utils.tearDown();
512: }
513:
514: private void testElementContext(ExpandedElementTypes elementType,
515: String[] customMenuItems) {
516: lastTestCase = getCurrentTestNamesWithCheck()[1];
517: String elementName = LibProperties
518: .getCurrentDefaultName(elementType);
519: String element = LibProperties.getProperties()
520: .getCurrentToolName(elementType);
521: //
522: String workPkg = workPkg0 + counter;
523: String diagramName = activityDiagramName0 + counter;
524: counter++;
525: //
526: DiagramOperator d = createDiagram(project, workPkg, diagramName);
527: //
528: int numChild = lastDiagramNode.getChildren().length;
529: //
530: UMLPaletteOperator pl = new UMLPaletteOperator();
531: pl.waitComponentShowing(true);
532: pl.waitComponentVisible(true);
533: //
534: try {
535: pl.selectTool(element);
536: } catch (NotFoundException ex) {
537: fail("BLOCKING: Can't find '" + element + "' in paletter");
538: }
539: //
540: DrawingAreaOperator drAr = d.getDrawingArea();
541: java.awt.Point a = drAr.getFreePoint();
542: drAr.clickMouse(a.x, a.y, 1);
543: drAr.pushKey(KeyEvent.VK_ESCAPE);
544: pl.waitSelection(element, false);
545: new EventTool().waitNoEvent(500);
546: //
547: try {
548: Thread.sleep(500);
549: } catch (Exception ex) {
550: }
551: a = drAr.getFreePoint(100);
552: drAr.clickMouse(a.x, a.y, 1, InputEvent.BUTTON3_MASK);
553: drAr.pushKey(KeyEvent.VK_ESCAPE);
554: //
555: DiagramElementOperator dEl = null;
556: try {
557: dEl = new DiagramElementOperator(d, elementName,
558: elementType, 0);
559: } catch (Exception ex) {
560: try {
561: fail(element
562: + " wasn't added to diagram, but object with type:"
563: + new DiagramElementOperator(d, elementName)
564: .getType()
565: + ": and element type :"
566: + new DiagramElementOperator(d, elementName)
567: .getElementType()
568: + ": was added whyle type should be :"
569: + elementType + ": was added");
570: } catch (Exception ex2) {
571:
572: }
573: fail(element + " wasn't added to diagram.");
574: }
575: dEl.select();
576: //call popup
577: drAr.clickMouse(dEl.getCenterPoint().x, dEl.getCenterPoint().y,
578: 1, InputEvent.BUTTON3_MASK);
579: verify(customMenuItems);
580: }
581:
582: private void testLinkContext(LinkTypes elementType,
583: ExpandedElementTypes[] elements, String[] customMenuItems) {
584: lastTestCase = getCurrentTestNamesWithCheck()[1];
585: String elementName = LibProperties
586: .getCurrentDefaultName(elementType);
587: String element = LibProperties.getCurrentToolName(elementType);
588: //
589: String workPkg = workPkg0 + counter;
590: String diagramName = activityDiagramName0 + counter;
591: counter++;
592: String localElName1 = "El1";
593: String localElName2 = "El2";
594: //
595: DiagramOperator d = createDiagram(project, workPkg, diagramName);
596: //
597: UMLPaletteOperator pl = new UMLPaletteOperator();
598: DrawingAreaOperator drAr = d.getDrawingArea();
599: //
600: java.awt.Point a = drAr.getFreePoint();
601: DiagramElementOperator dE1 = null, dE2 = null;
602: dE1 = d
603: .putElementOnDiagram(localElName1, elements[0], a.x,
604: a.y);
605: a = drAr.getFreePoint(150);
606: dE2 = d
607: .putElementOnDiagram(localElName2, elements[1], a.x,
608: a.y);
609: //
610: try {
611: pl.selectTool(element);
612: } catch (NotFoundException ex) {
613: fail("BLOCKING: Can't find '" + element + "' in paletter");
614: }
615: //
616: drAr.clickMouse(dE1.getCenterPoint().x, dE1.getCenterPoint().y,
617: 1);
618: drAr.clickMouse(dE2.getCenterPoint().x, dE2.getCenterPoint().y,
619: 1);
620: //
621: drAr.pushKey(KeyEvent.VK_ESCAPE);
622: pl.waitSelection(element, false);
623: new EventTool().waitNoEvent(500);
624: //
625: try {
626: Thread.sleep(500);
627: } catch (Exception ex) {
628: }
629: a = drAr.getFreePoint(100);
630: drAr.clickMouse(a.x, a.y, 1, InputEvent.BUTTON3_MASK);
631: drAr.pushKey(KeyEvent.VK_ESCAPE);
632: //"workaround for assembly connector"
633: if (elementType.equals(LinkTypes.ASSEMBLY)) {
634: dE1 = new DiagramElementOperator(d, "",
635: ExpandedElementTypes.PORT, 0);
636: elementType = LinkTypes.USAGE;
637: }
638: //
639: LinkOperator testedlink = null;
640: try {
641: testedlink = LinkOperator.findLink(dE1, dE2,
642: new LinkOperator.LinkByTypeChooser(elementType), 0);
643: } catch (Exception ex) {
644: fail(element + " of type " + elementType
645: + " wasn't added to diagram.");
646: }
647: if (testedlink == null) {
648: LinkOperator altLink = null;
649: try {
650: altLink = LinkOperator.findLink(dE1, dE2,
651: new LinkOperator.LinkByTypeChooser(
652: LinkTypes.ANY), 0);
653: } catch (Exception ex) {
654: fail("any link find failed.");
655: }
656: if (altLink != null)
657: fail("Can't find " + elementType
658: + " link between elements, but the is "
659: + altLink.getType() + " link.");
660: }
661: //
662: if (testedlink == null
663: && elementType.equals(LinkTypes.ACTIVITY_EDGE)) {
664: //fail("Can't find Activity Edge/MultiFlow link between elemens, may be test library limitation, please recheck manually.");
665: } else {
666: assertTrue("Can't find " + elementType
667: + " link between elements", testedlink != null);
668: }
669: //
670: if (elementType.equals(LinkTypes.ACTIVITY_EDGE)) {
671: //tried to get popup for activity edge
672: drAr
673: .clickMouse((dE1.getCenterPoint().x + dE2
674: .getCenterPoint().x) / 2,
675: (dE1.getCenterPoint().y + dE2
676: .getCenterPoint().y) / 2, 1,
677: InputEvent.BUTTON3_MASK);
678: } else {
679: drAr.clickMouse(testedlink.getNearCenterPoint().x,
680: testedlink.getNearCenterPoint().y, 1,
681: InputEvent.BUTTON3_MASK);
682: }
683: verify(customMenuItems);
684: }
685:
686: private void verify(String[] add) {
687: JPopupMenuOperator pop = new JPopupMenuOperator();
688: pop.waitComponentShowing(true);
689: try {
690: Thread.sleep(500);
691: } catch (Exception ex) {
692: }
693: //workaround for 78301
694: pop.pushKey(KeyEvent.VK_LEFT);
695: //
696: try {
697: Thread.sleep(500);
698: } catch (Exception ex) {
699: }
700: //
701: pop = new JPopupMenuOperator();
702: //
703: String fails = "";
704: for (int i = 0; i < commonMenuItems.length; i++) {
705: JMenuItemOperator it = null;
706: try {
707: it = pop.showMenuItem(commonMenuItems[i]);
708: if (it == null) {
709: fails += "Null item " + commonMenuItems[i] + ";\n";
710: org.netbeans.test.umllib.util.Utils
711: .makeScreenShot();
712: }
713: } catch (Exception ex) {
714: fails += "Timeout on selection of "
715: + commonMenuItems[i] + ";\n";
716: org.netbeans.test.umllib.util.Utils.makeScreenShot();
717: }
718: //returns back from inner popup
719: if (commonMenuItems[i].indexOf("|") > -1) {
720: new EventTool().waitNoEvent(500);
721: pop.pushKey(KeyEvent.VK_LEFT);
722: new EventTool().waitNoEvent(500);
723: pop.pushKey(KeyEvent.VK_LEFT);
724: }
725: }
726: if (add != null)
727: for (int i = 0; i < add.length; i++) {
728: JMenuItemOperator it = null;
729: try {
730: it = pop.showMenuItem(add[i]);
731: if (it == null) {
732: fails += "Null item " + add[i] + ";\n";
733: org.netbeans.test.umllib.util.Utils
734: .makeScreenShot(lastTestCase);
735: }
736: } catch (Exception ex) {
737: fails += "Timeout on selection of " + add[i]
738: + ";\n";
739: org.netbeans.test.umllib.util.Utils
740: .makeScreenShot(lastTestCase);
741: }
742: //returns back from inner popup
743: if (add[i].indexOf("|") > -1) {
744: new EventTool().waitNoEvent(500);
745: pop.pushKey(KeyEvent.VK_LEFT);
746: new EventTool().waitNoEvent(500);
747: pop.pushKey(KeyEvent.VK_LEFT);
748: }
749: }
750: //
751: assertTrue("There are some problems with context menu: "
752: + fails, fails.length() == 0);
753:
754: }
755:
756: }
|