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.diagramcontextmenu;
043:
044: import java.io.*;
045: import org.netbeans.jemmy.*;
046: import org.netbeans.jemmy.operators.*;
047:
048: import org.netbeans.junit.NbTestSuite;
049: import org.netbeans.test.umllib.*;
050: import org.netbeans.test.uml.diagramcontextmenu.utils.DCMUtils;
051: import org.netbeans.test.umllib.testcases.UMLTestCase;
052: import org.netbeans.test.umllib.util.PopupConstants;
053:
054: /**
055: *
056: * @author yaa
057: * @spec UML/Diagram_ContextMenus.xml
058: */
059: public class DiagramContextMenus_ACD extends UMLTestCase {
060: private static String prName = "UMLProjectDCntMn";
061: private static String acdName = "DActivity";
062:
063: private static final String workDir = System
064: .getProperty("xtest.workdir");
065: private static String OUT_LOG_FILE = "";
066: private static String ERR_LOG_FILE = "";
067: private static PrintStream myOut = null;
068: private static PrintStream myErr = null;
069: private static BufferedReader myIn = null;
070:
071: private String lastTestCase = null;
072:
073: /** Need to be defined because of JUnit */
074: public DiagramContextMenus_ACD(String name) {
075: super (name);
076: }
077:
078: public static NbTestSuite suite() {
079: NbTestSuite suite = new NbTestSuite(
080: org.netbeans.test.uml.diagramcontextmenu.DiagramContextMenus_ACD.class);
081: return suite;
082: }
083:
084: /**
085: * @caseblock Activity Diagram
086: * @usecase Check context menu of activity diagram
087: */
088: public void testItemCopy() {
089: lastTestCase = getCurrentTestMethodName();
090: String itemName = PopupConstants.EDIT + "|"
091: + PopupConstants.COPY;
092: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
093: diagram, itemName);
094: if (item == null) {
095: fail("Diagram popum menu item '" + itemName + "' not found");
096: } else if (item.isEnabled()) {
097: fail("Diagram popum menu item '" + itemName
098: + "' is enabled but should not be");
099: }
100: }
101:
102: /**
103: * @caseblock Activity Diagram
104: * @usecase Check context menu of activity diagram
105: */
106: public void testItemCut() {
107: lastTestCase = getCurrentTestMethodName();
108: String itemName = PopupConstants.EDIT + "|"
109: + PopupConstants.CUT;
110: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
111: diagram, itemName);
112: if (item == null) {
113: fail("Diagram popum menu item '" + itemName + "' not found");
114: } else if (item.isEnabled()) {
115: fail("Diagram popum menu item '" + itemName
116: + "' is enabled but should not be");
117: }
118: }
119:
120: /**
121: * @caseblock Activity Diagram
122: * @usecase Check context menu of activity diagram
123: */
124: public void testItemDelete() {
125: lastTestCase = getCurrentTestMethodName();
126: String itemName = PopupConstants.EDIT + "|"
127: + PopupConstants.DELETE;
128: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
129: diagram, itemName);
130: if (item == null) {
131: fail("Diagram popum menu item '" + itemName + "' not found");
132: } else if (item.isEnabled()) {
133: fail("Diagram popum menu item '" + itemName
134: + "' is enabled but should not be");
135: }
136: }
137:
138: /**
139: * @caseblock Activity Diagram
140: * @usecase Check context menu of activity diagram
141: */
142: public void testItemPaste() {
143: lastTestCase = getCurrentTestMethodName();
144: String itemName = PopupConstants.EDIT + "|"
145: + PopupConstants.PASTE;
146: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
147: diagram, itemName);
148: if (item == null) {
149: fail("Diagram popum menu item '" + itemName + "' not found");
150: } else if (item.isEnabled()) {
151: fail("Diagram popum menu item '" + itemName
152: + "' is enabled but should not be");
153: }
154: }
155:
156: /**
157: * @caseblock Activity Diagram
158: * @usecase Check context menu of activity diagram
159: */
160: public void testItemSelectAll() {
161: lastTestCase = getCurrentTestMethodName();
162: String itemName = PopupConstants.EDIT + "|"
163: + PopupConstants.SELECT_ALL;
164: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
165: diagram, itemName);
166: if (item == null) {
167: fail("Diagram popum menu item '" + itemName + "' not found");
168: } else if (!item.isEnabled()) {
169: fail("Diagram popum menu item '" + itemName
170: + "' is disabled but should not be");
171: }
172: }
173:
174: /**
175: * @caseblock Activity Diagram
176: * @usecase Check context menu of activity diagram
177: */
178: public void testItemSelectAllSimilar() {
179: lastTestCase = getCurrentTestMethodName();
180: String itemName = PopupConstants.EDIT + "|"
181: + PopupConstants.SELECT_ALL_SIMILAR;
182: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
183: diagram, itemName);
184: if (item == null) {
185: fail("Diagram popum menu item '" + itemName + "' not found");
186: } else if (item.isEnabled()) {
187: fail("Diagram popum menu item '" + itemName
188: + "' is enabled but should not be");
189: }
190: }
191:
192: /**
193: * @caseblock Activity Diagram
194: * @usecase Check context menu of activity diagram
195: */
196: public void testItemInvertSelection() {
197: lastTestCase = getCurrentTestMethodName();
198: String itemName = PopupConstants.EDIT + "|"
199: + PopupConstants.INVERT_SELECTION;
200: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
201: diagram, itemName);
202: if (item == null) {
203: fail("Diagram popum menu item '" + itemName + "' not found");
204: } else if (!item.isEnabled()) {
205: fail("Diagram popum menu item '" + itemName
206: + "' is disabled but should not be");
207: }
208: }
209:
210: /**
211: * @caseblock Activity Diagram
212: * @usecase Check context menu of activity diagram
213: */
214: public void testItemSetDimensions() {
215: lastTestCase = getCurrentTestMethodName();
216: String itemName = PopupConstants.EDIT + "|"
217: + PopupConstants.SET_DIMESIONS;
218: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
219: diagram, itemName);
220: if (item == null) {
221: fail("Diagram popum menu item '" + itemName + "' not found");
222: } else if (item.isEnabled()) {
223: fail("Diagram popum menu item '" + itemName
224: + "' is enabled but should not be");
225: }
226: }
227:
228: /**
229: * @caseblock Activity Diagram
230: * @usecase Check context menu of activity diagram
231: */
232: public void testItemLayoutHierarchical() {
233: lastTestCase = getCurrentTestMethodName();
234: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
235: + DCMUtils.DiagramPopupConstants.LAYOUT_HIERARCHICAL;
236: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
237: diagram, itemName);
238: if (item == null) {
239: fail(78330, "Diagram popum menu item '" + itemName
240: + "' not found");
241: } else if (!item.isEnabled()) {
242: fail("Diagram popum menu item '" + itemName
243: + "' is disabled but should not be");
244: }
245: }
246:
247: /**
248: * @caseblock Activity Diagram
249: * @usecase Check context menu of activity diagram
250: */
251: public void testItemLayoutOrthogonal() {
252: lastTestCase = getCurrentTestMethodName();
253: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
254: + DCMUtils.DiagramPopupConstants.LAYOUT_ORTHOGONAL;
255: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
256: diagram, itemName);
257: if (item == null) {
258: fail(78330, "Diagram popum menu item '" + itemName
259: + "' not found");
260: } else if (!item.isEnabled()) {
261: fail("Diagram popum menu item '" + itemName
262: + "' is disabled but should not be");
263: }
264: }
265:
266: /**
267: * @caseblock Activity Diagram
268: * @usecase Check context menu of activity diagram
269: */
270: public void testItemLayoutSymmetric() {
271: lastTestCase = getCurrentTestMethodName();
272: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
273: + DCMUtils.DiagramPopupConstants.LAYOUT_SYMMETRIC;
274: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
275: diagram, itemName);
276: if (item == null) {
277: fail(78330, "Diagram popum menu item '" + itemName
278: + "' not found");
279: } else if (!item.isEnabled()) {
280: fail("Diagram popum menu item '" + itemName
281: + "' is disabled but should not be");
282: }
283: }
284:
285: /**
286: * @caseblock Activity Diagram
287: * @usecase Check context menu of activity diagram
288: */
289: public void testItemLayoutIncremental() {
290: lastTestCase = getCurrentTestMethodName();
291: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
292: + DCMUtils.DiagramPopupConstants.LAYOUT_INCREMENTAL;
293: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
294: diagram, itemName);
295: if (item == null) {
296: fail(78330, "Diagram popum menu item '" + itemName
297: + "' not found");
298: } else if (!item.isEnabled()) {
299: fail("Diagram popum menu item '" + itemName
300: + "' is disabled but should not be");
301: }
302: }
303:
304: /**
305: * @caseblock Activity Diagram
306: * @usecase Check context menu of activity diagram
307: */
308: public void testItemLayoutProperties() {
309: lastTestCase = getCurrentTestMethodName();
310: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
311: + DCMUtils.DiagramPopupConstants.LAYOUT_PROPERTIES;
312: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
313: diagram, itemName);
314: if (item == null) {
315: fail(78330, "Diagram popum menu item '" + itemName
316: + "' not found");
317: } else if (!item.isEnabled()) {
318: fail("Diagram popum menu item '" + itemName
319: + "' is disabled but should not be");
320: } else {
321: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
322: if (!DCMUtils
323: .findAndCloseDialog(DCMUtils.DialogTitles.LAYOUT_PROPERTIES)) {
324: fail("Dialog with title '" + itemName
325: + "' not found or not closed correctly");
326: }
327: }
328: }
329:
330: /**
331: * @caseblock Activity Diagram
332: * @usecase Check context menu of activity diagram
333: */
334: public void testItemZoom() {
335: lastTestCase = getCurrentTestMethodName();
336: String itemName = DCMUtils.DiagramPopupConstants.ZOOM;
337: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
338: diagram, itemName);
339: if (item == null) {
340: fail("Diagram popum menu item '" + itemName + "' not found");
341: } else if (!item.isEnabled()) {
342: fail("Diagram popum menu item '" + itemName
343: + "' is disabled but should not be");
344: } else {
345: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
346: if (!DCMUtils
347: .findAndCloseDialog(DCMUtils.DialogTitles.ZOOM)) {
348: fail("Dialog with title '" + itemName
349: + "' not found or not closed correctly");
350: }
351: }
352: }
353:
354: /**
355: * @caseblock Activity Diagram
356: * @usecase Check context menu of activity diagram
357: */
358: public void testItemZoomIn() {
359: lastTestCase = getCurrentTestMethodName();
360: String itemName = DCMUtils.DiagramPopupConstants.ZOOM_IN;
361: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
362: diagram, itemName);
363: if (item == null) {
364: fail("Diagram popum menu item '" + itemName + "' not found");
365: } else if (!item.isEnabled()) {
366: fail("Diagram popum menu item '" + itemName
367: + "' is disabled but should not be");
368: }
369: }
370:
371: /**
372: * @caseblock Activity Diagram
373: * @usecase Check context menu of activity diagram
374: */
375: public void testItemZoomOut() {
376: lastTestCase = getCurrentTestMethodName();
377: String itemName = DCMUtils.DiagramPopupConstants.ZOOM_OUT;
378: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
379: diagram, itemName);
380: if (item == null) {
381: fail("Diagram popum menu item '" + itemName + "' not found");
382: } else if (!item.isEnabled()) {
383: fail("Diagram popum menu item '" + itemName
384: + "' is disabled but should not be");
385: }
386: }
387:
388: /**
389: * @caseblock Activity Diagram
390: * @usecase Check context menu of activity diagram
391: */
392: public void testItemSynchronize() {
393: lastTestCase = getCurrentTestMethodName();
394: String itemName = DCMUtils.DiagramPopupConstants.SYNCHRONIZE;
395: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
396: diagram, itemName);
397: if (item == null) {
398: fail("Diagram popum menu item '" + itemName + "' not found");
399: } else if (!item.isEnabled()) {
400: fail("Diagram popum menu item '" + itemName
401: + "' is disabled but should not be");
402: }
403: }
404:
405: /**
406: * @caseblock Activity Diagram
407: * @usecase Check context menu of activity diagram
408: */
409: public void testItemAssociateWith() {
410: lastTestCase = getCurrentTestMethodName();
411: String itemName = DCMUtils.DiagramPopupConstants.ASSOCIATE_WITH;
412: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
413: diagram, itemName);
414: if (item == null) {
415: fail("Diagram popum menu item '" + itemName + "' not found");
416: } else if (!item.isEnabled()) {
417: fail("Diagram popum menu item '" + itemName
418: + "' is disabled but should not be");
419: } else {
420: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
421: if (!DCMUtils
422: .findAndCloseDialog(DCMUtils.DialogTitles.ASSOCIATE_WITH)) {
423: fail("Dialog with title '" + itemName
424: + "' not found or not closed correctly");
425: }
426: }
427: }
428:
429: /**
430: * @caseblock Activity Diagram
431: * @usecase Check context menu of activity diagram
432: */
433: public void testItemApplyDesignPattern() {
434: lastTestCase = getCurrentTestMethodName();
435: String itemName = DCMUtils.DiagramPopupConstants.APPLY_DESIGN_PATTERN;
436: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
437: diagram, itemName);
438: if (item == null) {
439: fail("Diagram popum menu item '" + itemName + "' not found");
440: } else if (!item.isEnabled()) {
441: fail("Diagram popum menu item '" + itemName
442: + "' is disabled but should not be");
443: } else {
444: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
445: if (!DCMUtils
446: .findAndCloseDialog(DCMUtils.DialogTitles.APPLY_DESIGN_PATTERN)) {
447: fail("Dialog with title '" + itemName
448: + "' not found or not closed correctly");
449: }
450: }
451: }
452:
453: /**
454: * @caseblock Activity Diagram
455: * @usecase Check context menu of activity diagram
456: */
457: public void testItemProperties() {
458: lastTestCase = getCurrentTestMethodName();
459: String itemName = DCMUtils.DiagramPopupConstants.PROPERTIES;
460: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
461: diagram, itemName);
462: if (item == null) {
463: fail("Diagram popum menu item '" + itemName + "' not found");
464: } else if (!item.isEnabled()) {
465: fail("Diagram popum menu item '" + itemName
466: + "' is disabled but should not be");
467: } else {
468: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
469: if (!DCMUtils
470: .findAndCloseDialog(DCMUtils.DialogTitles.PROPERTIES)) {
471: fail("Dialog with title '" + itemName
472: + "' not found or not closed correctly");
473: }
474: }
475: }
476:
477: /**
478: * @caseblock Activity Diagram
479: * @usecase Check context menu of activity diagram
480: */
481: public void testCheckUnnecessaryItems() {
482: lastTestCase = getCurrentTestMethodName();
483: String[] itemsNecessary = new String[] {
484: PopupConstants.EDIT + "|" + PopupConstants.COPY,
485: PopupConstants.EDIT + "|" + PopupConstants.CUT,
486: PopupConstants.EDIT + "|" + PopupConstants.DELETE,
487: PopupConstants.EDIT + "|" + PopupConstants.PASTE,
488: PopupConstants.EDIT + "|" + PopupConstants.SELECT_ALL,
489: PopupConstants.EDIT + "|"
490: + PopupConstants.SELECT_ALL_SIMILAR,
491: PopupConstants.EDIT + "|"
492: + PopupConstants.INVERT_SELECTION,
493: PopupConstants.EDIT + "|"
494: + PopupConstants.SET_DIMESIONS,
495: DCMUtils.DiagramPopupConstants.LAYOUT
496: + "|"
497: + DCMUtils.DiagramPopupConstants.LAYOUT_HIERARCHICAL,
498: DCMUtils.DiagramPopupConstants.LAYOUT
499: + "|"
500: + DCMUtils.DiagramPopupConstants.LAYOUT_ORTHOGONAL,
501: DCMUtils.DiagramPopupConstants.LAYOUT
502: + "|"
503: + DCMUtils.DiagramPopupConstants.LAYOUT_SYMMETRIC,
504: DCMUtils.DiagramPopupConstants.LAYOUT
505: + "|"
506: + DCMUtils.DiagramPopupConstants.LAYOUT_INCREMENTAL,
507: DCMUtils.DiagramPopupConstants.LAYOUT
508: + "|"
509: + DCMUtils.DiagramPopupConstants.LAYOUT_PROPERTIES,
510: DCMUtils.DiagramPopupConstants.ZOOM,
511: DCMUtils.DiagramPopupConstants.ZOOM_IN,
512: DCMUtils.DiagramPopupConstants.ZOOM_OUT,
513: DCMUtils.DiagramPopupConstants.SYNCHRONIZE,
514: DCMUtils.DiagramPopupConstants.ASSOCIATE_WITH,
515: DCMUtils.DiagramPopupConstants.PROPERTIES,
516: DCMUtils.DiagramPopupConstants.SELECT_IN_MODEL,
517: DCMUtils.DiagramPopupConstants.APPLY_DESIGN_PATTERN };
518:
519: String result = DCMUtils.checkUnnecessaryItems(diagram,
520: itemsNecessary, getLog());
521: if (!result.equals("")) {
522: fail("Diagram context menu contains unnecessary items (see log also): "
523: + result);
524: }
525: }
526:
527: //------------------------------------------------------------------------------
528:
529: public void setUp() throws FileNotFoundException {
530: System.out.println("######## " + getName() + " #######");
531: JemmyProperties.setCurrentTimeout(
532: "DialogWaiter.WaitDialogTimeout", 1000);
533: JemmyProperties.setCurrentTimeout("Waiter.WaitingTime", 1000);
534: JemmyProperties.setCurrentTimeout(
535: "JMenuOperator.WaitPopupTimeout", 2000);
536: JemmyProperties.setCurrentTimeout(
537: "ComponentOperator.WaitComponentTimeout", 2000);
538: JemmyProperties.setCurrentTimeout(
539: "WindowWaiter.WaitWindowTimeout", 2000);
540:
541: OUT_LOG_FILE = workDir + File.separator + "jout_" + getName()
542: + ".log";
543: ERR_LOG_FILE = workDir + File.separator + "jerr_" + getName()
544: + ".log";
545:
546: myOut = new PrintStream(new FileOutputStream(OUT_LOG_FILE),
547: true);
548: myErr = new PrintStream(new FileOutputStream(ERR_LOG_FILE),
549: true);
550: JemmyProperties.setCurrentOutput(new TestOut(System.in, myOut,
551: myErr));
552:
553: diagram = DCMUtils.openDiagram(prName, acdName,
554: NewDiagramWizardOperator.ACTIVITY_DIAGRAM, workDir);
555: if (diagram == null) {
556: fail("Can't open diagram '" + acdName + "', project '"
557: + prName + "'.");
558: }
559: }
560:
561: public void tearDown() throws FileNotFoundException, IOException,
562: InterruptedException {
563: org.netbeans.test.umllib.util.Utils
564: .makeScreenShot(lastTestCase);
565: //org.netbeans.test.umllib.util.Utils.tearDown();
566: diagram.getDrawingArea().pushKey(
567: java.awt.event.KeyEvent.VK_ESCAPE);
568: try {
569: JDialogOperator dlgError = new JDialogOperator(
570: "Unexpected Exception");
571: JTextAreaOperator textarea = new JTextAreaOperator(dlgError);
572: String str = textarea.getDisplayedText();
573: int pos = str.indexOf("\n");
574: if (pos != -1) {
575: str = str.substring(1, pos - 1);
576: }
577: dlgError.close();
578: fail(" " + str);
579: } catch (TimeoutExpiredException e) {
580: }
581:
582: myIn = new BufferedReader(new FileReader(ERR_LOG_FILE));
583: String line;
584: do {
585: line = myIn.readLine();
586: if (line != null && line.indexOf("Exception") != -1) {
587: if ((line.indexOf("Unexpected Exception") == -1)
588: && (line.indexOf("TimeoutExpiredException") == -1)) {
589: //fail(line);
590: }
591: }
592: } while (line != null);
593: }
594:
595: private DiagramOperator diagram = null;
596: }
|