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.cdfs.utils;
043:
044: import java.util.ArrayList;
045: import javax.swing.JMenuItem;
046: import javax.swing.MenuElement;
047: import org.netbeans.jellytools.ProjectsTabOperator;
048: import org.netbeans.jellytools.actions.ActionNoBlock;
049: import org.netbeans.jellytools.nodes.Node;
050: import org.netbeans.jellytools.nodes.ProjectRootNode;
051: import org.netbeans.jemmy.EventTool;
052: import org.netbeans.jemmy.JemmyProperties;
053: import org.netbeans.jemmy.operators.JPopupMenuOperator;
054: import org.netbeans.test.umllib.DiagramElementOperator;
055: import org.netbeans.test.umllib.DiagramOperator;
056: import org.netbeans.test.umllib.NewDiagramWizardOperator;
057: import org.netbeans.test.umllib.testcases.UMLTestCase;
058:
059: public class CDFSUtil {
060:
061: public static String CDFS_XTEST_PROJECT_DIR = UMLTestCase.XTEST_PROJECT_DIR
062: + "/Projects-CDFS";
063:
064: private String projectName = "";
065: public final String CDFS_MENU = "Create Diagram From Selected Elements...";
066: public final String CDFS_COMPLEX_OBJ_TTL = "Create Diagram From Selected";
067: public final String YES_BTN = "Yes";
068: public final String NO_BTN = "No";
069: public final String OK_BTN = "OK";
070: private final static String FINISH_BTN = "Finish";
071: public final String EXCEPTION_DLG = "Exception";
072:
073: private EventTool eventTool = new EventTool();
074: public UMLTestCase tc = null;
075:
076: private final static String IMPLEMENTATION_MODE = "Implementation";
077:
078: public CDFSUtil(String projectName) {
079: this .projectName = projectName;
080: }
081:
082: public CDFSUtil(String projectName, UMLTestCase ts) {
083: this .projectName = projectName;
084: this .tc = ts;
085: }
086:
087: public Node getNode(String nodePath) {
088: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
089: ProjectRootNode root = new ProjectRootNode(pto.tree(),
090: projectName);
091:
092: Node node = new Node(root, nodePath);
093: return node;
094: }
095:
096: public void selectNode(String nodePath) {
097: Node node = getNode(nodePath);
098: node.select();
099: }
100:
101: public void createDiagram(Node[] nodes, String diagramType,
102: String diagramName) {
103: eventTool.waitNoEvent(1000);
104: new ActionNoBlock(null, CDFS_MENU).performPopup(nodes);
105: NewDiagramWizardOperator wizard = new NewDiagramWizardOperator();
106: wizard.setDiagramType(diagramType);
107: wizard.setDiagramName(diagramName);
108: wizard.clickFinish();
109: }
110:
111: public boolean diagramHasExactElements(String[] elementNames,
112: DiagramOperator dia) {
113: try {
114: DiagramElementOperator[] els = new DiagramElementOperator[elementNames.length];
115: for (int i = 0; i < elementNames.length; i++) {
116: els[i] = new DiagramElementOperator(dia,
117: elementNames[i]);
118: }
119: return diagramHasExactElements(els, dia);
120: } catch (Exception e) {
121: e.printStackTrace(tc.getLog());
122: return false;
123: }
124: }
125:
126: public boolean diagramHasExactElements(
127: DiagramElementOperator[] elements, DiagramOperator dia) {
128: ArrayList<DiagramElementOperator> al = new ArrayList<DiagramElementOperator>();
129: for (int i = 0; i < elements.length; i++) {
130: al.add(elements[i]);
131: }
132:
133: ArrayList<DiagramElementOperator> diaAl = dia
134: .getDiagramElements();
135: for (int i = 0; i < diaAl.size(); i++) {
136: int index = al.indexOf(diaAl.get(i));
137: if (index < 0) {
138: tc.getLog().println(
139: "could not find an element." + diaAl.size()
140: + " " + elements.length);
141: return false;
142: }
143: al.remove(index);
144: }
145:
146: if (al.size() > 0) {
147: tc.getLog().println("element is left" + elements);
148: return false;
149: }
150: return true;
151:
152: }
153:
154: public boolean nodeExists(String path) {
155: long waitNodeTime = JemmyProperties.getCurrentTimeouts()
156: .getTimeout("JTreeOperator.WaitNextNodeTimeout");
157: JemmyProperties.setCurrentTimeout(
158: "JTreeOperator.WaitNextNodeTimeout", 2000);
159: try {
160: Node node = getNode(path);
161: node.select();
162: return true;
163: } catch (Exception e) {
164: return false;
165: } finally {
166: JemmyProperties.setCurrentTimeout(
167: "JTreeOperator.WaitNextNodeTimeout", waitNodeTime);
168: }
169: }
170:
171: public boolean allNodesExist(String parentPath, String[] nodeLabels) {
172: for (int i = 0; i < nodeLabels.length; i++) {
173: if (!nodeExists(parentPath + "|" + nodeLabels[i])) {
174: return false;
175: }
176: }
177: return true;
178: }
179:
180: public boolean isPopupMenuItemExist(JPopupMenuOperator popup,
181: String menuItem) {
182: boolean isAvailable = false;
183:
184: MenuElement[] elements = popup.getSubElements();
185: for (int i = 0; i < elements.length; i++) {
186: if (elements[i] instanceof JMenuItem) {
187: //PopupConstants
188: if (((JMenuItem) elements[i]).getText()
189: .equalsIgnoreCase(menuItem)) {
190: isAvailable = true;
191: break;
192: }
193: }
194: }
195: return isAvailable;
196: }
197:
198: }
|