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