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_DPD extends UMLTestCase {
060: private static String prName = "UMLProjectDCntMn";
061: private static String dpdName = "DDeployment";
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_DPD(String name) {
075: super (name);
076: }
077:
078: public static NbTestSuite suite() {
079: NbTestSuite suite = new NbTestSuite(
080: org.netbeans.test.uml.diagramcontextmenu.DiagramContextMenus_DPD.class);
081: return suite;
082: }
083:
084: /**
085: * @caseblock Deployment Diagram
086: * @usecase Check context menu of deployment 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 Deployment Diagram
104: * @usecase Check context menu of deployment 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 Deployment Diagram
122: * @usecase Check context menu of deployment 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 Deployment Diagram
140: * @usecase Check context menu of deployment 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 Deployment Diagram
158: * @usecase Check context menu of deployment 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 Deployment Diagram
176: * @usecase Check context menu of deployment 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 Deployment Diagram
194: * @usecase Check context menu of deployment 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 Deployment Diagram
212: * @usecase Check context menu of deployment 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 Deployment Diagram
230: * @usecase Check context menu of deployment 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("Diagram popum menu item '" + itemName + "' not found");
240: } else if (!item.isEnabled()) {
241: fail("Diagram popum menu item '" + itemName
242: + "' is disabled but should not be");
243: }
244: }
245:
246: /**
247: * @caseblock Deployment Diagram
248: * @usecase Check context menu of deployment diagram
249: */
250: public void testItemLayoutOrthogonal() {
251: lastTestCase = getCurrentTestMethodName();
252: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
253: + DCMUtils.DiagramPopupConstants.LAYOUT_ORTHOGONAL;
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: }
262: }
263:
264: /**
265: * @caseblock Deployment Diagram
266: * @usecase Check context menu of deployment diagram
267: */
268: public void testItemLayoutSymmetric() {
269: lastTestCase = getCurrentTestMethodName();
270: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
271: + DCMUtils.DiagramPopupConstants.LAYOUT_SYMMETRIC;
272: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
273: diagram, itemName);
274: if (item == null) {
275: fail("Diagram popum menu item '" + itemName + "' not found");
276: } else if (!item.isEnabled()) {
277: fail("Diagram popum menu item '" + itemName
278: + "' is disabled but should not be");
279: }
280: }
281:
282: /**
283: * @caseblock Deployment Diagram
284: * @usecase Check context menu of deployment diagram
285: */
286: public void testItemLayoutIncremental() {
287: lastTestCase = getCurrentTestMethodName();
288: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
289: + DCMUtils.DiagramPopupConstants.LAYOUT_INCREMENTAL;
290: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
291: diagram, itemName);
292: if (item == null) {
293: fail("Diagram popum menu item '" + itemName + "' not found");
294: } else if (!item.isEnabled()) {
295: fail("Diagram popum menu item '" + itemName
296: + "' is disabled but should not be");
297: }
298: }
299:
300: /**
301: * @caseblock Deployment Diagram
302: * @usecase Check context menu of deployment diagram
303: */
304: public void testItemLayoutProperties() {
305: lastTestCase = getCurrentTestMethodName();
306: String itemName = DCMUtils.DiagramPopupConstants.LAYOUT + "|"
307: + DCMUtils.DiagramPopupConstants.LAYOUT_PROPERTIES;
308: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
309: diagram, itemName);
310: if (item == null) {
311: fail("Diagram popum menu item '" + itemName + "' not found");
312: } else if (!item.isEnabled()) {
313: fail("Diagram popum menu item '" + itemName
314: + "' is disabled but should not be");
315: } else {
316: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
317: if (!DCMUtils
318: .findAndCloseDialog(DCMUtils.DialogTitles.LAYOUT_PROPERTIES)) {
319: fail("Dialog with title '" + itemName
320: + "' not found or not closed correctly");
321: }
322: }
323: }
324:
325: /**
326: * @caseblock Deployment Diagram
327: * @usecase Check context menu of deployment diagram
328: */
329: public void testItemZoom() {
330: lastTestCase = getCurrentTestMethodName();
331: String itemName = DCMUtils.DiagramPopupConstants.ZOOM;
332: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
333: diagram, itemName);
334: if (item == null) {
335: fail("Diagram popum menu item '" + itemName + "' not found");
336: } else if (!item.isEnabled()) {
337: fail("Diagram popum menu item '" + itemName
338: + "' is disabled but should not be");
339: } else {
340: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
341: if (!DCMUtils
342: .findAndCloseDialog(DCMUtils.DialogTitles.ZOOM)) {
343: fail("Dialog with title '" + itemName
344: + "' not found or not closed correctly");
345: }
346: }
347: }
348:
349: /**
350: * @caseblock Deployment Diagram
351: * @usecase Check context menu of deployment diagram
352: */
353: public void testItemZoomIn() {
354: lastTestCase = getCurrentTestMethodName();
355: String itemName = DCMUtils.DiagramPopupConstants.ZOOM_IN;
356: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
357: diagram, itemName);
358: if (item == null) {
359: fail("Diagram popum menu item '" + itemName + "' not found");
360: } else if (!item.isEnabled()) {
361: fail("Diagram popum menu item '" + itemName
362: + "' is disabled but should not be");
363: }
364: }
365:
366: /**
367: * @caseblock Deployment Diagram
368: * @usecase Check context menu of deployment diagram
369: */
370: public void testItemZoomOut() {
371: lastTestCase = getCurrentTestMethodName();
372: String itemName = DCMUtils.DiagramPopupConstants.ZOOM_OUT;
373: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
374: diagram, itemName);
375: if (item == null) {
376: fail("Diagram popum menu item '" + itemName + "' not found");
377: } else if (!item.isEnabled()) {
378: fail("Diagram popum menu item '" + itemName
379: + "' is disabled but should not be");
380: }
381: }
382:
383: /**
384: * @caseblock Deployment Diagram
385: * @usecase Check context menu of deployment diagram
386: */
387: public void testItemSynchronize() {
388: lastTestCase = getCurrentTestMethodName();
389: String itemName = DCMUtils.DiagramPopupConstants.SYNCHRONIZE;
390: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
391: diagram, itemName);
392: if (item == null) {
393: fail("Diagram popum menu item '" + itemName + "' not found");
394: } else if (!item.isEnabled()) {
395: fail("Diagram popum menu item '" + itemName
396: + "' is disabled but should not be");
397: }
398: }
399:
400: /**
401: * @caseblock Deployment Diagram
402: * @usecase Check context menu of deployment diagram
403: */
404: public void testItemAssociateWith() {
405: lastTestCase = getCurrentTestMethodName();
406: String itemName = DCMUtils.DiagramPopupConstants.ASSOCIATE_WITH;
407: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
408: diagram, itemName);
409: if (item == null) {
410: fail("Diagram popum menu item '" + itemName + "' not found");
411: } else if (!item.isEnabled()) {
412: fail("Diagram popum menu item '" + itemName
413: + "' is disabled but should not be");
414: } else {
415: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
416: if (!DCMUtils
417: .findAndCloseDialog(DCMUtils.DialogTitles.ASSOCIATE_WITH)) {
418: fail("Dialog with title '" + itemName
419: + "' not found or not closed correctly");
420: }
421: }
422: }
423:
424: /**
425: * @caseblock Deployment Diagram
426: * @usecase Check context menu of deployment diagram
427: */
428: public void testItemApplyDesignPattern() {
429: lastTestCase = getCurrentTestMethodName();
430: String itemName = DCMUtils.DiagramPopupConstants.APPLY_DESIGN_PATTERN;
431: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
432: diagram, itemName);
433: if (item == null) {
434: fail("Diagram popum menu item '" + itemName + "' not found");
435: } else if (!item.isEnabled()) {
436: fail("Diagram popum menu item '" + itemName
437: + "' is disabled but should not be");
438: } else {
439: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
440: if (!DCMUtils
441: .findAndCloseDialog(DCMUtils.DialogTitles.APPLY_DESIGN_PATTERN)) {
442: fail("Dialog with title '" + itemName
443: + "' not found or not closed correctly");
444: }
445: }
446: }
447:
448: /**
449: * @caseblock Deployment Diagram
450: * @usecase Check context menu of deployment diagram
451: */
452: public void testItemProperties() {
453: lastTestCase = getCurrentTestMethodName();
454: String itemName = DCMUtils.DiagramPopupConstants.PROPERTIES;
455: JMenuItemOperator item = DCMUtils.checkDiagramPopupMenuItem(
456: diagram, itemName);
457: if (item == null) {
458: fail("Diagram popum menu item '" + itemName + "' not found");
459: } else if (!item.isEnabled()) {
460: fail("Diagram popum menu item '" + itemName
461: + "' is disabled but should not be");
462: } else {
463: DCMUtils.pushDiagramPopupMenuItem(diagram, itemName);
464: if (!DCMUtils
465: .findAndCloseDialog(DCMUtils.DialogTitles.PROPERTIES)) {
466: fail("Dialog with title '" + itemName
467: + "' not found or not closed correctly");
468: }
469: }
470: }
471:
472: /**
473: * @caseblock Deployment Diagram
474: * @usecase Check context menu of deployment diagram
475: */
476: public void testCheckUnnecessaryItems() {
477: lastTestCase = getCurrentTestMethodName();
478: String[] itemsNecessary = new String[] {
479: PopupConstants.EDIT + "|" + PopupConstants.COPY,
480: PopupConstants.EDIT + "|" + PopupConstants.CUT,
481: PopupConstants.EDIT + "|" + PopupConstants.DELETE,
482: PopupConstants.EDIT + "|" + PopupConstants.PASTE,
483: PopupConstants.EDIT + "|" + PopupConstants.SELECT_ALL,
484: PopupConstants.EDIT + "|"
485: + PopupConstants.SELECT_ALL_SIMILAR,
486: PopupConstants.EDIT + "|"
487: + PopupConstants.INVERT_SELECTION,
488: PopupConstants.EDIT + "|"
489: + PopupConstants.SET_DIMESIONS,
490: DCMUtils.DiagramPopupConstants.LAYOUT
491: + "|"
492: + DCMUtils.DiagramPopupConstants.LAYOUT_HIERARCHICAL,
493: DCMUtils.DiagramPopupConstants.LAYOUT
494: + "|"
495: + DCMUtils.DiagramPopupConstants.LAYOUT_ORTHOGONAL,
496: DCMUtils.DiagramPopupConstants.LAYOUT
497: + "|"
498: + DCMUtils.DiagramPopupConstants.LAYOUT_SYMMETRIC,
499: DCMUtils.DiagramPopupConstants.LAYOUT
500: + "|"
501: + DCMUtils.DiagramPopupConstants.LAYOUT_INCREMENTAL,
502: DCMUtils.DiagramPopupConstants.LAYOUT
503: + "|"
504: + DCMUtils.DiagramPopupConstants.LAYOUT_PROPERTIES,
505: DCMUtils.DiagramPopupConstants.ZOOM,
506: DCMUtils.DiagramPopupConstants.ZOOM_IN,
507: DCMUtils.DiagramPopupConstants.ZOOM_OUT,
508: DCMUtils.DiagramPopupConstants.SYNCHRONIZE,
509: DCMUtils.DiagramPopupConstants.ASSOCIATE_WITH,
510: DCMUtils.DiagramPopupConstants.APPLY_DESIGN_PATTERN,
511: DCMUtils.DiagramPopupConstants.PROPERTIES,
512: DCMUtils.DiagramPopupConstants.SELECT_IN_MODEL };
513:
514: String result = DCMUtils.checkUnnecessaryItems(diagram,
515: itemsNecessary, getLog());
516: if (!result.equals("")) {
517: fail("Diagram context menu contains unnecessary items (see log also): "
518: + result);
519: }
520: }
521:
522: //------------------------------------------------------------------------------
523:
524: public void setUp() throws FileNotFoundException {
525: System.out.println("######## " + getName() + " #######");
526: JemmyProperties.setCurrentTimeout(
527: "DialogWaiter.WaitDialogTimeout", 1000);
528: JemmyProperties.setCurrentTimeout("Waiter.WaitingTime", 1000);
529: JemmyProperties.setCurrentTimeout(
530: "JMenuOperator.WaitPopupTimeout", 2000);
531: JemmyProperties.setCurrentTimeout(
532: "ComponentOperator.WaitComponentTimeout", 2000);
533: JemmyProperties.setCurrentTimeout(
534: "WindowWaiter.WaitWindowTimeout", 2000);
535:
536: OUT_LOG_FILE = workDir + File.separator + "jout_" + getName()
537: + ".log";
538: ERR_LOG_FILE = workDir + File.separator + "jerr_" + getName()
539: + ".log";
540:
541: myOut = new PrintStream(new FileOutputStream(OUT_LOG_FILE),
542: true);
543: myErr = new PrintStream(new FileOutputStream(ERR_LOG_FILE),
544: true);
545: JemmyProperties.setCurrentOutput(new TestOut(System.in, myOut,
546: myErr));
547:
548: diagram = DCMUtils.openDiagram(prName, dpdName,
549: NewDiagramWizardOperator.DEPLOYMENT_DIAGRAM, workDir);
550: if (diagram == null) {
551: fail("Can't open diagram '" + dpdName + "', project '"
552: + prName + "'.");
553: }
554: }
555:
556: public void tearDown() throws FileNotFoundException, IOException,
557: InterruptedException {
558: org.netbeans.test.umllib.util.Utils
559: .makeScreenShot(lastTestCase);
560: //org.netbeans.test.umllib.util.Utils.tearDown();
561: diagram.getDrawingArea().pushKey(
562: java.awt.event.KeyEvent.VK_ESCAPE);
563: try {
564: JDialogOperator dlgError = new JDialogOperator(
565: "Unexpected Exception");
566: JTextAreaOperator textarea = new JTextAreaOperator(dlgError);
567: String str = textarea.getDisplayedText();
568: int pos = str.indexOf("\n");
569: if (pos != -1) {
570: str = str.substring(1, pos - 1);
571: }
572: dlgError.close();
573: fail(" " + str);
574: } catch (TimeoutExpiredException e) {
575: }
576:
577: myIn = new BufferedReader(new FileReader(ERR_LOG_FILE));
578: String line;
579: do {
580: line = myIn.readLine();
581: if (line != null && line.indexOf("Exception") != -1) {
582: if ((line.indexOf("Unexpected Exception") == -1)
583: && (line.indexOf("TimeoutExpiredException") == -1)) {
584: //fail(line);
585: }
586: }
587: } while (line != null);
588: }
589:
590: private DiagramOperator diagram = null;
591: }
|