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.sqd;
043:
044: import java.awt.AWTException;
045: import java.awt.event.KeyEvent;
046: import java.io.File;
047: import org.netbeans.jellytools.actions.SaveAllAction;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jemmy.EventTool;
050: import org.netbeans.jemmy.JemmyProperties;
051: import org.netbeans.jemmy.operators.JButtonOperator;
052: import org.netbeans.jemmy.operators.JDialogOperator;
053: import org.netbeans.junit.NbTestSuite;
054:
055: import org.netbeans.test.uml.sqd.utils.Util;
056: import org.netbeans.test.umllib.DiagramOperator;
057: import org.netbeans.test.umllib.project.Project;
058: import org.netbeans.test.umllib.testcases.UMLTestCase;
059:
060: public class SQDDiagramTests extends UMLTestCase {
061:
062: private EventTool eventTool = new EventTool();
063: private boolean failedByBug = false;
064: private String lastTestCase = null;
065:
066: public SQDDiagramTests(String name) {
067: super (name);
068: }
069:
070: public static NbTestSuite suite() {
071: NbTestSuite suite = new NbTestSuite(SQDDiagramTests.class);
072: return suite;
073: }
074:
075: /******************const section*************************/
076: private String PROJECT_NAME = "SQD_umlDT";
077: private String JAVA_PROJECT_NAME = "SQD_java";
078: private String EXCEPTION_DLG = "Exception";
079: private String PKG_PATH = "Model|sqd";
080: private String DIAGRAM = "EmptySequenceDiagram";
081: final String PATH_TO_DIAGRAM = "Model|sqd|" + DIAGRAM;
082: public final String OPEN_DIAGRAM = "Open";
083: public final String DELETE_DIAGRAM = "Delete";
084:
085: private final String CONFIRM_DELETION_DLG_TTL = "Confirm Object Deletion";
086: private final String YES_BTN = "Yes";
087: private final String PROJECT_PATH = System
088: .getProperty("xtest.workdir");
089:
090: /********************************************************/
091:
092: Util util = new Util(PROJECT_NAME);
093:
094: private static boolean initialized = false;
095:
096: protected void setUp() {
097: if (!initialized) {
098: //util.closeStartupException();
099: Project.openProject(this .XTEST_PROJECT_DIR + File.separator
100: + "Project-SQD");
101: org.netbeans.test.umllib.Utils
102: .createUMLProjectFromJavaProject(PROJECT_NAME,
103: JAVA_PROJECT_NAME, PROJECT_PATH);
104: eventTool.waitNoEvent(2000);
105: //setting up environment
106: util.addDiagram(DIAGRAM, PKG_PATH);
107: eventTool.waitNoEvent(2000);
108: initialized = true;
109: java.awt.Robot rbt;
110: try {
111: rbt = new java.awt.Robot();
112: rbt.keyRelease(KeyEvent.VK_SHIFT);
113: rbt.keyRelease(KeyEvent.VK_CONTROL);
114: rbt.keyRelease(KeyEvent.VK_ALT);
115: } catch (AWTException ex) {
116: ex.printStackTrace();
117: }
118: }
119: eventTool.waitNoEvent(2000);
120: }
121:
122: public void testCreateDiagram() {
123: lastTestCase = getCurrentTestMethodName();
124: ;
125: final String DIAGRAM_NAME = "testCreateDiagram";
126: util.addDiagram(DIAGRAM_NAME, PKG_PATH);
127: DiagramOperator dia = new DiagramOperator(DIAGRAM_NAME);
128: }
129:
130: public void testOpenDiagramByContextMenu() {
131: lastTestCase = getCurrentTestMethodName();
132: ;
133: Node diaNode = util.getNode(PATH_TO_DIAGRAM);
134: diaNode.performPopupActionNoBlock(OPEN_DIAGRAM);
135: new DiagramOperator(DIAGRAM);
136: }
137:
138: public void testOpenDiagramByDoubleClick() {
139: lastTestCase = getCurrentTestMethodName();
140: ;
141: Node diaNode = util.getNode(PATH_TO_DIAGRAM);
142: diaNode.tree().clickOnPath(diaNode.getTreePath(), 2);
143: new DiagramOperator(DIAGRAM);
144: }
145:
146: public void testDeleteDiagramByButton() {
147: lastTestCase = getCurrentTestMethodName();
148: ;
149: Node diaNode = util.getNode(PATH_TO_DIAGRAM);
150: diaNode.select();
151:
152: diaNode.tree().pushKey(KeyEvent.VK_DELETE);
153:
154: new JButtonOperator(new JDialogOperator(
155: CONFIRM_DELETION_DLG_TTL), YES_BTN).push();
156: eventTool.waitNoEvent(1000);
157:
158: if (util.nodeExists(PATH_TO_DIAGRAM)) {
159: fail("Node exists");
160: }
161: }
162:
163: public void testDeleteDiagramByContextMenu() {
164: lastTestCase = getCurrentTestMethodName();
165: ;
166: final String DIAGRAM_NAME = "testDeleteDiagramByContextMenu";
167:
168: //creating diagram first
169: util.addDiagram(DIAGRAM_NAME, PKG_PATH);
170: eventTool.waitNoEvent(1000);
171: new DiagramOperator(DIAGRAM_NAME);
172: Node diaNode = util.getNode(PKG_PATH + "|" + DIAGRAM_NAME);
173: diaNode.performPopupActionNoBlock(DELETE_DIAGRAM);
174:
175: //deleting it
176: new JButtonOperator(new JDialogOperator(
177: CONFIRM_DELETION_DLG_TTL), YES_BTN).push();
178: eventTool.waitNoEvent(1000);
179:
180: if (util.nodeExists(PKG_PATH + "|" + DIAGRAM_NAME)) {
181: fail("testDeleteDiagramByContextMenu verification failed");
182: }
183: }
184:
185: public void tearDown() {
186: org.netbeans.test.umllib.util.Utils
187: .makeScreenShot(lastTestCase);
188: long timeoutValDlg = JemmyProperties
189: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
190: try {
191: JemmyProperties.setCurrentTimeout(
192: "DialogWaiter.WaitDialogTimeout", 1000);
193: new JDialogOperator(EXCEPTION_DLG).close();
194: if (!failedByBug) {
195: fail("Unexpected Exception dialog was found");
196: }
197: } catch (Exception excp) {
198: } finally {
199: org.netbeans.test.umllib.util.Utils.saveAll();
200: closeAllModal();
201: if (failedByBug) {
202: failedByBug = false;
203: }
204: JemmyProperties.setCurrentTimeout(
205: "DialogWaiter.WaitDialogTimeout", timeoutValDlg);
206: //TODO: should be removed later
207: util.closeSaveDlg();
208: }
209: }
210:
211: }
|