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: /*
043: * Abstract.java
044: *
045: * Created on 19 Θώνό 2006 γ., 20:16
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.test.umllib.vrf;
052:
053: import java.awt.Point;
054: import java.awt.Robot;
055: import java.awt.event.KeyEvent;
056: import java.io.PrintStream;
057: import org.netbeans.jemmy.EventTool;
058: import org.netbeans.jemmy.JemmyProperties;
059: import org.netbeans.jemmy.TimeoutExpiredException;
060: import org.netbeans.jemmy.operators.JButtonOperator;
061: import org.netbeans.jemmy.operators.JCheckBoxOperator;
062: import org.netbeans.jemmy.operators.JDialogOperator;
063: import org.netbeans.test.umllib.DiagramElementOperator;
064: import org.netbeans.test.umllib.DiagramOperator;
065: import org.netbeans.test.umllib.ElementTypes;
066: import org.netbeans.test.umllib.customelements.LifelineOperator;
067: import org.netbeans.test.umllib.exceptions.NotFoundException;
068:
069: /**
070: *
071: * @author ak153256
072: */
073: public class GenericVerifier {
074:
075: protected EventTool eventTool = new EventTool();
076: protected DiagramOperator dia = null;
077:
078: protected PrintStream log = null;
079: protected Robot robot = null;
080:
081: protected String DELETE_DLG = "Delete";
082: protected String DELETE_PKG_DLG = "Deleting a Package";
083: protected String YES_BTN = "Yes";
084: protected String OK_BTN = "Ok";
085: protected String CANCEL_BTN = "Cancel";
086: protected String FONT_DLG = "Font";
087: protected String BOLD_CHB = "Bold";
088: protected String ITALIC_CHB = "Italic";
089:
090: protected final String CLASSIFIER_PREFIX = "C";
091:
092: /** Creates a new instance of Abstract */
093: public GenericVerifier(DiagramOperator dia) {
094: this (dia, null);
095: }
096:
097: public GenericVerifier(DiagramOperator dia, PrintStream log) {
098: this .dia = dia;
099: this .log = log;
100: try {
101: this .robot = new Robot();
102: } catch (Exception e) {
103: }
104: }
105:
106: public DiagramElementOperator createElement(String name,
107: ElementTypes elementType) throws NotFoundException {
108: Point p = dia.getDrawingArea().getFreePoint();
109: return createElement(name, elementType, p.x, p.y);
110: }
111:
112: public DiagramElementOperator createElement(String name,
113: ElementTypes elementType, int x, int y)
114: throws NotFoundException {
115: if (elementType.equals(ElementTypes.LIFELINE)) {
116: return dia.putElementOnDiagram(name + ":"
117: + CLASSIFIER_PREFIX + name, elementType, x, y);
118: } else if (elementType.equals(ElementTypes.ACTOR_LIFELINE)) {
119: dia.createGenericElementOnDiagram(name + ":"
120: + CLASSIFIER_PREFIX + name, elementType, x, y);
121: return new LifelineOperator(dia, name, CLASSIFIER_PREFIX
122: + name);
123: // TMP workaround for tests....
124: } else if (elementType.equals(ElementTypes.COMPOSITE_STATE)) {
125: return dia.putElementOnDiagram(name, elementType, x, y,
126: new DiagramElementOperator.PropertyNamer());
127: } else if (isElementWithoutEditControl(elementType)) {
128: return dia.putElementOnDiagram(name, elementType, x, y,
129: new DiagramElementOperator.PropertyNamer());
130: } else {
131: return dia.putElementOnDiagram(name, elementType, x, y);
132: }
133: }
134:
135: public DiagramElementOperator getElement(String name)
136: throws NotFoundException {
137: return getElement(name, ElementTypes.ANY, 0);
138: }
139:
140: public DiagramElementOperator getElement(String name,
141: ElementTypes elementType, int index)
142: throws NotFoundException {
143: if (elementType.equals(ElementTypes.LIFELINE)
144: || elementType.equals(ElementTypes.ACTOR_LIFELINE)) {
145: String aName = name + ":" + CLASSIFIER_PREFIX + name;
146: int semicolonPos = aName.indexOf(':');
147: String lineName = aName.substring(0, semicolonPos);
148: String classifierName = aName.substring(semicolonPos + 1);
149: return new LifelineOperator(dia, lineName, classifierName,
150: index);
151: } else {
152: return new DiagramElementOperator(dia, name, elementType,
153: index);
154: }
155: }
156:
157: private boolean isElementWithoutEditControl(ElementTypes elementType) {
158: return elementType.equals(ElementTypes.COMMENT)
159: || elementType.equals(ElementTypes.LINK_COMMENT)
160: ||
161: // activity
162: elementType.equals(ElementTypes.INITIAL_NODE)
163: || elementType.equals(ElementTypes.ACTIVITY_FINAL_NODE)
164: || elementType.equals(ElementTypes.FLOW_FINAL)
165: || elementType.equals(ElementTypes.VERTICAL_FORK)
166: || elementType.equals(ElementTypes.HORIZONTAL_FORK)
167: ||
168: // state
169: elementType.equals(ElementTypes.INITIAL_STATE)
170: || elementType.equals(ElementTypes.VERTICAL_JOIN_MERGE)
171: || elementType
172: .equals(ElementTypes.HORIZONTAL_JOIN_MERGE)
173: || elementType.equals(ElementTypes.FINAL_STATE)
174: || elementType.equals(ElementTypes.ABORTED_FINAL_STATE)
175: || elementType.equals(ElementTypes.CHOICE_PSEUDO_STATE)
176: || elementType
177: .equals(ElementTypes.SHALLOW_HISTORY_STATE)
178: || elementType.equals(ElementTypes.DEEP_HISTORY_STATE)
179: || elementType.equals(ElementTypes.ENTRY_POINT_STATE)
180: || elementType
181: .equals(ElementTypes.JUNCTION_POINT_STATE)
182: || elementType.equals(ElementTypes.CHOICE_PSEUDO_STATE);
183: }
184:
185: public void safeDeleteAllElements() {
186:
187: long timeoutVal = JemmyProperties
188: .getCurrentTimeout("DiagramElementOperator.WaitDiagramElementTime");
189: JemmyProperties.setCurrentTimeout(
190: "DiagramElementOperator.WaitDiagramElementTime", 2000);
191: eventTool.waitNoEvent(500);
192: try {
193: dia = new DiagramOperator(dia.getName());
194: if (dia != null) {
195: //deleting the element
196: Point point = dia.getDrawingArea().getFreePoint();
197: dia.getDrawingArea().clickMouse(point.x, point.y, 1);
198:
199: pushShortcut(KeyEvent.VK_A, KeyEvent.VK_CONTROL);
200:
201: // 2000 milis were changed to 1000. Let's look if this will broke smth
202: eventTool.waitNoEvent(1000);
203:
204: pushKey(KeyEvent.VK_DELETE);
205:
206: new Thread(new Runnable() {
207: public void run() {
208: new JCheckBoxOperator(new JDialogOperator(
209: DELETE_DLG)).clickMouse();
210: new JButtonOperator(new JDialogOperator(
211: DELETE_DLG), YES_BTN).push();
212: }
213: }).start();
214:
215: new Thread(new Runnable() {
216: public void run() {
217: try {
218: for (;;) {
219: new JButtonOperator(
220: new JDialogOperator(
221: DELETE_PKG_DLG),
222: YES_BTN).push();
223: }
224: } catch (TimeoutExpiredException e) {
225: }
226: }
227: }).start();
228: } // end if dia != null
229: } catch (Exception e) {
230: e.printStackTrace(log);
231: } finally {
232: JemmyProperties.setCurrentTimeout(
233: "DiagramElementOperator.WaitDiagramElementTime",
234: timeoutVal);
235: }
236: }
237:
238: protected void pushKey(int key) {
239: robot.keyPress(key);
240: eventTool.waitNoEvent(100);
241: robot.keyRelease(key);
242: }
243:
244: protected void pushShortcut(int key, int mask) {
245: robot.keyPress(mask);
246: eventTool.waitNoEvent(100);
247: pushKey(key);
248: eventTool.waitNoEvent(100);
249: robot.keyRelease(mask);
250: }
251:
252: protected void log(String message) {
253: if (log != null) {
254: log.println(message);
255: }
256: }
257:
258: }
|