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.umllib.vrf;
043:
044: import java.awt.Point;
045: import java.awt.Robot;
046: import java.awt.event.KeyEvent;
047: import java.io.PrintStream;
048: import org.netbeans.jellytools.actions.SaveAllAction;
049: import org.netbeans.jemmy.JemmyProperties;
050: import org.netbeans.jemmy.TimeoutExpiredException;
051: import org.netbeans.jemmy.operators.JButtonOperator;
052: import org.netbeans.jemmy.operators.JCheckBoxOperator;
053: import org.netbeans.jemmy.operators.JDialogOperator;
054: import org.netbeans.jemmy.operators.JPopupMenuOperator;
055: import org.netbeans.test.umllib.DiagramElementOperator;
056: import org.netbeans.test.umllib.DiagramOperator;
057: import org.netbeans.test.umllib.ElementTypes;
058: import org.netbeans.test.umllib.LinkOperator;
059: import org.netbeans.test.umllib.LinkTypes;
060: import org.netbeans.test.umllib.customelements.LifelineOperator;
061: import org.netbeans.test.umllib.exceptions.NotFoundException;
062: import org.netbeans.test.umllib.exceptions.UnexpectedElementSelectionException;
063: import org.netbeans.test.umllib.util.PopupConstants;
064:
065: public class LinkVerifier extends GenericVerifier {
066: private LinkTypes linkType = null;
067: private String prefix = "";
068:
069: public LinkVerifier(DiagramOperator dia, LinkTypes linkType) {
070: this (dia, linkType, "", null);
071: }
072:
073: public LinkVerifier(DiagramOperator dia, LinkTypes linkType,
074: String prefix) {
075: this (dia, linkType, prefix, null);
076: }
077:
078: public LinkVerifier(DiagramOperator dia, LinkTypes linkType,
079: PrintStream log) {
080: this (dia, linkType, "", log);
081: }
082:
083: public LinkVerifier(DiagramOperator dia, LinkTypes linkType,
084: String prefix, PrintStream log) {
085: super (dia, log);
086: this .linkType = linkType;
087: this .prefix = prefix;
088: }
089:
090: public boolean checkDeleteByPopup(ElementTypes sourceElementType,
091: ElementTypes targetElementType) {
092: final String EL_NAME = prefix + "DelP";// + linkType.toString().substring(0, 3);
093: try {
094: //create source element
095: DiagramElementOperator el1 = createElement(EL_NAME + "S",
096: sourceElementType);
097: eventTool.waitNoEvent(500);
098:
099: //create target element
100: Point point = dia.getDrawingArea().getFreePoint(170);
101: DiagramElementOperator el2 = createElement(EL_NAME + "T",
102: targetElementType, point.x, point.y);
103: eventTool.waitNoEvent(500);
104:
105: //create link
106: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
107: eventTool.waitNoEvent(500);
108:
109: new SaveAllAction().performAPI();
110: eventTool.waitNoEvent(500);
111:
112: //deleting
113: new Thread(new Runnable() {
114: public void run() {
115: eventTool.waitNoEvent(1000);
116: new JCheckBoxOperator(new JDialogOperator(
117: DELETE_DLG)).clickMouse();
118: new JButtonOperator(
119: new JDialogOperator(DELETE_DLG), YES_BTN)
120: .push();
121: }
122: }).start();
123:
124: LinkOperator link = new LinkOperator(el1, el2);
125: JPopupMenuOperator popup = link.getPopup();
126: //to close automatically opened submenu before searching for menu item
127: eventTool.waitNoEvent(500);
128: popup.pushKey(KeyEvent.VK_LEFT);
129: popup = new JPopupMenuOperator();
130: popup.pushMenu(PopupConstants.EDIT + "|"
131: + PopupConstants.DELETE);
132: eventTool.waitNoEvent(2000);
133:
134: //checking the link has disappeared
135: long timeoutVal = JemmyProperties
136: .getCurrentTimeout("LinkOperator.WaitLinkTime");
137: JemmyProperties.setCurrentTimeout(
138: "LinkOperator.WaitLinkTime", 2000);
139: try {
140: new LinkOperator(el1, el2);
141: log("Link still present on diagram after "
142: + PopupConstants.DELETE + " action");
143: return false;
144: } catch (Exception e) {
145: } finally {
146: JemmyProperties.setCurrentTimeout(
147: "LinkOperator.WaitLinkTime", timeoutVal);
148: }
149:
150: return true;
151: } catch (Exception e) {
152: if (log != null) {
153: e.printStackTrace(log);
154: }
155: return false;
156: } finally {
157: safeDeleteAllElements();
158: }
159: }
160:
161: public boolean checkDeleteByShortcut(
162: ElementTypes sourceElementType,
163: ElementTypes targetElementType) {
164: final String EL_NAME = prefix + "DelS";// + linkType.toString().substring(0, 3);
165: try {
166: //create source element
167: DiagramElementOperator el1 = createElement(EL_NAME + "S",
168: sourceElementType);
169: eventTool.waitNoEvent(500);
170:
171: //create target element
172: Point point = dia.getDrawingArea().getFreePoint(170);
173: DiagramElementOperator el2 = createElement(EL_NAME + "T",
174: targetElementType, point.x, point.y);
175: eventTool.waitNoEvent(500);
176:
177: //create link
178: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
179: eventTool.waitNoEvent(500);
180:
181: new SaveAllAction().performAPI();
182: eventTool.waitNoEvent(500);
183:
184: //deleting
185: new Thread(new Runnable() {
186: public void run() {
187: eventTool.waitNoEvent(1000);
188: new JCheckBoxOperator(new JDialogOperator(
189: DELETE_DLG)).clickMouse();
190: new JButtonOperator(
191: new JDialogOperator(DELETE_DLG), YES_BTN)
192: .push();
193: }
194: }).start();
195:
196: LinkOperator link = new LinkOperator(el1, el2);
197: link.select();
198: pushKey(KeyEvent.VK_DELETE);
199: eventTool.waitNoEvent(2000);
200:
201: //checking the link has disappeared
202: long timeoutVal = JemmyProperties
203: .getCurrentTimeout("LinkOperator.WaitLinkTime");
204: JemmyProperties.setCurrentTimeout(
205: "LinkOperator.WaitLinkTime", 2000);
206: try {
207: new LinkOperator(el1, el2);
208: log("Link still present on diagram after "
209: + PopupConstants.DELETE + " action");
210: return false;
211: } catch (Exception e) {
212: } finally {
213: JemmyProperties.setCurrentTimeout(
214: "LinkOperator.WaitLinkTime", timeoutVal);
215: }
216:
217: return true;
218: } catch (Exception e) {
219: if (log != null) {
220: e.printStackTrace(log);
221: }
222: return false;
223: } finally {
224: safeDeleteAllElements();
225: }
226: }
227:
228: public boolean checkSelectAllByPopup(
229: ElementTypes sourceElementType,
230: ElementTypes targetElementType, LinkTypes lnkType) {
231: final String EL_NAME = prefix + "SelAllP";// + linkType.toString().substring(0, 3);
232: try {
233: //create source element
234: DiagramElementOperator el1 = createElement(EL_NAME + "S",
235: sourceElementType);
236: eventTool.waitNoEvent(500);
237:
238: //create target element
239: Point point = dia.getDrawingArea().getFreePoint(170);
240: DiagramElementOperator el2 = createElement(EL_NAME + "T",
241: targetElementType, point.x, point.y);
242: eventTool.waitNoEvent(500);
243:
244: //create link
245: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
246: eventTool.waitNoEvent(500);
247:
248: point = dia.getDrawingArea().getFreePoint(170);
249: DiagramElementOperator el3 = createElement(EL_NAME + "S2",
250: sourceElementType, point.x, point.y);
251: eventTool.waitNoEvent(500);
252:
253: point = dia.getDrawingArea().getFreePoint(170);
254: DiagramElementOperator el4 = createElement(EL_NAME + "T2",
255: targetElementType, point.x, point.y);
256: eventTool.waitNoEvent(500);
257:
258: dia.createGenericRelationshipOnDiagram(lnkType, el3, el4);
259: eventTool.waitNoEvent(500);
260:
261: new SaveAllAction().performAPI();
262: eventTool.waitNoEvent(500);
263:
264: //select all
265: LinkOperator link = new LinkOperator(el1, el2);
266: JPopupMenuOperator popup = link.getPopup();
267: //to close automatically opened submenu before searching for menu item
268: eventTool.waitNoEvent(500);
269: popup.pushKey(KeyEvent.VK_LEFT);
270: popup = new JPopupMenuOperator();
271: popup.pushMenu(PopupConstants.EDIT + "|"
272: + PopupConstants.SELECT_ALL);
273: eventTool.waitNoEvent(2000);
274:
275: //checking everything was selected
276:
277: el1 = getElement(EL_NAME + "S", sourceElementType, 0);
278: if (!el1.isSelected()) {
279: log("Element '" + EL_NAME + "S" + "' not selected");
280: return false;
281: }
282: el2 = getElement(EL_NAME + "T", targetElementType, 0);
283: if (!el2.isSelected()) {
284: log("Element '" + EL_NAME + "T" + "' not selected");
285: return false;
286: }
287: el3 = getElement(EL_NAME + "S2", sourceElementType, 0);
288: if (!el3.isSelected()) {
289: log("Element '" + EL_NAME + "S2" + "' not selected");
290: return false;
291: }
292: el4 = getElement(EL_NAME + "T2", targetElementType, 0);
293: if (!el4.isSelected()) {
294: log("Element '" + EL_NAME + "T2" + "' not selected");
295: return false;
296: }
297:
298: LinkOperator lnk1 = new LinkOperator(el1, el2);
299: if (!lnk1.isSelected()) {
300: log(lnk1.getType() + "(1) link not selected");
301: return false;
302: }
303: LinkOperator lnk2 = new LinkOperator(el3, el4);
304: if (!lnk2.isSelected()) {
305: log(lnk2.getType() + "(2) link not selected");
306: return false;
307: }
308:
309: return true;
310: } catch (Exception e) {
311: if (log != null) {
312: e.printStackTrace(log);
313: }
314: return false;
315: } finally {
316: safeDeleteAllElements();
317: }
318: }
319:
320: public boolean checkInvertSelection(ElementTypes sourceElementType,
321: ElementTypes targetElementType, LinkTypes lnkType) {
322: final String EL_NAME = prefix + "InvSel";// + linkType.toString().substring(0, 3);
323: try {
324: //create source element
325: DiagramElementOperator el1 = createElement(EL_NAME + "S",
326: sourceElementType);
327: eventTool.waitNoEvent(500);
328:
329: //create target element
330: Point point = dia.getDrawingArea().getFreePoint(170);
331: DiagramElementOperator el2 = createElement(EL_NAME + "T",
332: targetElementType, point.x, point.y);
333: eventTool.waitNoEvent(500);
334:
335: //create link
336: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
337: eventTool.waitNoEvent(500);
338:
339: point = dia.getDrawingArea().getFreePoint(170);
340: DiagramElementOperator el3 = createElement(EL_NAME + "S2",
341: sourceElementType, point.x, point.y);
342: eventTool.waitNoEvent(500);
343:
344: point = dia.getDrawingArea().getFreePoint(170);
345: DiagramElementOperator el4 = createElement(EL_NAME + "T2",
346: targetElementType, point.x, point.y);
347: eventTool.waitNoEvent(500);
348:
349: dia.createGenericRelationshipOnDiagram(lnkType, el3, el4);
350: eventTool.waitNoEvent(500);
351:
352: new SaveAllAction().performAPI();
353: eventTool.waitNoEvent(1500);
354:
355: //
356: LinkOperator link = new LinkOperator(el1, el2);
357: JPopupMenuOperator popup = link.getPopup();
358: //to close automatically opened submenu before searching for menu item
359: eventTool.waitNoEvent(500);
360: popup.pushKey(KeyEvent.VK_LEFT);
361: popup = new JPopupMenuOperator();
362: popup.pushMenu(PopupConstants.EDIT + "|"
363: + PopupConstants.INVERT_SELECTION);
364: eventTool.waitNoEvent(2000);
365:
366: //checking selection
367:
368: el1 = getElement(EL_NAME + "S", sourceElementType, 0);
369: if (!el1.isSelected()) {
370: log("Element '" + EL_NAME + "S" + "' not selected");
371: return false;
372: }
373: el2 = getElement(EL_NAME + "T", targetElementType, 0);
374: if (!el2.isSelected()) {
375: log("Element '" + EL_NAME + "T" + "' not selected");
376: return false;
377: }
378: el3 = getElement(EL_NAME + "S2", sourceElementType, 0);
379: if (!el3.isSelected()) {
380: log("Element '" + EL_NAME + "S2" + "' not selected");
381: return false;
382: }
383: el4 = getElement(EL_NAME + "T2", targetElementType, 0);
384: if (!el4.isSelected()) {
385: log("Element '" + EL_NAME + "T2" + "' not selected");
386: return false;
387: }
388:
389: LinkOperator lnk1 = new LinkOperator(el1, el2);
390: if (lnk1.isSelected()) {
391: log(lnk1.getType() + "link selected");
392: return false;
393: }
394: LinkOperator lnk2 = new LinkOperator(el3, el4);
395: if (!lnk2.isSelected()) {
396: log(lnk2.getType() + " link not selected");
397: return false;
398: }
399:
400: return true;
401: } catch (Exception e) {
402: if (log != null) {
403: e.printStackTrace(log);
404: }
405: return false;
406: } finally {
407: safeDeleteAllElements();
408: }
409: }
410:
411: public boolean checkFindSourceElement(
412: ElementTypes sourceElementType,
413: ElementTypes targetElementType) {
414: final String EL_NAME = prefix + "FindSrc";// + linkType.toString().substring(0, 3);
415: try {
416: //create source element
417: DiagramElementOperator el1 = createElement(EL_NAME + "S",
418: sourceElementType);
419: eventTool.waitNoEvent(500);
420:
421: //create target element
422: Point point = dia.getDrawingArea().getFreePoint(170);
423: DiagramElementOperator el2 = createElement(EL_NAME + "T",
424: targetElementType, point.x, point.y);
425: eventTool.waitNoEvent(500);
426:
427: //create link
428: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
429: eventTool.waitNoEvent(1000);
430:
431: new SaveAllAction().performAPI();
432: eventTool.waitNoEvent(1500);
433:
434: //call popup
435: LinkOperator link = new LinkOperator(el1, el2);
436: JPopupMenuOperator popup = link.getPopup();
437: //to close automatically opened submenu before searching for menu item
438: eventTool.waitNoEvent(500);
439: popup.pushKey(KeyEvent.VK_LEFT);
440: popup = new JPopupMenuOperator();
441: popup.pushMenu(PopupConstants.FIND + "|"
442: + PopupConstants.SOURCE_ELEMENT);
443: eventTool.waitNoEvent(2000);
444:
445: //checking selection
446:
447: el1 = getElement(EL_NAME + "S", sourceElementType, 0);
448: if (!el1.isSelected()) {
449: String description = "Element '" + EL_NAME + "S"
450: + "' not selected";
451: log(description);
452: throw new UnexpectedElementSelectionException(
453: description,
454: UnexpectedElementSelectionException.Status.NOTSELECTED,
455: el1);
456: //return false;
457: }
458:
459: el2 = getElement(EL_NAME + "T", targetElementType, 0);
460: if (el2.isSelected()) {
461: String description = "Element '" + EL_NAME + "T"
462: + "' selected";
463: log(description);
464: throw new UnexpectedElementSelectionException(
465: description,
466: UnexpectedElementSelectionException.Status.SELECTED,
467: el2);
468: //return false;
469: }
470:
471: LinkOperator lnk = new LinkOperator(el1, el2);
472: if (lnk.isSelected()) {
473: String description = lnk.getType() + "link selected";
474: log(description);
475: throw new UnexpectedElementSelectionException(
476: description,
477: UnexpectedElementSelectionException.Status.SELECTED,
478: lnk);
479: //return false;
480: }
481:
482: return true;
483: //}catch(Exception e){
484: // if (log != null){e.printStackTrace(log);}
485: // return false;
486: } finally {
487: safeDeleteAllElements();
488: }
489: }
490:
491: public boolean checkFindTargetElement(
492: ElementTypes sourceElementType,
493: ElementTypes targetElementType) {
494: final String EL_NAME = prefix + "FindTgt";// + linkType.toString().substring(0, 3);
495: try {
496: //create source element
497: DiagramElementOperator el1 = createElement(EL_NAME + "S",
498: sourceElementType);
499: eventTool.waitNoEvent(500);
500:
501: //create target element
502: Point point = dia.getDrawingArea().getFreePoint(170);
503: DiagramElementOperator el2 = createElement(EL_NAME + "T",
504: targetElementType, point.x, point.y);
505: eventTool.waitNoEvent(500);
506:
507: //create link
508: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
509: eventTool.waitNoEvent(1000);
510:
511: new SaveAllAction().performAPI();
512: eventTool.waitNoEvent(1500);
513:
514: //call popup
515: LinkOperator link = new LinkOperator(el1, el2);
516: JPopupMenuOperator popup = link.getPopup();
517: //to close automatically opened submenu before searching for menu item
518: eventTool.waitNoEvent(500);
519: popup.pushKey(KeyEvent.VK_LEFT);
520: popup = new JPopupMenuOperator();
521: popup.pushMenu(PopupConstants.FIND + "|"
522: + PopupConstants.TARGET_ELEMENT);
523: eventTool.waitNoEvent(2000);
524:
525: //checking selection
526:
527: el1 = getElement(EL_NAME + "S", sourceElementType, 0);
528: if (el1.isSelected()) {
529: String description = "Element '" + EL_NAME + "S"
530: + "' selected";
531: log(description);
532: throw new UnexpectedElementSelectionException(
533: description,
534: UnexpectedElementSelectionException.Status.SELECTED,
535: el1);
536: //return false;
537: }
538:
539: el2 = getElement(EL_NAME + "T", targetElementType, 0);
540: if (!el2.isSelected()) {
541: String description = "Element '" + EL_NAME + "T"
542: + "' not selected";
543: log(description);
544: throw new UnexpectedElementSelectionException(
545: description,
546: UnexpectedElementSelectionException.Status.NOTSELECTED,
547: el2);
548: //return false;
549: }
550:
551: LinkOperator lnk = new LinkOperator(el1, el2);
552: if (lnk.isSelected()) {
553: String description = lnk.getType() + "link selected";
554: log(description);
555: throw new UnexpectedElementSelectionException(
556: description,
557: UnexpectedElementSelectionException.Status.SELECTED,
558: lnk);
559: //return false;
560: }
561:
562: return true;
563: //}catch(Exception e){
564: // if (log != null){e.printStackTrace(log);}
565: // return false;
566: } finally {
567: safeDeleteAllElements();
568: }
569: }
570:
571: public boolean checkRedirectSourceElement(
572: ElementTypes sourceElementType,
573: ElementTypes targetElementType,
574: ElementTypes redirectElementType) {
575: final String EL_NAME = prefix + "RdrSrc";// + linkType.toString().substring(0, 3);
576: try {
577: //create source element
578: DiagramElementOperator el1 = createElement(EL_NAME + "S",
579: sourceElementType);
580: eventTool.waitNoEvent(500);
581:
582: //create target element
583: Point point = dia.getDrawingArea().getFreePoint(170);
584: DiagramElementOperator el2 = createElement(EL_NAME + "T",
585: targetElementType, point.x, point.y);
586: eventTool.waitNoEvent(500);
587:
588: //create element to redirect
589: point = dia.getDrawingArea().getFreePoint(170);
590: DiagramElementOperator el3 = createElement(EL_NAME + "R",
591: redirectElementType, point.x, point.y);
592: eventTool.waitNoEvent(500);
593:
594: //create link
595: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
596: eventTool.waitNoEvent(1000);
597:
598: new SaveAllAction().performAPI();
599: eventTool.waitNoEvent(500);
600:
601: //redirect source
602: LinkOperator lnk = new LinkOperator(el1, el2);
603: point = lnk.getNearSourcePoint();
604: dia.getDrawingArea().clickMouse(point.x, point.y, 1);
605: eventTool.waitNoEvent(500);
606:
607: el3.clickOnCenter();
608: eventTool.waitNoEvent(1000);
609:
610: //checking
611: lnk = new LinkOperator(el3, el2);
612: return true;
613: } catch (Exception e) {
614: if (log != null) {
615: e.printStackTrace(log);
616: }
617: return false;
618: } finally {
619: safeDeleteAllElements();
620: }
621: }
622:
623: public boolean checkRedirectTargetElement(
624: ElementTypes sourceElementType,
625: ElementTypes targetElementType,
626: ElementTypes redirectElementType) {
627: final String EL_NAME = prefix + "RdrTgt";// + linkType.toString().substring(0, 3);
628: try {
629: //create source element
630: DiagramElementOperator el1 = createElement(EL_NAME + "S",
631: sourceElementType);
632: eventTool.waitNoEvent(500);
633:
634: //create target element
635: Point point = dia.getDrawingArea().getFreePoint(170);
636: DiagramElementOperator el2 = createElement(EL_NAME + "T",
637: targetElementType, point.x, point.y);
638: eventTool.waitNoEvent(500);
639:
640: //create element to redirect
641: point = dia.getDrawingArea().getFreePoint(170);
642: DiagramElementOperator el3 = createElement(EL_NAME + "R",
643: redirectElementType, point.x, point.y);
644: eventTool.waitNoEvent(500);
645:
646: //create link
647: dia.createGenericRelationshipOnDiagram(linkType, el1, el2);
648: eventTool.waitNoEvent(1000);
649:
650: new SaveAllAction().performAPI();
651: eventTool.waitNoEvent(500);
652:
653: //redirect source
654: LinkOperator lnk = new LinkOperator(el1, el2);
655:
656: point = lnk.getNearTargetPoint();
657: dia.getDrawingArea().clickMouse(point.x, point.y, 1);
658: eventTool.waitNoEvent(500);
659:
660: el3.clickOnCenter();
661: eventTool.waitNoEvent(1000);
662:
663: //checking
664: lnk = new LinkOperator(el1, el3);
665:
666: return true;
667: } catch (Exception e) {
668: if (log != null) {
669: e.printStackTrace(log);
670: }
671: return false;
672: } finally {
673: safeDeleteAllElements();
674: }
675: }
676:
677: //------------------------------------------------------------------------------
678:
679: }
|