0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.test.umllib.tests;
0043:
0044: import java.awt.Component;
0045: import java.awt.Point;
0046: import java.awt.event.KeyEvent;
0047: import java.util.ArrayList;
0048: import org.netbeans.jellytools.MainWindowOperator;
0049: import org.netbeans.jellytools.ProjectsTabOperator;
0050: import org.netbeans.jellytools.nodes.Node;
0051: import org.netbeans.jellytools.properties.Property;
0052: import org.netbeans.jellytools.properties.PropertySheetOperator;
0053: import org.netbeans.jemmy.ComponentChooser;
0054: import org.netbeans.jemmy.EventTool;
0055: import org.netbeans.jemmy.TimeoutExpiredException;
0056: import org.netbeans.jemmy.operators.ContainerOperator;
0057: import org.netbeans.jemmy.operators.JButtonOperator;
0058: import org.netbeans.jemmy.operators.JCheckBoxMenuItemOperator;
0059: import org.netbeans.jemmy.operators.JDialogOperator;
0060: import org.netbeans.jemmy.operators.JMenuItemOperator;
0061: import org.netbeans.jemmy.operators.JPopupMenuOperator;
0062: import org.netbeans.jemmy.operators.JTreeOperator;
0063: import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETEdge;
0064: import org.netbeans.test.umllib.DiagramElementOperator;
0065: import org.netbeans.test.umllib.DiagramOperator;
0066: import org.netbeans.test.umllib.DiagramToolbarOperator;
0067: import org.netbeans.test.umllib.ElementTypes;
0068: import org.netbeans.test.umllib.LinkOperator;
0069: import org.netbeans.test.umllib.LinkTypes;
0070: import org.netbeans.test.umllib.exceptions.NotFoundException;
0071: import org.netbeans.test.umllib.exceptions.UMLCommonException;
0072: import org.netbeans.test.umllib.testcases.UMLTestCase;
0073: import org.netbeans.test.umllib.util.JPopupByPointChooser;
0074: import com.tomsawyer.drawing.geometry.TSConstPoint;
0075:
0076: /**
0077: *
0078: * @author psb
0079: * @spec UML/ComponentDiagram.xml
0080: */
0081: public abstract class DiagramLayout extends UMLTestCase {
0082:
0083: //some system properties
0084: private static String contextPropItemName = "Properties";
0085: private static String umlPropertyWindowTitle = "Project Properties";
0086: private static String umlSourcePackagesLabel = "Source Packages";
0087: private static String umlSourcePackagesColumn = "Folder Label";
0088: private static String umlSourceUsageColumn = "Model?";
0089: private static String mainTreeTabName = "Projects";
0090: public static String diagramType = null;//NewDiagramWizardOperator.ACTIVITY_DIAGRAM;
0091: public static String childClassName = null;
0092: //common test properties
0093: public static String prName = null;// "ActivityDiagramProjectADC";
0094: public static String project = null;//prName+"|Model";
0095: private static String sourceProject = "source";
0096: private static boolean codeSync = false;
0097: private ProjectsTabOperator pto = null;
0098: private Node lastDiagramNode = null;
0099: private String lastTestCase = null;
0100: private JTreeOperator prTree = null;
0101: private static String workdir = System.getProperty("xtest.workdir");
0102: private static long elCount = 0;
0103:
0104: private static ElementTypes centerElement = null;
0105: private static ElementTypes outerElement = null;
0106: private static LinkTypes link = null;
0107:
0108: private boolean fromouter;
0109:
0110: public static final int NOMENUITEM = 1;
0111:
0112: /** */
0113: public DiagramLayout(String name, String type, String prNm,
0114: String childClName, ElementTypes center,
0115: ElementTypes outer, LinkTypes lnk, boolean fromouter) {
0116: super (name);
0117: diagramType = type;
0118: prName = prNm;
0119: project = prName + "|Model";
0120: childClassName = childClName;
0121: centerElement = center;
0122: outerElement = outer;
0123: link = lnk;
0124: this .fromouter = fromouter;
0125: }
0126:
0127: public void setUp() {
0128: System.out.println("######## " + getName() + " #######");
0129: pto = ProjectsTabOperator.invoke();
0130: if (!codeSync) {
0131: if (prName == null)
0132: throw new UMLCommonException("Project is null");
0133: org.netbeans.test.umllib.tests.utils.Utils
0134: .commonTestsSetup(workdir, prName, "Yes");
0135: //
0136: codeSync = true;
0137: }
0138: }
0139:
0140: public void testHierarchicalLayoutViaContext() {
0141: lastTestCase = getCurrentTestMethodName();
0142: elCount++;
0143: String diagramName = "testD" + elCount;
0144: String workPkg = "pkg" + elCount;
0145: //
0146: createContent();
0147: //
0148: DiagramOperator dgr = new DiagramOperator(diagramName);
0149: //
0150: JMenuItemOperator mi = null;
0151: try {
0152: mi = dgr.getDrawingArea().getPopup().showMenuItem(
0153: "Layout|Hierarchical");
0154: } catch (TimeoutExpiredException ex) {
0155: failInPlace(NOMENUITEM, ex);
0156: }
0157: if (mi == null)
0158: failInPlace(NOMENUITEM, new NotFoundException(
0159: "Can't find Layout|Hierarchical menu item"));
0160: mi.pushNoBlock();
0161: verifyHierarchical(diagramName);
0162: }
0163:
0164: public void testHierarchicalLayoutViaToolbar() {
0165: lastTestCase = getCurrentTestMethodName();
0166: elCount++;
0167: String diagramName = "testD" + elCount;
0168: String workPkg = "pkg" + elCount;
0169: //
0170: createContent();
0171: //
0172: DiagramOperator dgr = new DiagramOperator(diagramName);
0173: //
0174: dgr.toolbar().selectToolNoBlock(
0175: DiagramToolbarOperator.HIERARCHICAL_LAYOUT_TOOL);
0176: verifyHierarchical(diagramName);
0177: }
0178:
0179: public void testHierarchicalLayoutViaShortcut() {
0180: lastTestCase = getCurrentTestMethodName();
0181: elCount++;
0182: String diagramName = "testD" + elCount;
0183: String workPkg = "pkg" + elCount;
0184: //
0185: createContent();
0186: //
0187: DiagramOperator dgr = new DiagramOperator(diagramName);
0188: //
0189: dgr.pushKey(KeyEvent.VK_K, KeyEvent.CTRL_MASK
0190: | KeyEvent.SHIFT_MASK);
0191: verifyHierarchical(diagramName);
0192: }
0193:
0194: public void testOrthogonalLayoutViaContext() {
0195: lastTestCase = getCurrentTestMethodName();
0196: elCount++;
0197: String diagramName = "testD" + elCount;
0198: String workPkg = "pkg" + elCount;
0199: //
0200: createContent();
0201: //
0202: DiagramOperator dgr = new DiagramOperator(diagramName);
0203: //
0204: JMenuItemOperator mi = null;
0205: try {
0206: mi = dgr.getDrawingArea().getPopup().showMenuItem(
0207: "Layout|Orthogonal");
0208: } catch (TimeoutExpiredException ex) {
0209: failInPlace(NOMENUITEM, ex);
0210: }
0211: if (mi == null)
0212: failInPlace(NOMENUITEM, new NotFoundException(
0213: "Can't find Layout|Hierarchical menu item"));
0214: mi.pushNoBlock();
0215: //
0216: verifyOrthogonal(diagramName);
0217: }
0218:
0219: public void testOrthogonalLayoutViaToolbar() {
0220: lastTestCase = getCurrentTestMethodName();
0221: elCount++;
0222: String diagramName = "testD" + elCount;
0223: String workPkg = "pkg" + elCount;
0224: //
0225: createContent();
0226: //
0227: DiagramOperator dgr = new DiagramOperator(diagramName);
0228: //
0229: dgr.toolbar().selectToolNoBlock(
0230: DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL);
0231: //
0232: verifyOrthogonal(diagramName);
0233: }
0234:
0235: public void testOrthogonalLayoutViaShortcut() {
0236: lastTestCase = getCurrentTestMethodName();
0237: elCount++;
0238: String diagramName = "testD" + elCount;
0239: String workPkg = "pkg" + elCount;
0240: //
0241: createContent();
0242: //
0243: DiagramOperator dgr = new DiagramOperator(diagramName);
0244: //
0245: dgr.pushKey(KeyEvent.VK_B, KeyEvent.CTRL_MASK
0246: | KeyEvent.SHIFT_MASK);
0247: //
0248: verifyOrthogonal(diagramName);
0249: }
0250:
0251: public void testSymmetricLayoutViaContext() {
0252: lastTestCase = getCurrentTestMethodName();
0253: elCount++;
0254: String diagramName = "testD" + elCount;
0255: String workPkg = "pkg" + elCount;
0256: //
0257: createContent();
0258: //
0259: DiagramOperator dgr = new DiagramOperator(diagramName);
0260: //
0261: JMenuItemOperator mi = null;
0262: try {
0263: mi = dgr.getDrawingArea().getPopup().showMenuItem(
0264: "Layout|Symmetric");
0265: } catch (TimeoutExpiredException ex) {
0266: failInPlace(NOMENUITEM, ex);
0267: }
0268: if (mi == null)
0269: failInPlace(NOMENUITEM, new NotFoundException(
0270: "Can't find Layout|Hierarchical menu item"));
0271: mi.pushNoBlock();
0272: //
0273: verifySymmetric(diagramName);
0274: }
0275:
0276: public void testSymmetricLayoutViaToolbar() {
0277: lastTestCase = getCurrentTestMethodName();
0278: elCount++;
0279: String diagramName = "testD" + elCount;
0280: String workPkg = "pkg" + elCount;
0281: //
0282: createContent();
0283: //
0284: DiagramOperator dgr = new DiagramOperator(diagramName);
0285: //
0286: dgr.toolbar().selectToolNoBlock(
0287: DiagramToolbarOperator.SYMMETRIC_LAYOUT_TOOL);
0288: //
0289: verifySymmetric(diagramName);
0290: }
0291:
0292: public void testSymmetricLayoutViaShortcut() {
0293: lastTestCase = getCurrentTestMethodName();
0294: elCount++;
0295: String diagramName = "testD" + elCount;
0296: String workPkg = "pkg" + elCount;
0297: //
0298: createContent();
0299: //
0300: DiagramOperator dgr = new DiagramOperator(diagramName);
0301: //
0302: dgr.pushKey(KeyEvent.VK_Y, KeyEvent.CTRL_MASK
0303: | KeyEvent.SHIFT_MASK);
0304: //
0305: verifySymmetric(diagramName);
0306: }
0307:
0308: public void testIncrementalLayoutViaContext() {
0309: lastTestCase = getCurrentTestMethodName();
0310: elCount++;
0311: String diagramName = "testD" + elCount;
0312: String workPkg = "pkg" + elCount;
0313: //
0314: createContent();
0315: //
0316: DiagramOperator dgr = new DiagramOperator(diagramName);
0317: //
0318: JMenuItemOperator mi = null;
0319: try {
0320: mi = dgr.getDrawingArea().getPopup().showMenuItem(
0321: "Layout|Orthogonal");
0322: } catch (TimeoutExpiredException ex) {
0323: failInPlace(NOMENUITEM, ex);
0324: }
0325: if (mi == null)
0326: failInPlace(NOMENUITEM, new NotFoundException(
0327: "Can't find Layout|Hierarchical menu item"));
0328: mi.pushNoBlock();
0329: JDialogOperator lt = new JDialogOperator("Layout");
0330: new JButtonOperator(lt, "Yes").push();
0331: lt.waitClosed();
0332: try {
0333: Thread.sleep(1000);
0334: } catch (Exception ex) {
0335: }
0336: addContent(diagramName);
0337: mi = null;
0338: try {
0339: mi = dgr.getDrawingArea().getPopup().showMenuItem(
0340: "Layout|Incremental");
0341: } catch (TimeoutExpiredException ex) {
0342: failInPlace(NOMENUITEM, ex);
0343: }
0344: if (mi == null)
0345: failInPlace(NOMENUITEM, new NotFoundException(
0346: "Can't find Layout|Hierarchical menu item"));
0347: mi.pushNoBlock();
0348: //
0349: verifyIncremental(diagramName);
0350: }
0351:
0352: public void testIncrementalLayoutViaToolbar() {
0353: lastTestCase = getCurrentTestMethodName();
0354: elCount++;
0355: String diagramName = "testD" + elCount;
0356: String workPkg = "pkg" + elCount;
0357: //
0358: createContent();
0359: //
0360: DiagramOperator dgr = new DiagramOperator(diagramName);
0361: //
0362: dgr.toolbar().selectToolNoBlock(
0363: DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL);
0364: JDialogOperator lt = new JDialogOperator("Layout");
0365: new JButtonOperator(lt, "Yes").push();
0366: lt.waitClosed();
0367: try {
0368: Thread.sleep(1000);
0369: } catch (Exception ex) {
0370: }
0371: addContent(diagramName);
0372: //
0373: dgr.toolbar().selectToolNoBlock(
0374: DiagramToolbarOperator.INCREMENTAL_LAYOUT_TOOL);
0375: verifyIncremental(diagramName);
0376: }
0377:
0378: public void testIncrementalLayoutViaShortcut() {
0379: lastTestCase = getCurrentTestMethodName();
0380: elCount++;
0381: String diagramName = "testD" + elCount;
0382: String workPkg = "pkg" + elCount;
0383: //
0384: createContent();
0385: //
0386: DiagramOperator dgr = new DiagramOperator(diagramName);
0387: //
0388: dgr.pushKey(KeyEvent.VK_B, KeyEvent.CTRL_MASK
0389: | KeyEvent.SHIFT_MASK);
0390: JDialogOperator lt = new JDialogOperator("Layout");
0391: new JButtonOperator(lt, "Yes").push();
0392: lt.waitClosed();
0393: try {
0394: Thread.sleep(1000);
0395: } catch (Exception ex) {
0396: }
0397: addContent(diagramName);
0398: dgr.pushKey(KeyEvent.VK_I, KeyEvent.CTRL_MASK
0399: | KeyEvent.SHIFT_MASK);
0400: //
0401: verifyIncremental(diagramName);
0402: }
0403:
0404: private void createContent() {
0405: String diagramName = "testD" + elCount;
0406: String workPkg = "pkg" + elCount;
0407: //
0408: org.netbeans.test.umllib.Utils.RetAll rt = org.netbeans.test.umllib.Utils
0409: .createDiagram(project, workPkg, diagramName,
0410: diagramType);
0411: lastDiagramNode = rt.lastDiagramNode;
0412: Point a = rt.dOp.getDrawingArea().getFreePoint(120);
0413: DiagramElementOperator cntr = rt.dOp.putElementOnDiagram(
0414: "CENTER", centerElement, a.x, a.y);
0415: a = rt.dOp.getDrawingArea().getFreePoint(30);
0416: DiagramElementOperator o1 = rt.dOp.putElementOnDiagram("OUT1",
0417: outerElement, a.x, a.y);
0418: a = rt.dOp.getDrawingArea().getFreePoint(30);
0419: DiagramElementOperator o2 = rt.dOp.putElementOnDiagram("OUT2",
0420: outerElement, a.x, a.y);
0421: a = rt.dOp.getDrawingArea().getFreePoint(30);
0422: DiagramElementOperator o3 = rt.dOp.putElementOnDiagram("OUT3",
0423: outerElement, a.x, a.y);
0424: //
0425: if (fromouter) {
0426: rt.dOp.createLinkOnDiagram(link, o1, cntr);
0427: rt.dOp.createLinkOnDiagram(link, o2, cntr);
0428: rt.dOp.createLinkOnDiagram(link, o3, cntr);
0429: } else {
0430: rt.dOp.createLinkOnDiagram(link, cntr, o1);
0431: rt.dOp.createLinkOnDiagram(link, cntr, o2);
0432: rt.dOp.createLinkOnDiagram(link, cntr, o3);
0433: }
0434: }
0435:
0436: private void addContent(String diagramName) {
0437: //
0438: DiagramOperator dOp = new DiagramOperator(diagramName);
0439: Point a = a = dOp.getDrawingArea().getFreePoint(30);
0440: DiagramElementOperator cntr = new DiagramElementOperator(dOp,
0441: "CENTER", centerElement);
0442: DiagramElementOperator o4 = dOp.putElementOnDiagram("OUT4",
0443: outerElement, a.x, a.y);
0444: //
0445: if (fromouter) {
0446: dOp.createLinkOnDiagram(link, o4, cntr);
0447: } else {
0448: dOp.createLinkOnDiagram(link, cntr, o4);
0449: }
0450: }
0451:
0452: private void verifyHierarchical(String diagramName) {
0453: //
0454: JDialogOperator lt = new JDialogOperator("Layout");
0455: new JButtonOperator(lt, "Yes").push();
0456: lt.waitClosed();
0457: try {
0458: Thread.sleep(1000);
0459: } catch (Exception ex) {
0460: }
0461: DiagramOperator dgr = new DiagramOperator(diagramName);
0462: DiagramElementOperator cntr = new DiagramElementOperator(dgr,
0463: "CENTER", centerElement);
0464: DiagramElementOperator o1 = new DiagramElementOperator(dgr,
0465: "OUT1", outerElement);
0466: DiagramElementOperator o2 = new DiagramElementOperator(dgr,
0467: "OUT2", outerElement);
0468: DiagramElementOperator o3 = new DiagramElementOperator(dgr,
0469: "OUT3", outerElement);
0470: //
0471: assertTrue(
0472: "All \"outer\" elements should be on the same level, now: "
0473: + o1.getCenterPoint().y + ";"
0474: + o2.getCenterPoint().y + ";"
0475: + o3.getCenterPoint().y,
0476: o1.getCenterPoint().y == o2.getCenterPoint().y
0477: && o3.getCenterPoint().y == o2.getCenterPoint().y);
0478: int maxX = Math.max(Math.max(o1.getCenterPoint().x, o2
0479: .getCenterPoint().x), o3.getCenterPoint().x);
0480: int minX = Math.min(Math.min(o1.getCenterPoint().x, o2
0481: .getCenterPoint().x), o3.getCenterPoint().x);
0482: assertTrue(
0483: "Center element should be between \"outer\" elements on x axe, now: "
0484: + cntr.getCenterPoint().x + " vs "
0485: + o1.getCenterPoint().x + ";"
0486: + o2.getCenterPoint().x + ";"
0487: + o3.getCenterPoint().x, maxX > cntr
0488: .getCenterPoint().x
0489: && minX < cntr.getCenterPoint().x);
0490: if (!fromouter) {
0491: assertTrue(
0492: "Element level do not match relation after layout",
0493: o1.getCenterPoint().y < cntr.getCenterPoint().y);
0494: } else {
0495: assertTrue(
0496: "Element level do not match relation after layout",
0497: o1.getCenterPoint().y > cntr.getCenterPoint().y);
0498: }
0499: //verify buttons, properties etc
0500: try {
0501: Thread.sleep(100);
0502: } catch (InterruptedException ex) {
0503: ex.printStackTrace();
0504: }
0505: dgr.getDrawingArea().clickMouse();
0506: try {
0507: Thread.sleep(100);
0508: } catch (InterruptedException ex) {
0509: ex.printStackTrace();
0510: }
0511: dgr.getDrawingArea().clickMouse();
0512: try {
0513: Thread.sleep(100);
0514: } catch (InterruptedException ex) {
0515: ex.printStackTrace();
0516: }
0517: //properties
0518: PropertySheetOperator ps = null;
0519: try {
0520: ps = new PropertySheetOperator(diagramName
0521: + " - Properties");
0522: } catch (Exception ex) {
0523: ps = new PropertySheetOperator();
0524: fail("Property sheet isn't for " + diagramName
0525: + ", but for " + ps.getName());
0526: }
0527: Property pr = new Property(ps, "Layout Style");
0528: assertTrue("Layout style isn't hierarchical in properties",
0529: "hierarchical".equals(pr.getValue()));
0530: //context menu
0531: JMenuItemOperator mi = null;
0532: JPopupMenuOperator popm = dgr.getDrawingArea().getPopup();
0533: try {
0534: mi = popm.showMenuItem("Layout");
0535: } catch (TimeoutExpiredException e) {
0536: //do nothing, null check is below
0537: }
0538: //do not check if there is no item, fail should be in another place of test
0539: if (mi != null) {
0540: mi.pushNoBlock();
0541: try {
0542: Thread.sleep(100);
0543: } catch (InterruptedException ex) {
0544: ex.printStackTrace();
0545: }
0546: //fail(mi.getHeight()/2+":"+mi.getWidth()+":"+mi.getLocationOnScreen());
0547: JPopupMenuOperator pmo = new JPopupMenuOperator(
0548: MainWindowOperator.getDefault(),
0549: new JPopupByPointChooser(mi.getWidth() + 30, mi
0550: .getHeight() / 2, mi.getSource(), 0));
0551: JCheckBoxMenuItemOperator cmi = new JCheckBoxMenuItemOperator(
0552: pmo, "Hierarchical");
0553: assertTrue("Layout|Hierarchical isn't checked", cmi
0554: .isSelected());
0555: }
0556: //toolbar
0557: assertTrue(
0558: 100638,
0559: "Hierarchical on toolbar isn't selected",
0560: dgr
0561: .toolbar()
0562: .getToggleButtonByTooltip(
0563: DiagramToolbarOperator.HIERARCHICAL_LAYOUT_TOOL)
0564: .isSelected());
0565: }
0566:
0567: private void verifyOrthogonal(String diagramName) {
0568: //
0569: JDialogOperator lt = new JDialogOperator("Layout");
0570: new JButtonOperator(lt, "Yes").push();
0571: lt.waitClosed();
0572: try {
0573: Thread.sleep(1000);
0574: } catch (Exception ex) {
0575: }
0576: DiagramOperator dgr = new DiagramOperator(diagramName);
0577: DiagramElementOperator cntr = new DiagramElementOperator(dgr,
0578: "CENTER", centerElement);
0579: DiagramElementOperator o1 = new DiagramElementOperator(dgr,
0580: "OUT1", outerElement);
0581: DiagramElementOperator o2 = new DiagramElementOperator(dgr,
0582: "OUT2", outerElement);
0583: DiagramElementOperator o3 = new DiagramElementOperator(dgr,
0584: "OUT3", outerElement);
0585: //
0586: int maxX = Math.max(Math.max(o1.getCenterPoint().x, o2
0587: .getCenterPoint().x), o3.getCenterPoint().x);
0588: int minX = Math.min(Math.min(o1.getCenterPoint().x, o2
0589: .getCenterPoint().x), o3.getCenterPoint().x);
0590: int maxY = Math.max(Math.max(o1.getCenterPoint().y, o2
0591: .getCenterPoint().y), o3.getCenterPoint().y);
0592: int minY = Math.min(Math.min(o1.getCenterPoint().y, o2
0593: .getCenterPoint().y), o3.getCenterPoint().y);
0594: assertTrue(
0595: "Center element should be between \"outer\" elements on x or y axe, now: "
0596: + cntr.getCenterPoint().x + " vs "
0597: + o1.getCenterPoint().x + ";"
0598: + o2.getCenterPoint().x + ";"
0599: + o3.getCenterPoint().x,
0600: (maxX > cntr.getCenterPoint().x && minX < cntr
0601: .getCenterPoint().x)
0602: || (maxY > cntr.getCenterPoint().y && minY < cntr
0603: .getCenterPoint().y));
0604: //verify links are orthogonal
0605:
0606: LinkOperator lnks[] = null;
0607: if (fromouter)
0608: lnks = new LinkOperator[] { new LinkOperator(o1, cntr),
0609: new LinkOperator(o2, cntr),
0610: new LinkOperator(o3, cntr) };
0611: else
0612: lnks = new LinkOperator[] { new LinkOperator(cntr, o1),
0613: new LinkOperator(cntr, o2),
0614: new LinkOperator(cntr, o3) };
0615: //
0616: for (int i = 0; i < lnks.length; i++) {
0617: ArrayList<TSConstPoint> pnts = new ArrayList<TSConstPoint>();
0618: pnts.add(((ETEdge) (lnks[i].getSource()))
0619: .getSourceClippingPoint());
0620: for (int j = 0; j < lnks[i].getBends().size(); j++) {
0621: pnts.add((TSConstPoint) (lnks[i].getBends().get(j)));
0622: }
0623: pnts.add(((ETEdge) (lnks[i].getSource()))
0624: .getTargetClippingPoint());
0625: //
0626: for (int j = 1; j < pnts.size(); j++) {
0627: assertTrue(
0628: "Pairs of bends/target/source points on link do not on same axe",
0629: pnts.get(j).getX() == pnts.get(j - 1).getX()
0630: || pnts.get(j).getY() == pnts
0631: .get(j - 1).getY());
0632: }
0633: }
0634: //
0635: int top = 0;
0636: int left = 0;
0637: int right = 0;
0638: int bottom = 0;
0639: //
0640: if (o1.getCenterPoint().x < (cntr.getCenterPoint().x
0641: - cntr.getBoundingRect().width / 2 - o1
0642: .getBoundingRect().width / 2)) {
0643: //it's at left side
0644: left++;
0645: assertTrue(
0646: "OUT1 shifts greatly from horizontal axe",
0647: o1.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0648: && o1.getCenterPoint().y < (cntr
0649: .getCenterPoint().y + 10));
0650: } else if (o1.getCenterPoint().x > (cntr.getCenterPoint().x
0651: + cntr.getBoundingRect().width / 2 + o1
0652: .getBoundingRect().width / 2)) {
0653: //right side
0654: right++;
0655: assertTrue(
0656: "OUT1 shifts greatly from horizontal axe",
0657: o1.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0658: && o1.getCenterPoint().y < (cntr
0659: .getCenterPoint().y + 10));
0660: } else if (o1.getCenterPoint().y < (cntr.getCenterPoint().y
0661: - cntr.getBoundingRect().height / 2 - o1
0662: .getBoundingRect().height / 2)) {
0663: //top
0664: top++;
0665: assertTrue(
0666: "OUT1 shifts greatly from vertical axe",
0667: o1.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0668: && o1.getCenterPoint().x < (cntr
0669: .getCenterPoint().x + 10));
0670: } else if (o1.getCenterPoint().y > (cntr.getCenterPoint().y
0671: + cntr.getBoundingRect().height / 2 + o1
0672: .getBoundingRect().height / 2)) {
0673: bottom++;
0674: assertTrue(
0675: "OUT1 shifts greatly from vertical axe",
0676: o1.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0677: && o1.getCenterPoint().x < (cntr
0678: .getCenterPoint().x + 10));
0679: }
0680: //--
0681: if (o2.getCenterPoint().x < (cntr.getCenterPoint().x
0682: - cntr.getBoundingRect().width / 2 - o2
0683: .getBoundingRect().width / 2)) {
0684: //it's at left side
0685: left++;
0686: assertTrue(
0687: "OUT2 shifts greatly from horizontal axe",
0688: o2.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0689: && o2.getCenterPoint().y < (cntr
0690: .getCenterPoint().y + 10));
0691: } else if (o2.getCenterPoint().x > (cntr.getCenterPoint().x
0692: + cntr.getBoundingRect().width / 2 + o2
0693: .getBoundingRect().width / 2)) {
0694: //right side
0695: right++;
0696: assertTrue(
0697: "OUT2 shifts greatly from horizontal axe",
0698: o2.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0699: && o2.getCenterPoint().y < (cntr
0700: .getCenterPoint().y + 10));
0701: } else if (o2.getCenterPoint().y < (cntr.getCenterPoint().y
0702: - cntr.getBoundingRect().height / 2 - o2
0703: .getBoundingRect().height / 2)) {
0704: //top
0705: top++;
0706: assertTrue(
0707: "OUT2 shifts greatly from vertical axe",
0708: o2.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0709: && o2.getCenterPoint().x < (cntr
0710: .getCenterPoint().x + 10));
0711: } else if (o2.getCenterPoint().y > (cntr.getCenterPoint().y
0712: + cntr.getBoundingRect().height / 2 + o2
0713: .getBoundingRect().height / 2)) {
0714: bottom++;
0715: assertTrue(
0716: "OUT2 shifts greatly from vertical axe",
0717: o2.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0718: && o2.getCenterPoint().x < (cntr
0719: .getCenterPoint().x + 10));
0720: }
0721: //--
0722: if (o3.getCenterPoint().x < (cntr.getCenterPoint().x
0723: - cntr.getBoundingRect().width / 2 - o3
0724: .getBoundingRect().width / 2)) {
0725: //it's at left side
0726: left++;
0727: assertTrue(
0728: "OUT3 shifts greatly from horizontal axe",
0729: o3.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0730: && o3.getCenterPoint().y < (cntr
0731: .getCenterPoint().y + 10));
0732: } else if (o3.getCenterPoint().x > (cntr.getCenterPoint().x
0733: + cntr.getBoundingRect().width / 2 + o3
0734: .getBoundingRect().width / 2)) {
0735: //right side
0736: right++;
0737: assertTrue(
0738: "OUT3 shifts greatly from horizontal axe",
0739: o3.getCenterPoint().y > (cntr.getCenterPoint().y - 10)
0740: && o3.getCenterPoint().y < (cntr
0741: .getCenterPoint().y + 10));
0742: } else if (o3.getCenterPoint().y < (cntr.getCenterPoint().y
0743: - cntr.getBoundingRect().height / 2 - o3
0744: .getBoundingRect().height / 2)) {
0745: //top
0746: top++;
0747: assertTrue(
0748: "OUT3 shifts greatly from vertical axe",
0749: o3.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0750: && o3.getCenterPoint().x < (cntr
0751: .getCenterPoint().x + 10));
0752: } else if (o3.getCenterPoint().y > (cntr.getCenterPoint().y
0753: + cntr.getBoundingRect().height / 2 + o3
0754: .getBoundingRect().height / 2)) {
0755: bottom++;
0756: assertTrue(
0757: "OUT3 shifts greatly from vertical axe",
0758: o3.getCenterPoint().x > (cntr.getCenterPoint().x - 10)
0759: && o3.getCenterPoint().x < (cntr
0760: .getCenterPoint().x + 10));
0761: }
0762: assertTrue("Diagram do not match 3 sided scenaruio.", left < 2
0763: && right < 2 && top < 2 && bottom < 2
0764: && (left + top + bottom + right) == 3);
0765: //verify buttons, properties etc
0766: try {
0767: Thread.sleep(100);
0768: } catch (InterruptedException ex) {
0769: ex.printStackTrace();
0770: }
0771: dgr.getDrawingArea().clickMouse();
0772: try {
0773: Thread.sleep(100);
0774: } catch (InterruptedException ex) {
0775: ex.printStackTrace();
0776: }
0777: //properties
0778: PropertySheetOperator ps = new PropertySheetOperator();
0779: assertTrue("Property sheet isn't for " + diagramName
0780: + ", but for " + ps.getName(),
0781: (diagramName + " - Properties").equals(ps.getName()));
0782: Property pr = new Property(ps, "Layout Style");
0783: assertTrue("Layout style isn't orthogonal in properties",
0784: "orthogonal".equals(pr.getValue()));
0785: //context menu
0786: JMenuItemOperator mi = null;
0787: JPopupMenuOperator popm = dgr.getDrawingArea().getPopup();
0788: try {
0789: mi = popm.showMenuItem("Layout");
0790: } catch (TimeoutExpiredException e) {
0791: //do nothing, null check is below
0792: }
0793: //do not check if there is no item, fail should be in another place of test
0794: if (mi != null) {
0795: mi.pushNoBlock();
0796: try {
0797: Thread.sleep(100);
0798: } catch (InterruptedException ex) {
0799: ex.printStackTrace();
0800: }
0801: JPopupMenuOperator pmo = new JPopupMenuOperator(
0802: MainWindowOperator.getDefault(),
0803: new JPopupByPointChooser(mi.getWidth() + 30, mi
0804: .getHeight() / 2, mi.getSource(), 0));
0805: JCheckBoxMenuItemOperator cmi = new JCheckBoxMenuItemOperator(
0806: pmo, "Orthogonal");
0807: assertTrue("Layout|Orthogonal isn't checked", cmi
0808: .isSelected());
0809: }
0810: //toolbar
0811: assertTrue(100638, "Orthogonal on toolbar isn't selected", dgr
0812: .toolbar().getToggleButtonByTooltip(
0813: DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL)
0814: .isSelected());
0815: }
0816:
0817: private void verifySymmetric(String diagramName) {
0818: //
0819: JDialogOperator lt = new JDialogOperator("Layout");
0820: new JButtonOperator(lt, "Yes").push();
0821: lt.waitClosed();
0822: try {
0823: Thread.sleep(1000);
0824: } catch (Exception ex) {
0825: }
0826: DiagramOperator dgr = new DiagramOperator(diagramName);
0827: DiagramElementOperator cntr = new DiagramElementOperator(dgr,
0828: "CENTER", centerElement);
0829: DiagramElementOperator o1 = new DiagramElementOperator(dgr,
0830: "OUT1", outerElement);
0831: DiagramElementOperator o2 = new DiagramElementOperator(dgr,
0832: "OUT2", outerElement);
0833: DiagramElementOperator o3 = new DiagramElementOperator(dgr,
0834: "OUT3", outerElement);
0835: //
0836: Point cp = cntr.getCenterPoint();
0837: Point p1 = o1.getCenterPoint();
0838: Point p2 = o2.getCenterPoint();
0839: Point p3 = o3.getCenterPoint();
0840: //
0841: int maxX = Math.max(Math.max(p1.x, p2.x), p3.x);
0842: int minX = Math.min(Math.min(p1.x, p2.x), p3.x);
0843: int maxY = Math.max(Math.max(p1.y, p2.y), p3.y);
0844: int minY = Math.min(Math.min(p1.y, p2.y), p3.y);
0845: assertTrue(
0846: "Center element should be between \"outer\" elements on x and y axe, now: "
0847: + cp.x + " vs " + p1.x + ";" + p2.x + ";"
0848: + p3.x, maxX > cp.x && minX < cp.x
0849: && minY < cp.y && maxY > cp.y);
0850: //find angles 1-2, 1-3
0851: double dx1 = p1.x - cp.x;
0852: double dy1 = p1.y - cp.y;
0853: double len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
0854: dx1 = dx1 / len1;
0855: dy1 = dy1 / len1;
0856:
0857: double dx2 = p2.x - cp.x;
0858: double dy2 = p2.y - cp.y;
0859: double len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
0860: dx2 = dx2 / len2;
0861: dy2 = dy2 / len2;
0862:
0863: double dx3 = p3.x - cp.x;
0864: double dy3 = p3.y - cp.y;
0865: double len3 = Math.sqrt(dx3 * dx3 + dy3 * dy3);
0866: dx3 = dx3 / len3;
0867: dy3 = dy3 / len3;
0868:
0869: double cos12 = dx1 * dx2 + dy1 * dy2;
0870: double cos13 = dx1 * dx3 + dy1 * dy3;
0871: double cos23 = dx2 * dx3 + dy2 * dy3;
0872:
0873: double angle12 = Math.acos(cos12) * 180 / Math.PI;
0874: double angle13 = Math.acos(cos13) * 180 / Math.PI;
0875: double angle23 = Math.acos(cos23) * 180 / Math.PI;
0876:
0877: assertTrue("Angles should be about 120 grad: " + angle12 + ":"
0878: + angle13 + ":" + angle23, Math.abs(angle12 - 120) < 12
0879: && Math.abs(angle13 - 120) < 12
0880: && Math.abs(angle23 - 120) < 12);
0881:
0882: //verify buttons, properties etc
0883: try {
0884: Thread.sleep(100);
0885: } catch (InterruptedException ex) {
0886: ex.printStackTrace();
0887: }
0888: dgr.getDrawingArea().clickMouse();
0889: try {
0890: Thread.sleep(100);
0891: } catch (InterruptedException ex) {
0892: ex.printStackTrace();
0893: }
0894: //properties
0895: PropertySheetOperator ps = new PropertySheetOperator();
0896: assertTrue("Property sheet isn't for " + diagramName
0897: + ", but for " + ps.getName(),
0898: (diagramName + " - Properties").equals(ps.getName()));
0899: Property pr = new Property(ps, "Layout Style");
0900: assertTrue("Layout style isn't symmetric in properties",
0901: "symmetric".equals(pr.getValue()));
0902: //context menu
0903: JMenuItemOperator mi = null;
0904: JPopupMenuOperator popm = dgr.getDrawingArea().getPopup();
0905: try {
0906: mi = popm.showMenuItem("Layout");
0907: } catch (TimeoutExpiredException e) {
0908: //do nothing, null check is below
0909: }
0910: //do not check if there is no item, fail should be in another place of test
0911: if (mi != null) {
0912: mi.pushNoBlock();
0913: try {
0914: Thread.sleep(100);
0915: } catch (InterruptedException ex) {
0916: ex.printStackTrace();
0917: }
0918: JPopupMenuOperator pmo = new JPopupMenuOperator(
0919: MainWindowOperator.getDefault(),
0920: new JPopupByPointChooser(mi.getWidth() + 30, mi
0921: .getHeight() / 2, mi.getSource(), 0));
0922: JCheckBoxMenuItemOperator cmi = new JCheckBoxMenuItemOperator(
0923: pmo, "Symmetric");
0924: assertTrue("Layout|Orthogonal isn't checked", cmi
0925: .isSelected());
0926: }
0927: //toolbar
0928: assertTrue(100638, "Orthogonal on toolbar isn't selected", dgr
0929: .toolbar().getToggleButtonByTooltip(
0930: DiagramToolbarOperator.SYMMETRIC_LAYOUT_TOOL)
0931: .isSelected());
0932: }
0933:
0934: private void verifyIncremental(String diagramName) {
0935: //
0936: JDialogOperator lt = new JDialogOperator("Layout");
0937: new JButtonOperator(lt, "Yes").push();
0938: lt.waitClosed();
0939: try {
0940: Thread.sleep(1000);
0941: } catch (Exception ex) {
0942: }
0943: DiagramOperator dgr = new DiagramOperator(diagramName);
0944: DiagramElementOperator cntr = new DiagramElementOperator(dgr,
0945: "CENTER", centerElement);
0946: DiagramElementOperator o1 = new DiagramElementOperator(dgr,
0947: "OUT1", outerElement);
0948: DiagramElementOperator o2 = new DiagramElementOperator(dgr,
0949: "OUT2", outerElement);
0950: DiagramElementOperator o3 = new DiagramElementOperator(dgr,
0951: "OUT3", outerElement);
0952: DiagramElementOperator o4 = new DiagramElementOperator(dgr,
0953: "OUT4", outerElement);
0954: //
0955: int maxX = Math.max(Math.max(Math.max(o1.getCenterPoint().x, o2
0956: .getCenterPoint().x), o3.getCenterPoint().x), o4
0957: .getCenterPoint().x);
0958: int minX = Math.min(Math.min(Math.min(o1.getCenterPoint().x, o2
0959: .getCenterPoint().x), o3.getCenterPoint().x), o4
0960: .getCenterPoint().x);
0961: int maxY = Math.max(Math.max(Math.max(o1.getCenterPoint().y, o2
0962: .getCenterPoint().y), o3.getCenterPoint().y), o4
0963: .getCenterPoint().y);
0964: int minY = Math.min(Math.min(Math.min(o1.getCenterPoint().y, o2
0965: .getCenterPoint().y), o3.getCenterPoint().y), o4
0966: .getCenterPoint().y);
0967: assertTrue(
0968: "Center element should be between \"outer\" elements on x or y axe, now: "
0969: + cntr.getCenterPoint().x + " vs "
0970: + o1.getCenterPoint().x + ";"
0971: + o2.getCenterPoint().x + ";"
0972: + o3.getCenterPoint().x,
0973: (maxX > cntr.getCenterPoint().x && minX < cntr
0974: .getCenterPoint().x)
0975: || (maxY > cntr.getCenterPoint().y && minY < cntr
0976: .getCenterPoint().y));
0977: //verify links are orthogonal
0978: LinkOperator lnks[] = null;
0979: if (fromouter)
0980: lnks = new LinkOperator[] { new LinkOperator(o1, cntr),
0981: new LinkOperator(o2, cntr),
0982: new LinkOperator(o3, cntr),
0983: new LinkOperator(o4, cntr) };
0984: else
0985: lnks = new LinkOperator[] { new LinkOperator(cntr, o1),
0986: new LinkOperator(cntr, o2),
0987: new LinkOperator(cntr, o3),
0988: new LinkOperator(cntr, o4) };
0989: //
0990: for (int i = 0; i < lnks.length; i++) {
0991: ArrayList<TSConstPoint> pnts = new ArrayList<TSConstPoint>();
0992: pnts.add(((ETEdge) (lnks[i].getSource()))
0993: .getSourceClippingPoint());
0994: for (int j = 0; j < lnks[i].getBends().size(); j++) {
0995: pnts.add((TSConstPoint) (lnks[i].getBends().get(j)));
0996: }
0997: pnts.add(((ETEdge) (lnks[i].getSource()))
0998: .getTargetClippingPoint());
0999: //
1000: for (int j = 1; j < pnts.size(); j++) {
1001: assertTrue(
1002: "Pairs of bends/target/source points on link do not on same axe",
1003: pnts.get(j).getX() == pnts.get(j - 1).getX()
1004: || pnts.get(j).getY() == pnts
1005: .get(j - 1).getY());
1006: }
1007: }
1008: //verify buttons, properties etc
1009: try {
1010: Thread.sleep(100);
1011: } catch (InterruptedException ex) {
1012: ex.printStackTrace();
1013: }
1014: dgr.getDrawingArea().clickMouse();
1015: try {
1016: Thread.sleep(100);
1017: } catch (InterruptedException ex) {
1018: ex.printStackTrace();
1019: }
1020: //properties
1021: PropertySheetOperator ps = new PropertySheetOperator();
1022: assertTrue("Property sheet isn't for " + diagramName
1023: + ", but for " + ps.getName(),
1024: (diagramName + " - Properties").equals(ps.getName()));
1025: Property pr = new Property(ps, "Layout Style");
1026: assertTrue("Layout style isn't orthogonal in properties",
1027: "orthogonal".equals(pr.getValue()));
1028: //context menu
1029: JMenuItemOperator mi = null;
1030: JPopupMenuOperator popm = dgr.getDrawingArea().getPopup();
1031: try {
1032: mi = popm.showMenuItem("Layout");
1033: } catch (TimeoutExpiredException e) {
1034: //do nothing, null check is below
1035: }
1036: //do not check if there is no item, fail should be in another place of test
1037: if (mi != null) {
1038: mi.pushNoBlock();
1039: try {
1040: Thread.sleep(100);
1041: } catch (InterruptedException ex) {
1042: ex.printStackTrace();
1043: }
1044: JPopupMenuOperator pmo = new JPopupMenuOperator(
1045: MainWindowOperator.getDefault(),
1046: new JPopupByPointChooser(mi.getWidth() + 30, mi
1047: .getHeight() / 2, mi.getSource(), 0));
1048: JCheckBoxMenuItemOperator cmi = new JCheckBoxMenuItemOperator(
1049: pmo, "Orthogonal");
1050: assertTrue("Layout|Orthogonal isn't checked", cmi
1051: .isSelected());
1052: }
1053: //toolbar
1054: assertTrue(100638, "Orthogonal on toolbar isn't selected", dgr
1055: .toolbar().getToggleButtonByTooltip(
1056: DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL)
1057: .isSelected());
1058: }
1059:
1060: public void tearDown() {
1061: org.netbeans.test.umllib.util.Utils.makeScreenShot(
1062: childClassName, lastTestCase);
1063: //popup protection
1064: MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE);
1065: new EventTool().waitNoEvent(1000);
1066: //
1067: closeAllModal();
1068: if (lastDiagramNode != null) {
1069: lastDiagramNode.collapse();
1070: new Node(lastDiagramNode.tree(), lastDiagramNode
1071: .getParentPath()).collapse();
1072: }
1073: //save all
1074: ContainerOperator tlb = MainWindowOperator.getDefault()
1075: .getToolbar("File");
1076: JButtonOperator sa = MainWindowOperator.getDefault()
1077: .getToolbarButton(tlb, "Save All");
1078: if (sa.isEnabled()) {
1079: sa.push();
1080: sa.waitState(new ChooseEnabledState(false));
1081: try {
1082: Thread.sleep(100);
1083: } catch (Exception ex) {
1084: }
1085: }
1086: //
1087: DiagramOperator d = null;
1088: try {
1089: d = new DiagramOperator("testD");
1090: } catch (Exception e) {
1091: }
1092: //
1093: if (d != null) {
1094: try {
1095: final DiagramOperator d2 = d;
1096: new Thread() {
1097: public void run() {
1098: d2.closeAllDocuments();
1099: }
1100: }.start();
1101:
1102: d.waitClosed();
1103: new EventTool().waitNoEvent(1000);
1104: } catch (Exception ex) {
1105: }
1106: ;
1107: }
1108: closeAllModal();
1109: //save
1110: org.netbeans.test.umllib.util.Utils.tearDown();
1111: }
1112:
1113: abstract public void failInPlace(int failId, RuntimeException ex);//most fail will be handled in child class (with specific bugs)
1114:
1115: public class ChooseEnabledState implements ComponentChooser {
1116: private boolean enabled = false;
1117:
1118: ChooseEnabledState(boolean enabled) {
1119: this .enabled = enabled;
1120: }
1121:
1122: public boolean checkComponent(Component component) {
1123: return (component.isEnabled() && enabled)
1124: || (!enabled && !component.isEnabled());
1125: }
1126:
1127: public String getDescription() {
1128: return "choose component if it's enabled: " + enabled;
1129: }
1130:
1131: }
1132: }
|