KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > javahelp > JavaHelpDialogTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package gui.javahelp;
21
22 import org.netbeans.jellytools.JellyTestCase;
23 import org.netbeans.jellytools.HelpOperator;
24 import org.netbeans.jellytools.MainWindowOperator;
25 import org.netbeans.jellytools.NbDialogOperator;
26 import org.netbeans.jellytools.OptionsOperator;
27 import org.netbeans.jellytools.actions.HelpAction;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29
30 import org.netbeans.jemmy.operators.JMenuBarOperator;
31 import org.netbeans.jemmy.operators.JTreeOperator;
32
33 import org.netbeans.junit.NbTestSuite;
34
35 /**
36  * JellyTestCase test case with implemented Java Help Test support stuff
37  *
38  * @author mmirilovic@netbeans.org
39  */

40 public class JavaHelpDialogTest extends JellyTestCase {
41     
42     private HelpOperator helpWindow;
43     
44     /** Creates a new instance of JavaHelpDialogTest */
45     public JavaHelpDialogTest(String JavaDoc testName) {
46         super(testName);
47     }
48     
49     
50     public static NbTestSuite suite() {
51         NbTestSuite suite = new NbTestSuite();
52         suite.addTest(new JavaHelpDialogTest("testHelpF1"));
53         suite.addTest(new JavaHelpDialogTest("testHelpFromMenu"));
54         suite.addTest(new JavaHelpDialogTest("testHelpByButtonNonModal"));
55         suite.addTest(new JavaHelpDialogTest("testHelpByButtonModal"));
56         suite.addTest(new JavaHelpDialogTest("testSearchInIndex"));
57         suite.addTest(new JavaHelpDialogTest("testContextualSearch"));
58         suite.addTest(new JavaHelpDialogTest("testHelpByButtonNestedModal"));
59         return suite;
60     }
61     
62     public void setUp() {
63     }
64     
65     public void tearDown(){
66         closeAllModal();
67         
68         if(helpWindow != null && helpWindow.isVisible())
69             helpWindow.close();
70         
71         helpWindow = null;
72     }
73     
74     public void testHelpF1(){
75         MainWindowOperator.getDefault().pressKey(java.awt.event.KeyEvent.VK_F1);
76         new org.netbeans.jemmy.EventTool().waitNoEvent(7000);
77         helpWindow = new HelpOperator();
78     }
79     
80     public void testHelpFromMenu(){
81         new HelpAction().performMenu();
82         helpWindow = new HelpOperator();
83     }
84     
85     public void testHelpCoreFromMenu(){
86         String JavaDoc helpMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Help"); // Help
87
String JavaDoc helpSetsMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.javahelp.resources.Bundle", "Menu/Help/HelpShortcuts"); // Help Sets
88
String JavaDoc coreIDEHelpMenu = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.usersguide.Bundle", "Actions/Help/org-netbeans-modules-usersguide-mainpage.xml"); // Core IDE Help
89

90         MainWindowOperator.getDefault().menuBar().pushMenu( helpMenu+"|"+helpSetsMenu+"|"+coreIDEHelpMenu, "|");
91         helpWindow = new HelpOperator();
92     }
93     
94     public void testHelpByButtonNonModal(){
95         OptionsOperator.invoke(); //new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()).pushMenuNoBlock("Tools|Options","|"); // NOI18N
96
OptionsOperator options = new OptionsOperator();
97         options.help();
98         helpWindow = new HelpOperator();
99         options.close();
100     }
101     
102     public void testHelpByButtonModal(){
103         String JavaDoc toolsMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // Tools
104
//String setupWizardMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.actions.Bundle", "LBL_SetupWizard"); // Setup Wizard
105
String JavaDoc javaPlatformMenu = "Java Platform Manager";
106         
107         new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()).pushMenuNoBlock(toolsMenu+"|"+javaPlatformMenu,"|");
108         //new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.ui.Bundle", "CTL_SetupWizardTitle")).help(); // Setup Wizard
109
new NbDialogOperator("Java Platform Manager").help(); // Java Platform Manager
110
helpWindow = new HelpOperator();
111     }
112     
113     public void testHelpByButtonNestedModal(){
114         String JavaDoc toolsMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // Tools
115
//String setupWizardMenu = org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.actions.Bundle", "LBL_SetupWizard"); // Setup Wizard
116
String JavaDoc javaPlatformMenu = "Java Platform Manager";
117         
118         new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()).pushMenuNoBlock(toolsMenu+"|"+javaPlatformMenu,"|");
119         //new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.core.ui.Bundle", "CTL_SetupWizardTitle")).help(); // Setup Wizard
120
NbDialogOperator javaPlatformManager = new NbDialogOperator("Java Platform Manager");// Java Platform Manager
121

122         new JButtonOperator(javaPlatformManager, "Add Platform...").pushNoBlock();
123         NbDialogOperator addJavaPlatform = new NbDialogOperator("Add Java Platform");// Add Java Platform dialog
124
addJavaPlatform.help();
125         helpWindow = new HelpOperator();
126         
127         // close
128
addJavaPlatform.cancel();
129         javaPlatformManager.closeByButton();
130     }
131     
132     public void testSearchInIndex(){
133         new HelpAction().perform();
134         helpWindow = new HelpOperator();
135         helpWindow.selectPageIndex();
136         helpWindow.indexFind("compile");
137         try{
138             Thread.sleep(5000);
139         }catch(Exception JavaDoc exc){
140             exc.printStackTrace(getLog());
141         }
142         
143         JTreeOperator tree = helpWindow.treeIndex();
144         log("Selection path="+tree.getSelectionPath());
145         log("Selection count="+tree.getSelectionCount());
146         
147         if(tree.getSelectionCount()<1)
148             fail("None founded text in the help, it isn't obvious");
149     }
150     
151     public void testContextualSearch(){
152         new HelpAction().perform();
153         helpWindow = new HelpOperator();
154         helpWindow.selectPageSearch();
155         helpWindow.searchFind("compile");
156         
157         try{
158             Thread.sleep(5000);
159         }catch(Exception JavaDoc exc){
160             exc.printStackTrace(getLog());
161         }
162         
163         
164         JTreeOperator tree = helpWindow.treeSearch();
165         log("Selection path="+tree.getSelectionPath());
166         log("Selection count="+tree.getSelectionCount());
167         
168         if(tree.getSelectionCount()<1)
169             fail("None founded text in the help, it isn't obvious");
170     }
171     
172     
173     /** Test could be executed internaly in Forte without XTest
174      * @param args arguments from command line
175      */

176     public static void main(String JavaDoc[] args) {
177         junit.textui.TestRunner.run(suite());
178     }
179 }
180
Popular Tags