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.jellytools;
043:
044: import java.awt.event.KeyEvent;
045: import junit.framework.Test;
046: import junit.framework.TestSuite;
047: import junit.textui.TestRunner;
048: import org.netbeans.jemmy.EventTool;
049: import org.netbeans.jemmy.JemmyProperties;
050: import org.netbeans.jemmy.Waitable;
051: import org.netbeans.jemmy.Waiter;
052: import org.netbeans.junit.NbTestSuite;
053:
054: /** Test of HelpOperator.
055: *
056: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a>
057: * @author Jiri.Skrivanek@sun.com
058: */
059: public class HelpOperatorTest extends JellyTestCase {
060:
061: /** constructor required by JUnit
062: * @param testName method name to be used as testcase
063: */
064: public HelpOperatorTest(String testName) {
065: super (testName);
066: }
067:
068: /** method used for explicit testsuite definition
069: */
070: public static Test suite() {
071: TestSuite suite = new NbTestSuite();
072: suite.addTest(new HelpOperatorTest("testInvoke"));
073: suite.addTest(new HelpOperatorTest("testContentsSelection"));
074: suite.addTest(new HelpOperatorTest("testSearchFind"));
075: suite.addTest(new HelpOperatorTest("testPreviousAndNext"));
076: suite.addTest(new HelpOperatorTest("testPrint"));
077: suite.addTest(new HelpOperatorTest("testPageSetup"));
078: suite.addTest(new HelpOperatorTest("testClose"));
079: return suite;
080: }
081:
082: /** Print out test name. */
083: @Override
084: public void setUp() {
085: System.out.println("### " + getName() + " ###");
086: // find help window if not found before
087: if (help == null && !getName().equals("testInvoke")) {
088: help = new HelpOperator();
089: }
090: }
091:
092: /** method called after each testcase
093: */
094: @Override
095: protected void tearDown() {
096: }
097:
098: /** Use for internal test execution inside IDE
099: * @param args command line arguments
100: */
101: public static void main(java.lang.String[] args) {
102: TestRunner.run(suite());
103: }
104:
105: private static HelpOperator help;
106:
107: /** Test invoke */
108: public void testInvoke() {
109: // push Escape key to close potentially open popup menu from previous execution
110: MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE);
111: long oldTimeout = JemmyProperties
112: .getCurrentTimeout("JMenuOperator.PushMenuTimeout");
113: // increase time to open help window
114: JemmyProperties.setCurrentTimeout(
115: "JMenuOperator.PushMenuTimeout", 60000);
116: try {
117: help = HelpOperator.invoke();
118: } finally {
119: // reset timeout
120: JemmyProperties.setCurrentTimeout(
121: "JMenuOperator.PushMenuTimeout", oldTimeout);
122: }
123: }
124:
125: /** simple test case
126: */
127: public void testContentsSelection() {
128: String text = help.getContentText();
129: help.treeContents().selectRow(0);
130: new EventTool().waitNoEvent(500);
131: assertTrue(!text.equals(help.getContentText()));
132: }
133:
134: /** simple test case
135: */
136: public void testSearchFind() {
137: help.searchFind("help");
138: new EventTool().waitNoEvent(500);
139: String text = help.getContentText();
140: help.searchFind("menu");
141: new EventTool().waitNoEvent(500);
142: assertTrue(!text.equals(help.getContentText()));
143: }
144:
145: /** simple test case
146: */
147: public void testPreviousAndNext() throws InterruptedException {
148: final String text = help.getContentText();
149: help.back();
150: new Waiter(new Waitable() {
151: public Object actionProduced(Object oper) {
152: return text.equals(help.getContentText()) ? null
153: : Boolean.TRUE;
154: }
155:
156: public String getDescription() {
157: return ("Text after back not equal to previous text"); // NOI18N
158: }
159: }).waitAction(null);
160: help.next();
161: new Waiter(new Waitable() {
162: public Object actionProduced(Object oper) {
163: return text.equals(help.getContentText()) ? Boolean.TRUE
164: : null;
165: }
166:
167: public String getDescription() {
168: return ("Text after next equal to previous text"); // NOI18N
169: }
170: }).waitAction(null);
171: }
172:
173: /** Test btPrint() method. */
174: public void testPrint() {
175: String tooltip = help.btPrint().getToolTipText();
176: if (!tooltip.equals("Print") && !tooltip.equals("Tisk")) {
177: fail("btPrint() returned wrong button: " + tooltip);
178: }
179: }
180:
181: /** Test btPageSetup() method. */
182: public void testPageSetup() {
183: String tooltip = help.btPageSetup().getToolTipText();
184: if (!tooltip.equals("Page Setup")
185: && !tooltip.startsWith("Nastaven")) { // "Nastavenà stránky"
186: fail("btPageSetup() returned wrong button: " + tooltip);
187: }
188: }
189:
190: /** Test close() method. */
191: public void testClose() {
192: help.close();
193: }
194:
195: }
|