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.diagramtoolbarbuttons;
043:
044: import java.io.*;
045: import javax.swing.JButton;
046: import javax.swing.JToggleButton;
047: import org.netbeans.jemmy.*;
048: import org.netbeans.jemmy.operators.*;
049:
050: import org.netbeans.junit.NbTestSuite;
051: import org.netbeans.test.uml.diagramtoolbarbuttons.utils.DTBUtils;
052: import org.netbeans.test.umllib.DiagramOperator;
053: import org.netbeans.test.umllib.DiagramToolbarOperator;
054: import org.netbeans.test.umllib.NewDiagramWizardOperator;
055: import org.netbeans.test.umllib.testcases.UMLTestCase;
056:
057: /**
058: *
059: * @author yaa
060: * @spec UML/Diagram_ToolbarButtons.xml
061: */
062: public class DiagramToolbarButtons_COD extends UMLTestCase {
063: private static String prName = "UMLProjectDTlbBtn";
064: private static String codName = "DCollaboration";
065:
066: private static final String workDir = System
067: .getProperty("xtest.workdir");
068: private static String OUT_LOG_FILE = "";
069: private static String ERR_LOG_FILE = "";
070: private static PrintStream myOut = null;
071: private static PrintStream myErr = null;
072: private static BufferedReader myIn = null;
073:
074: /** Need to be defined because of JUnit */
075: public DiagramToolbarButtons_COD(String name) {
076: super (name);
077: }
078:
079: public static NbTestSuite suite() {
080: NbTestSuite suite = new NbTestSuite(
081: org.netbeans.test.uml.diagramtoolbarbuttons.DiagramToolbarButtons_COD.class);
082: return suite;
083: }
084:
085: public void testBtn_PrintPreviewDiagram() {
086: String btnTooltipName = DiagramToolbarOperator.PRINT_PREVIEW_DIAGRAM_TOOL;
087: JButton btn = diagram.toolbar().getButtonByTooltip(
088: btnTooltipName);
089: if (!btn.isEnabled()) {
090: fail("Diagram toolbar button '" + btnTooltipName
091: + "' is disabled but should not be");
092: }
093: new JButtonOperator(btn).pushNoBlock();
094: if (!DTBUtils
095: .findAndCloseDialog(DTBUtils.DialogTitles.PRINT_PREVIEW)) {
096: fail("Dialog with title '"
097: + DTBUtils.DialogTitles.PRINT_PREVIEW
098: + "' not found or not closed correctly");
099: }
100:
101: }
102:
103: /**
104: * @caseblock Collaboration Diagram
105: * @usecase Check toolbar buttons of collaboration diagram
106: */
107: public void testBtn_ExportAsImage() {
108: String btnTooltipName = DiagramToolbarOperator.EXPORT_AS_IMAGE_TOOL;
109: JButton btn = diagram.toolbar().getButtonByTooltip(
110: btnTooltipName);
111: if (!btn.isEnabled()) {
112: fail("Diagram toolbar button '" + btnTooltipName
113: + "' is disabled but should not be");
114: }
115: new JButtonOperator(btn).pushNoBlock();
116: if (!DTBUtils
117: .findAndCloseDialog(DTBUtils.DialogTitles.EXPORT_AS_IMAGE)) {
118: fail(6276927, "Dialog with title '"
119: + DTBUtils.DialogTitles.EXPORT_AS_IMAGE
120: + "' not found or not closed correctly");
121: }
122: }
123:
124: /**
125: * @caseblock Collaboration Diagram
126: * @usecase Check toolbar buttons of collaboration diagram
127: */
128: public void testBtn_Select() {
129: String btnTooltipName = DiagramToolbarOperator.SELECT_TOOL;
130: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
131: btnTooltipName);
132: if (!btn.isEnabled()) {
133: fail("Diagram toolbar button '" + btnTooltipName
134: + "' is disabled but should not be");
135: }
136: }
137:
138: /**
139: * @caseblock Collaboration Diagram
140: * @usecase Check toolbar buttons of collaboration diagram
141: */
142: public void testBtn_Pan() {
143: String btnTooltipName = DiagramToolbarOperator.PAN_TOOL;
144: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
145: btnTooltipName);
146: if (!btn.isEnabled()) {
147: fail("Diagram toolbar button '" + btnTooltipName
148: + "' is disabled but should not be");
149: }
150: }
151:
152: /**
153: * @caseblock Collaboration Diagram
154: * @usecase Check toolbar buttons of collaboration diagram
155: */
156: public void testBtn_ZoomWithMarquee() {
157: String btnTooltipName = DiagramToolbarOperator.ZOOM_WITH_MARQUEE_TOOL;
158: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
159: btnTooltipName);
160: if (!btn.isEnabled()) {
161: fail("Diagram toolbar button '" + btnTooltipName
162: + "' is disabled but should not be");
163: }
164: }
165:
166: /**
167: * @caseblock Collaboration Diagram
168: * @usecase Check toolbar buttons of collaboration diagram
169: */
170: public void testBtn_ZoomInteractively() {
171: String btnTooltipName = DiagramToolbarOperator.ZOOM_INTERACTIVELY_TOOL;
172: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
173: btnTooltipName);
174: if (!btn.isEnabled()) {
175: fail("Diagram toolbar button '" + btnTooltipName
176: + "' is disabled but should not be");
177: }
178: }
179:
180: /**
181: * @caseblock Collaboration Diagram
182: * @usecase Check toolbar buttons of collaboration diagram
183: */
184: public void testBtn_NavigateLink() {
185: String btnTooltipName = DiagramToolbarOperator.NAVIGATE_LINK_TOOL;
186: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
187: btnTooltipName);
188: if (!btn.isEnabled()) {
189: fail("Diagram toolbar button '" + btnTooltipName
190: + "' is disabled but should not be");
191: }
192: }
193:
194: /**
195: * @caseblock Collaboration Diagram
196: * @usecase Check toolbar buttons of collaboration diagram
197: */
198: public void testBtn_OverviewWindow() {
199: String btnTooltipName = DiagramToolbarOperator.OVERVIEW_WINDOW_TOOL;
200: JButton btn = diagram.toolbar().getButtonByTooltip(
201: btnTooltipName);
202: if (!btn.isEnabled()) {
203: fail("Diagram toolbar button '" + btnTooltipName
204: + "' is disabled but should not be");
205: }
206: new JButtonOperator(btn).pushNoBlock();
207: if (!DTBUtils
208: .findAndCloseDialog(DTBUtils.DialogTitles.OVERVIEW)) {
209: fail("Dialog with title '" + DTBUtils.DialogTitles.OVERVIEW
210: + "' not found or not closed correctly");
211: }
212: }
213:
214: /**
215: * @caseblock Collaboration Diagram
216: * @usecase Check toolbar buttons of collaboration diagram
217: */
218: public void testBtn_DiagramSynchronization() {
219: String btnTooltipName = DiagramToolbarOperator.DIAGRAM_SYNCHRONIZATION_TOOL;
220: JButton btn = diagram.toolbar().getButtonByTooltip(
221: btnTooltipName);
222: if (!btn.isEnabled()) {
223: fail("Diagram toolbar button '" + btnTooltipName
224: + "' is disabled but should not be");
225: }
226: }
227:
228: /*
229: public void testBtn_ShowFriendlyNames(){
230: String btnTooltipName = DiagramToolbarOperator.SHOW_FRIENDLY_NAMES_TOOL;
231: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(btnTooltipName);
232: if(!btn.isEnabled()){
233: fail("Diagram toolbar button '" + btnTooltipName + "' is disabled but should not be");
234: }
235: }
236: */
237:
238: /**
239: * @caseblock Collaboration Diagram
240: * @usecase Check toolbar buttons of collaboration diagram
241: */
242: public void testBtn_RelationshipDiscovery() {
243: String btnTooltipName = DiagramToolbarOperator.RELATIONSHIP_DISCOVERY_TOOL;
244: JButton btn = diagram.toolbar().getButtonByTooltip(
245: btnTooltipName);
246: if (!btn.isEnabled()) {
247: fail("Diagram toolbar button '" + btnTooltipName
248: + "' is disabled but should not be");
249: }
250: }
251:
252: /**
253: * @caseblock Collaboration Diagram
254: * @usecase Check toolbar buttons of collaboration diagram
255: */
256: public void testBtn_FitToWindow() {
257: String btnTooltipName = DiagramToolbarOperator.FIT_TO_WINDOW_TOOL;
258: JButton btn = diagram.toolbar().getButtonByTooltip(
259: btnTooltipName);
260: if (!btn.isEnabled()) {
261: fail("Diagram toolbar button '" + btnTooltipName
262: + "' is disabled but should not be");
263: }
264: }
265:
266: public void testBtn_ZoomComboBox() {
267: JComboBoxOperator cmbZoom = new JComboBoxOperator(diagram, 0);
268: JTextFieldOperator txt = new JTextFieldOperator(cmbZoom, 0);
269: JButtonOperator btnArrow = new JButtonOperator(cmbZoom, 0);
270:
271: btnArrow.pushNoBlock();
272: try {
273: Thread.sleep(2000);
274: } catch (InterruptedException ex) {
275: ex.printStackTrace();
276: }
277: btnArrow.pushNoBlock();
278: try {
279: Thread.sleep(2000);
280: } catch (InterruptedException ex) {
281: ex.printStackTrace();
282: }
283: }
284:
285: /**
286: * @caseblock Collaboration Diagram
287: * @usecase Check toolbar buttons of collaboration diagram
288: */
289: public void testBtn_ZoomIn() {
290: String btnTooltipName = DiagramToolbarOperator.ZOOM_IN_TOOL;
291: JButton btn = diagram.toolbar().getButtonByTooltip(
292: btnTooltipName);
293: if (!btn.isEnabled()) {
294: fail("Diagram toolbar button '" + btnTooltipName
295: + "' is disabled but should not be");
296: }
297: }
298:
299: /**
300: * @caseblock Collaboration Diagram
301: * @usecase Check toolbar buttons of collaboration diagram
302: */
303: public void testBtn_ZoomOut() {
304: String btnTooltipName = DiagramToolbarOperator.ZOOM_OUT_TOOL;
305: JButton btn = diagram.toolbar().getButtonByTooltip(
306: btnTooltipName);
307: if (!btn.isEnabled()) {
308: fail("Diagram toolbar button '" + btnTooltipName
309: + "' is disabled but should not be");
310: }
311: }
312:
313: /**
314: * @caseblock Collaboration Diagram
315: * @usecase Check toolbar buttons of collaboration diagram
316: */
317: public void testBtn_MoveForward() {
318: String btnTooltipName = DiagramToolbarOperator.MOVE_FORWARD_TOOL;
319: JButton btn = diagram.toolbar().getButtonByTooltip(
320: btnTooltipName);
321: if (!btn.isEnabled()) {
322: fail("Diagram toolbar button '" + btnTooltipName
323: + "' is disabled but should not be");
324: }
325: }
326:
327: /**
328: * @caseblock Collaboration Diagram
329: * @usecase Check toolbar buttons of collaboration diagram
330: */
331: public void testBtn_MoveToFront() {
332: String btnTooltipName = DiagramToolbarOperator.MOVE_TO_FRONT_TOOL;
333: JButton btn = diagram.toolbar().getButtonByTooltip(
334: btnTooltipName);
335: if (!btn.isEnabled()) {
336: fail("Diagram toolbar button '" + btnTooltipName
337: + "' is disabled but should not be");
338: }
339: }
340:
341: /**
342: * @caseblock Collaboration Diagram
343: * @usecase Check toolbar buttons of collaboration diagram
344: */
345: public void testBtn_MoveBackward() {
346: String btnTooltipName = DiagramToolbarOperator.MOVE_BACKWARD_TOOL;
347: JButton btn = diagram.toolbar().getButtonByTooltip(
348: btnTooltipName);
349: if (!btn.isEnabled()) {
350: fail("Diagram toolbar button '" + btnTooltipName
351: + "' is disabled but should not be");
352: }
353: }
354:
355: /**
356: * @caseblock Collaboration Diagram
357: * @usecase Check toolbar buttons of collaboration diagram
358: */
359: public void testBtn_MoveToBack() {
360: String btnTooltipName = DiagramToolbarOperator.MOVE_TO_BACK_TOOL;
361: JButton btn = diagram.toolbar().getButtonByTooltip(
362: btnTooltipName);
363: if (!btn.isEnabled()) {
364: fail("Diagram toolbar button '" + btnTooltipName
365: + "' is disabled but should not be");
366: }
367: }
368:
369: /**
370: * @caseblock Collaboration Diagram
371: * @usecase Check toolbar buttons of collaboration diagram
372: */
373: public void testBtn_HierarchicalLayout() {
374: String btnTooltipName = DiagramToolbarOperator.HIERARCHICAL_LAYOUT_TOOL;
375: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
376: btnTooltipName);
377: if (!btn.isEnabled()) {
378: fail("Diagram toolbar button '" + btnTooltipName
379: + "' is disabled but should not be");
380: }
381: }
382:
383: /**
384: * @caseblock Collaboration Diagram
385: * @usecase Check toolbar buttons of collaboration diagram
386: */
387: public void testBtn_OrthogonalLayout() {
388: String btnTooltipName = DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL;
389: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
390: btnTooltipName);
391: if (!btn.isEnabled()) {
392: fail("Diagram toolbar button '" + btnTooltipName
393: + "' is disabled but should not be");
394: }
395: }
396:
397: /**
398: * @caseblock Collaboration Diagram
399: * @usecase Check toolbar buttons of collaboration diagram
400: */
401: public void testBtn_SymmetricLayout() {
402: String btnTooltipName = DiagramToolbarOperator.SYMMETRIC_LAYOUT_TOOL;
403: JToggleButton btn = diagram.toolbar().getToggleButtonByTooltip(
404: btnTooltipName);
405: if (!btn.isEnabled()) {
406: fail("Diagram toolbar button '" + btnTooltipName
407: + "' is disabled but should not be");
408: }
409: }
410:
411: /**
412: * @caseblock Collaboration Diagram
413: * @usecase Check toolbar buttons of collaboration diagram
414: */
415: public void testBtn_SequenceLayout() {
416: String btnTooltipName = DiagramToolbarOperator.SEQUENCE_LAYOUT_TOOL;
417: try {
418: diagram.toolbar().getButtonByTooltip(btnTooltipName);
419: fail("unexpected " + btnTooltipName
420: + " on collaboration diagram.");
421: } catch (Exception ex) {
422: //good
423: }
424: }
425:
426: /**
427: * @caseblock Collaboration Diagram
428: * @usecase Check toolbar buttons of collaboration diagram
429: */
430: public void testBtn_IncrementalLayout() {
431: String btnTooltipName = DiagramToolbarOperator.INCREMENTAL_LAYOUT_TOOL;
432: JButton btn = diagram.toolbar().getButtonByTooltip(
433: btnTooltipName);
434: if (!btn.isEnabled()) {
435: fail("Diagram toolbar button '" + btnTooltipName
436: + "' is disabled but should not be");
437: }
438: }
439:
440: /**
441: * @caseblock Collaboration Diagram
442: * @usecase Check toolbar buttons of collaboration diagram
443: */
444: public void testCBox_Zoom() {
445: JComboBoxOperator cbox = new JComboBoxOperator(diagram);
446: if (cbox == null) {
447: fail("Diagram toolbar ComboBox 'Zoom' not found");
448: } else if (!cbox.isEnabled()) {
449: fail("Diagram toolbar ComboBox 'Zoom' is disabled but should not be");
450: }
451: }
452:
453: /**
454: * @caseblock Collaboration Diagram
455: * @usecase Check toolbar buttons of collaboration diagram
456: */
457: public void testCheckUnnecessaryItems() {
458: String[] buttonsNecessary = new String[] {
459: DiagramToolbarOperator.PRINT_PREVIEW_DIAGRAM_TOOL,
460: DiagramToolbarOperator.EXPORT_AS_IMAGE_TOOL,
461: DiagramToolbarOperator.SELECT_TOOL,
462: DiagramToolbarOperator.PAN_TOOL,
463: DiagramToolbarOperator.ZOOM_WITH_MARQUEE_TOOL,
464: DiagramToolbarOperator.ZOOM_INTERACTIVELY_TOOL,
465: DiagramToolbarOperator.NAVIGATE_LINK_TOOL,
466: DiagramToolbarOperator.OVERVIEW_WINDOW_TOOL,
467: DiagramToolbarOperator.DIAGRAM_SYNCHRONIZATION_TOOL,
468: // DiagramToolbarOperator.SHOW_FRIENDLY_NAMES_TOOL,
469: DiagramToolbarOperator.RELATIONSHIP_DISCOVERY_TOOL,
470: DiagramToolbarOperator.FIT_TO_WINDOW_TOOL,
471: DiagramToolbarOperator.ZOOM_IN_TOOL,
472: DiagramToolbarOperator.ZOOM_OUT_TOOL,
473: DiagramToolbarOperator.MOVE_FORWARD_TOOL,
474: DiagramToolbarOperator.MOVE_TO_FRONT_TOOL,
475: DiagramToolbarOperator.MOVE_BACKWARD_TOOL,
476: DiagramToolbarOperator.MOVE_TO_BACK_TOOL,
477: DiagramToolbarOperator.HIERARCHICAL_LAYOUT_TOOL,
478: DiagramToolbarOperator.ORTHOGONAL_LAYOUT_TOOL,
479: DiagramToolbarOperator.SYMMETRIC_LAYOUT_TOOL,
480: DiagramToolbarOperator.SEQUENCE_LAYOUT_TOOL,
481: DiagramToolbarOperator.INCREMENTAL_LAYOUT_TOOL };
482:
483: boolean result = DTBUtils.checkUnnecessaryButtons(diagram,
484: buttonsNecessary, getLog());
485: if (!result) {
486: fail("Diagram toolbar contains unnecessary buttons (see log)");
487: }
488: }
489:
490: //------------------------------------------------------------------------------
491:
492: public void setUp() throws FileNotFoundException {
493: System.out.println("######## " + getName() + " #######");
494: JemmyProperties.setCurrentTimeout(
495: "DialogWaiter.WaitDialogTimeout", 1000);
496: JemmyProperties.setCurrentTimeout("Waiter.WaitingTime", 1000);
497: JemmyProperties.setCurrentTimeout(
498: "JMenuOperator.WaitPopupTimeout", 2000);
499: JemmyProperties.setCurrentTimeout(
500: "ComponentOperator.WaitComponentTimeout", 2000);
501: JemmyProperties.setCurrentTimeout(
502: "WindowWaiter.WaitWindowTimeout", 2000);
503:
504: OUT_LOG_FILE = workDir + File.separator + "jout_" + getName()
505: + ".log";
506: ERR_LOG_FILE = workDir + File.separator + "jerr_" + getName()
507: + ".log";
508:
509: myOut = new PrintStream(new FileOutputStream(OUT_LOG_FILE),
510: true);
511: myErr = new PrintStream(new FileOutputStream(ERR_LOG_FILE),
512: true);
513: JemmyProperties.setCurrentOutput(new TestOut(System.in, myOut,
514: myErr));
515:
516: diagram = DTBUtils
517: .openDiagram(prName, codName,
518: NewDiagramWizardOperator.COLLABORATION_DIAGRAM,
519: workDir);
520: if (diagram == null) {
521: fail("Can't open diagram '" + codName + "', project '"
522: + prName + "'.");
523: }
524: }
525:
526: public void tearDown() throws FileNotFoundException, IOException,
527: InterruptedException {
528: org.netbeans.test.umllib.util.Utils.tearDown();
529: try {
530: JDialogOperator dlgError = new JDialogOperator(
531: "Unexpected Exception");
532: JTextAreaOperator textarea = new JTextAreaOperator(dlgError);
533: String str = textarea.getDisplayedText();
534: int pos = str.indexOf("\n");
535: if (pos != -1) {
536: str = str.substring(1, pos - 1);
537: }
538: dlgError.close();
539: fail(" " + str);
540: } catch (TimeoutExpiredException e) {
541: }
542:
543: myIn = new BufferedReader(new FileReader(ERR_LOG_FILE));
544: String line;
545: do {
546: line = myIn.readLine();
547: if (line != null && line.indexOf("Exception") != -1) {
548: if ((line.indexOf("Unexpected Exception") == -1)
549: && (line.indexOf("TimeoutExpiredException") == -1)) {
550: //fail(line);
551: }
552: }
553: } while (line != null);
554: }
555:
556: private DiagramOperator diagram = null;
557: }
|