Source Code Cross Referenced for MainWindowOperatorTest.java in  » IDE-Netbeans » jellytools » org » netbeans » jellytools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » jellytools » org.netbeans.jellytools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        package org.netbeans.jellytools;
042:
043:        import java.awt.Component;
044:        import java.io.ByteArrayOutputStream;
045:        import java.io.PrintStream;
046:        import java.util.ArrayList;
047:        import junit.textui.TestRunner;
048:        import org.netbeans.jemmy.ComponentChooser;
049:
050:        import org.netbeans.jemmy.EventTool;
051:        import org.netbeans.jemmy.JemmyException;
052:        import org.netbeans.jemmy.JemmyProperties;
053:        import org.netbeans.jemmy.operators.ContainerOperator;
054:
055:        import org.netbeans.junit.NbTestSuite;
056:        import org.openide.awt.StatusDisplayer;
057:        import org.openide.awt.Toolbar;
058:
059:        /**
060:         * Test of org.netbeans.jellytools.MainWindowOperator.
061:         */
062:        public class MainWindowOperatorTest extends JellyTestCase {
063:
064:            /** Instance of MainWindowOperator (singleton) to test. */
065:            private MainWindowOperator mainWindowOper;
066:
067:            /** constructor required by JUnit
068:             * @param testName method name to be used as testcase
069:             */
070:            public MainWindowOperatorTest(String testName) {
071:                super (testName);
072:            }
073:
074:            /** method used for explicit testsuite definition
075:             * @return Test suite.
076:             */
077:            public static NbTestSuite suite() {
078:                NbTestSuite suite = new NbTestSuite(
079:                        MainWindowOperatorTest.class);
080:                return suite;
081:            }
082:
083:            /** Redirect output to log files, wait before each test case and
084:             * show dialog to test. */
085:            @Override
086:            protected void setUp() {
087:                System.out.println("### " + getName() + " ###");
088:                mainWindowOper = MainWindowOperator.getDefault();
089:            }
090:
091:            /** Tear down after test case. */
092:            @Override
093:            protected void tearDown() {
094:            }
095:
096:            /** Use for internal test execution inside IDE
097:             * @param args command line arguments
098:             */
099:            public static void main(java.lang.String[] args) {
100:                TestRunner.run(suite());
101:            }
102:
103:            /** Test of getDefault() method. */
104:            public void testGetDefault() {
105:                MainWindowOperator.getDefault();
106:            }
107:
108:            /** Test of testMenuBar method. */
109:            public void testMenuBar() {
110:                MainWindowOperator mwo = MainWindowOperator.getDefault();
111:                mwo.menuBar();
112:            }
113:
114:            /** Test of getStatusText method. */
115:            public void testGetSetStatusText() {
116:                String expectedText = "Hello World!!!";
117:                mainWindowOper.setStatusText(expectedText);
118:                String text = mainWindowOper.getStatusText();
119:                assertEquals("Wrong status text.", expectedText, text);
120:            }
121:
122:            /** Test of waitStatusText method. */
123:            public void testWaitStatusText() {
124:                String expectedText = "Hello World!!!";
125:                StatusDisplayer.getDefault().setStatusText(expectedText);
126:                mainWindowOper.waitStatusText(expectedText);
127:            }
128:
129:            /***************** methods for toolbars manipulation *******************/
130:
131:            /** Test of getToolbar(int) method. */
132:            public void testGetToolbarInt() {
133:                mainWindowOper.getToolbar(0);
134:            }
135:
136:            /** Test of getToolbar(String) method. */
137:            public void testGetToolbarString() {
138:                mainWindowOper.getToolbar("Build"); // NOI18N
139:            }
140:
141:            /** Test of getToolbarCount method. */
142:            public void testGetToolbarCount() {
143:                assertEquals("Wrong toolbar count.", 4, mainWindowOper
144:                        .getToolbarCount());
145:            }
146:
147:            /** Test of getToolbarName method. */
148:            public void testGetToolbarName() {
149:                String toolbarName = mainWindowOper.getToolbarName(0);
150:                String expected = ((Toolbar) mainWindowOper.getToolbar(0)
151:                        .getSource()).getDisplayName();
152:                assertEquals("Wrong toolbar name", expected, toolbarName);
153:            }
154:
155:            /** Test of getToolbarButton method. Finds Build toolbar and checks if
156:             * getToolbarButton(1) returns Build Main Project button. */
157:            public void testGetToolbarButtonInt() {
158:                ContainerOperator toolbarOper = mainWindowOper
159:                        .getToolbar("Build"); // NOI18N
160:                String tooltip = mainWindowOper
161:                        .getToolbarButton(toolbarOper, 1).getToolTipText();
162:                String expected = Bundle.getStringTrimmed(
163:                        "org.netbeans.modules.project.ui.actions.Bundle",
164:                        "LBL_BuildMainProjectAction_Name");
165:                assertTrue("Wrong toolbar button.",
166:                        tooltip.indexOf(expected) != -1);
167:            }
168:
169:            /** Test of getToolbarButton method. Finds Build toolbar and checks if
170:             * getToolbarButton() finds Build All button. */
171:            public void testGetToolbarButtonString() {
172:                ContainerOperator toolbarOper = mainWindowOper
173:                        .getToolbar("Build"); // NOI18N
174:                String buildMainProject = Bundle.getStringTrimmed(
175:                        "org.netbeans.modules.project.ui.actions.Bundle",
176:                        "LBL_BuildMainProjectAction_Name");
177:                mainWindowOper.getToolbarButton(toolbarOper, buildMainProject);
178:            }
179:
180:            /** Test of pushToolbarPopupMenu method. Pushes popup menu Edit
181:             * checks whether toolbar Edit dismissed and push again to enable it. */
182:            public void testPushToolbarPopupMenu() {
183:                int expectedToolbarsCount = mainWindowOper.getToolbarCount();
184:                // "File"
185:                String popupPath = Bundle.getStringTrimmed(
186:                        "org.netbeans.core.Bundle", "Toolbars/File");
187:                mainWindowOper.pushToolbarPopupMenu(popupPath);
188:                int actualToolbarCount = mainWindowOper.getToolbarCount();
189:                mainWindowOper.pushToolbarPopupMenu(popupPath);
190:                assertEquals(
191:                        "Toolbar popup menu not pushed. Toolbars count should differ:",
192:                        expectedToolbarsCount, actualToolbarCount + 1);
193:            }
194:
195:            /** Test of pushToolbarPopupMenuNoBlock method.  */
196:            public void testPushToolbarPopupMenuNoBlock() {
197:                // at the time no item in menu is blocking so we use testPushToolbarPopupMenu
198:                int expectedToolbarsCount = mainWindowOper.getToolbarCount();
199:                // "File"
200:                String popupPath = Bundle.getStringTrimmed(
201:                        "org.netbeans.core.Bundle", "Toolbars/File");
202:                mainWindowOper.pushToolbarPopupMenuNoBlock(popupPath);
203:                new EventTool().waitNoEvent(500);
204:                int actualToolbarCount = mainWindowOper.getToolbarCount();
205:                mainWindowOper.pushToolbarPopupMenu(popupPath);
206:                assertEquals(
207:                        "Toolbar popup menu not pushed. Toolbars count should differ:",
208:                        expectedToolbarsCount, actualToolbarCount + 1);
209:            }
210:
211:            /** Test of dragNDropToolbar method. Tries to move toolbar down and checks
212:             * whether main window is enlarged. */
213:            public void testDragNDropToolbar() {
214:                // need toolbar container to check drag and drop operation
215:                Component toolbarPool = mainWindowOper
216:                        .findSubComponent(new ComponentChooser() {
217:                            public boolean checkComponent(Component comp) {
218:                                return comp.getClass().getName().equals(
219:                                        "org.openide.awt.ToolbarPool");
220:                            }
221:
222:                            public String getDescription() {
223:                                return "org.openide.awt.ToolbarPool";
224:                            }
225:                        });
226:                ContainerOperator toolbarOper = mainWindowOper.getToolbar(0);
227:                int heightOrig = toolbarPool.getHeight();
228:                mainWindowOper.dragNDropToolbar(toolbarOper, 0, 100);
229:                assertTrue(
230:                        "Toolbar not moved down - main window height the same.",
231:                        heightOrig != toolbarPool.getHeight());
232:            }
233:
234:            /** Test of MainWindowOperator.StatusTextTracer class. */
235:            public void testStatusTextTracer() {
236:                MainWindowOperator.StatusTextTracer stt = mainWindowOper
237:                        .getStatusTextTracer();
238:                stt.start();
239:                // simulate compile action which produces at least two messages: "Compiling ..." and
240:                // "Finished ..."
241:                StatusDisplayer.getDefault().setStatusText("Compiling");
242:                StatusDisplayer.getDefault().setStatusText("Finished");
243:                //new CompileAction().performAPI();
244:                // waits for "Compiling" status text
245:                stt.waitText("Compiling");
246:                // waits for "Finished" status text
247:                stt.waitText("Finished");
248:
249:                // order is not significant => following works as well
250:                stt.waitText("Finished");
251:                stt.waitText("Compiling");
252:
253:                ArrayList list = stt.getStatusTextHistory();
254:                assertEquals(
255:                        "Method getStatusTextHistory returns wrong ArrayList.",
256:                        "Compiling", list.get(0));
257:                assertEquals(
258:                        "Method getStatusTextHistory returns wrong ArrayList.",
259:                        "Finished", list.get(1));
260:                ByteArrayOutputStream stream = new ByteArrayOutputStream();
261:                stt.printStatusTextHistory(new PrintStream(stream));
262:                assertTrue(
263:                        "Method printStatusTextHistory prints wrong values.",
264:                        stream.toString().indexOf("Compiling") > -1); // NOI18N
265:                assertTrue(
266:                        "Method printStatusTextHistory prints wrong values.",
267:                        stream.toString().indexOf("Finished") > -1); // NOI18N
268:
269:                // to be order significant, set removedCompared parameter to true
270:                stt.waitText("Compiling", true);
271:                stt.waitText("Finished", true);
272:
273:                // history was removed by above methods => need to produce a new messages
274:                StatusDisplayer.getDefault().setStatusText("Compiling");
275:                StatusDisplayer.getDefault().setStatusText("Finished");
276:                //new CompileAction().performAPI();
277:
278:                // order is significant if removedCompared parameter is true =>
279:                // => following fails because Finished is shown as second
280:                stt.waitText("Finished", true);
281:                long oldTimeout = JemmyProperties
282:                        .getCurrentTimeout("Waiter.WaitingTime");
283:                try {
284:                    JemmyProperties.setCurrentTimeout("Waiter.WaitingTime",
285:                            3000);
286:                    stt.waitText("Compiling", true);
287:                    fail("waitText() should fail because of wrong order.");
288:                } catch (JemmyException e) {
289:                    // OK. It fails.
290:                } finally {
291:                    JemmyProperties.setCurrentTimeout("Waiter.WaitingTime",
292:                            oldTimeout);
293:                }
294:
295:                String expectedText = "Should be traced.";
296:                StatusDisplayer.getDefault().setStatusText(expectedText);
297:                // stop tracing
298:                stt.stop();
299:                assertTrue("Text \"" + expectedText + "\" not traced.", stt
300:                        .contains(expectedText, false));
301:                stt.clear();
302:                assertTrue("clear() doesn't work.", !stt.contains(expectedText,
303:                        false));
304:                expectedText = "Should not be traced.";
305:                StatusDisplayer.getDefault().setStatusText(expectedText);
306:                assertTrue("stop() doesn't work. Text \"" + expectedText
307:                        + "\" should not be traced.", !stt.contains(
308:                        expectedText, false));
309:            }
310:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.