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-2006 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.jellytools;
043:
044: import java.awt.Toolkit;
045: import java.awt.datatransfer.DataFlavor;
046: import java.awt.datatransfer.Transferable;
047: import org.netbeans.jellytools.actions.DebugProjectAction;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jemmy.EventTool;
050: import org.netbeans.jemmy.Waitable;
051: import org.netbeans.jemmy.Waiter;
052: import org.netbeans.jemmy.operators.JButtonOperator;
053: import org.netbeans.jemmy.operators.JTextFieldOperator;
054: import org.netbeans.junit.NbTest;
055: import org.netbeans.junit.NbTestSuite;
056:
057: /**
058: * Test of OutputOperator.
059: *
060: * @author Jiri.Skrivanek@sun.com
061: */
062: public class OutputOperatorTest extends JellyTestCase {
063:
064: public OutputOperatorTest(java.lang.String testName) {
065: super (testName);
066: }
067:
068: public static void main(java.lang.String[] args) {
069: junit.textui.TestRunner.run(suite());
070: }
071:
072: public static NbTest suite() {
073: NbTestSuite suite = new NbTestSuite();
074: // suites have to be in particular order
075: suite.addTest(new OutputOperatorTest("testInvoke"));
076: suite.addTest(new OutputOperatorTest("testGetOutputTab"));
077: suite.addTest(new OutputOperatorTest("testGetText"));
078: suite.addTest(new OutputOperatorTest("testSelectAll"));
079: suite.addTest(new OutputOperatorTest("testCopy"));
080: suite.addTest(new OutputOperatorTest("testFind"));
081: suite.addTest(new OutputOperatorTest("testFindNext"));
082: // TODO
083: //suite.addTest(new OutputOperatorTest("testNextError"));
084: // TODO
085: //suite.addTest(new OutputOperatorTest("testPreviousError"));
086: suite.addTest(new OutputOperatorTest("testWrapText"));
087: suite.addTest(new OutputOperatorTest("testSaveAs"));
088: suite.addTest(new OutputOperatorTest("testClear"));
089: suite.addTest(new OutputOperatorTest("testVerify"));
090: return suite;
091: }
092:
093: /** Print out test name. */
094: public void setUp() {
095: System.out.println("### " + getName() + " ###");
096: }
097:
098: // OutputOperator instance used in tests
099: private static OutputOperator outputOperator;
100: private static final String OUTPUT_TITLE = "SampleProject (debug)";
101:
102: /**
103: * Test of invoke method
104: */
105: public void testInvoke() {
106: OutputOperator.invoke().close();
107: // be sure it is opened
108: outputOperator = OutputOperator.invoke();
109: }
110:
111: /**
112: * Test of getOutputTab method
113: */
114: public void testGetOutputTab() {
115: // setup - open output tab
116: Node sampleProjectNode = ProjectsTabOperator.invoke()
117: .getProjectRootNode("SampleProject");
118: new DebugProjectAction().perform(sampleProjectNode);
119: // increase time to wait
120: outputOperator.getTimeouts().setTimeout(
121: "ComponentOperator.WaitStateTimeout", 60000);
122: // wait for finish of debugging
123: outputOperator.getOutputTab(OUTPUT_TITLE)
124: .waitText("total time");
125:
126: OutputTabOperator oto = outputOperator
127: .getOutputTab(OUTPUT_TITLE);
128: assertTrue("Wrong OutputTabOperator found.", oto.getName()
129: .indexOf(OUTPUT_TITLE) > -1);
130: }
131:
132: /**
133: * Test of getText method
134: */
135: public void testGetText() {
136: String text = outputOperator.getText();
137: assertTrue("Text is not from debugger term.", text
138: .indexOf("debug") > -1); //NOI18N
139: }
140:
141: /**
142: * Test of selectAll method
143: */
144: public void testSelectAll() {
145: startTest();
146: outputOperator.getOutputTab(OUTPUT_TITLE);
147: outputOperator.selectAll();
148: endTest();
149: }
150:
151: /**
152: * Test of copy method
153: */
154: public void testCopy() throws Exception {
155: startTest();
156: clearTestStatus();
157: outputOperator.copy();
158: assertTrue("Copy doesn't work.", getClipboardText().indexOf(
159: "debug") > -1); // NOI18N
160: }
161:
162: /**
163: * Test of find method
164: */
165: public void testFind() throws Exception {
166: outputOperator.find();
167: // "Find"
168: String findTitle = Bundle.getString(
169: "org.netbeans.core.output2.Bundle", "LBL_Find_Title");
170: NbDialogOperator findDialog = new NbDialogOperator(findTitle);
171: // assuming debug string is printed in output at least twice
172: new JTextFieldOperator(findDialog).setText("b"); // NOI18N
173: // "Find"
174: String findButtonLabel = Bundle.getStringTrimmed(
175: "org.netbeans.core.output2.Bundle", "BTN_Find");
176: new JButtonOperator(findDialog, findButtonLabel).push();
177: // wait a little until "b" is selected
178: new EventTool().waitNoEvent(500);
179: // verify "b" is selected
180: outputOperator.copy();
181: if (!getClipboardText().equals("b")) {
182: // repeat because find action was not executed
183: outputOperator.find();
184: findDialog = new NbDialogOperator(findTitle);
185: new JTextFieldOperator(findDialog).setText("b"); // NOI18N
186: new JButtonOperator(findDialog, findButtonLabel).push();
187: }
188: }
189:
190: /**
191: * Test of findNext method
192: */
193: public void testFindNext() {
194: outputOperator.findNext();
195: }
196:
197: /** Test of nextError method. */
198: public void testNextError() {
199: // TODO add test some day
200: //outputOperator.nextError();
201: }
202:
203: /** Test of previousError method. */
204: public void testPreviousError() {
205: // TODO add test some day
206: //outputOperator.previousError();
207: }
208:
209: /** Test of wrapText method. */
210: public void testWrapText() {
211: // set
212: outputOperator.wrapText();
213: // unset
214: outputOperator.wrapText();
215: }
216:
217: /**
218: * Test of saveAs method.
219: */
220: public void testSaveAs() {
221: outputOperator.saveAs();
222: // "Save As"
223: String saveAsTitle = Bundle.getString(
224: "org.netbeans.core.output2.Bundle", "TITLE_SAVE_DLG");
225: new NbDialogOperator(saveAsTitle).close();
226: }
227:
228: /** Test of clear method. */
229: public void testClear() {
230: outputOperator.clear();
231: assertTrue("Text was not cleared.", outputOperator.getText()
232: .length() == 0);
233: }
234:
235: /**
236: * Test of verify method
237: */
238: public void testVerify() {
239: // currently does nothing
240: outputOperator.verify();
241: }
242:
243: /** Wait until clipboard contains string data and returns the text. */
244: private String getClipboardText() throws Exception {
245: Waiter waiter = new Waiter(new Waitable() {
246: public Object actionProduced(Object obj) {
247: Transferable contents = Toolkit.getDefaultToolkit()
248: .getSystemClipboard().getContents(null);
249: if (contents == null) {
250: return null;
251: } else {
252: return contents
253: .isDataFlavorSupported(DataFlavor.stringFlavor) ? Boolean.TRUE
254: : null;
255: }
256: }
257:
258: public String getDescription() {
259: return ("Wait clipboard contains string data");
260: }
261: });
262: waiter.waitAction(null);
263: return Toolkit.getDefaultToolkit().getSystemClipboard()
264: .getContents(null).getTransferData(
265: DataFlavor.stringFlavor).toString();
266: }
267: }
|