KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > junit > testcreation > GotoTest


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.junit.testcreation;
21
22 import org.netbeans.jellytools.Bundle;
23 import org.netbeans.jellytools.EditorOperator;
24 import org.netbeans.jellytools.MainWindowOperator;
25 import org.netbeans.jellytools.ProjectsTabOperator;
26 import org.netbeans.jellytools.nodes.Node;
27 import org.netbeans.jemmy.operators.JMenuBarOperator;
28 import org.netbeans.jemmy.operators.JMenuItemOperator;
29 import org.netbeans.jemmy.operators.JMenuOperator;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.test.junit.utils.Utilities;
33
34 /**
35  * Tests "Goto Test" action
36  * @author Max Sauer
37  */

38 public class GotoTest extends NbTestCase {
39     private static final String JavaDoc TEST_PACKAGE_NAME =
40             "org.netbeans.test.junit.testresults.test";
41     
42     private static final String JavaDoc TEST_PACKAGE_PACKAGEGOTO_NAME =
43             "org.netbeans.test.junit.go.test";
44     
45     /** Creates a new instance of GotoTest */
46     public GotoTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     /**
51      * Adds tests to suite
52      * @return created suite
53      */

54     public static NbTestSuite suite() {
55         NbTestSuite suite = new NbTestSuite(GotoTest.class);
56         return suite;
57     }
58     
59     /**
60      * Test selecting appropriate test from Main menu
61      */

62     public void testSelectTestFromMainMenu() {
63         //open sample class
64
Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
65                 "|" + TEST_PACKAGE_NAME+ "|" + Utilities.TEST_CLASS_NAME);
66         
67         EditorOperator eos = new EditorOperator(Utilities.TEST_CLASS_NAME);
68         
69         JMenuBarOperator jbo = new JMenuBarOperator(
70                 MainWindowOperator.getDefault().getJMenuBar());
71         String JavaDoc[] sf = {Bundle.getStringTrimmed("org.netbeans.core.Bundle",
72                 "Menu/GoTo"),
73                 Bundle.getStringTrimmed("org.netbeans.modules.junit.Bundle",
74                 "LBL_Action_GoToTest")};
75         jbo.pushMenu(sf[0]);
76         JMenuItemOperator jmio = new JMenuItemOperator(new JMenuOperator(jbo, sf[0]).getItem(0));
77         //Check if goto test is enabled inside menu
78
assertTrue("Goto Test disabled when invoked from Editor!", jmio.isEnabled());
79         jbo.pushMenu(sf);
80         //Operator for opened TestClassTest
81
EditorOperator eo = new EditorOperator(Utilities.TEST_CLASS_NAME + "Test");
82         assertTrue("Test for \"" + TEST_PACKAGE_NAME +
83                 Utilities.TEST_CLASS_NAME + "\" not opened!", eo.isVisible());
84         eo.close(false);
85         eos.close(false);
86     }
87     
88     /**
89      * Test selecting appropriate test from Edior's context menu
90      */

91     public void testSelectTestFromExplorer() {
92         //select sample class in explorer
93
Node pn = new ProjectsTabOperator().getProjectRootNode(
94                 Utilities.TEST_PROJECT_NAME);
95         pn.select();
96         Node n = new Node(pn, Utilities.SRC_PACKAGES_PATH +
97                 "|" + TEST_PACKAGE_NAME+ "|" + Utilities.TEST_CLASS_NAME);
98         n.select();
99         
100         JMenuBarOperator jbo = new JMenuBarOperator(
101                 MainWindowOperator.getDefault().getJMenuBar());
102         
103         String JavaDoc[] sf = {Bundle.getStringTrimmed("org.netbeans.core.Bundle",
104                 "Menu/GoTo"),
105                 Bundle.getStringTrimmed("org.netbeans.modules.junit.Bundle",
106                 "LBL_Action_GoToTest")};
107         jbo.pushMenu(sf[0]);
108         JMenuItemOperator jmio = new JMenuItemOperator(new JMenuOperator(jbo, sf[0]).getItem(0));
109         //Check if goto test is enabled inside menu
110
assertTrue("Goto Test disabled when invoked from Explorer, over a class node!" +
111                 "see: http://www.netbeans.org/issues/show_bug.cgi?id=88599",
112                 jmio.isEnabled());
113         jbo.pushMenu(sf);
114         EditorOperator eot = new EditorOperator(Utilities.TEST_CLASS_NAME);
115         assertTrue("Test for \"" + TEST_PACKAGE_NAME +
116                 Utilities.TEST_CLASS_NAME + "\" not opened!", eot.isVisible());
117         eot.close(false);
118     }
119     
120     /**
121      * Tests selecting of suite test when invoking GoTo Test for a java package
122      */

123     public void testSelectTestFromExplorerPackage() {
124         //select sample class in explorer
125
Node pn = new ProjectsTabOperator().getProjectRootNode(
126                 Utilities.TEST_PROJECT_NAME);
127         pn.select();
128         Node n = new Node(pn, Utilities.SRC_PACKAGES_PATH +
129                 "|" + TEST_PACKAGE_PACKAGEGOTO_NAME);
130         n.select(); //select the 'go' package from test project
131

132         JMenuBarOperator jbo = new JMenuBarOperator(
133                 MainWindowOperator.getDefault().getJMenuBar());
134         
135         String JavaDoc[] sf = {Bundle.getStringTrimmed("org.netbeans.core.Bundle",
136                 "Menu/GoTo"),
137                 Bundle.getStringTrimmed("org.netbeans.modules.junit.Bundle",
138                 "LBL_Action_GoToTest")};
139         jbo.pushMenu(sf[0]);
140         JMenuItemOperator jmio = new JMenuItemOperator(new JMenuOperator(jbo, sf[0]).getItem(0));
141         //Check if goto test is enabled inside menu
142
assertTrue("Goto Test disabled when invoked from Explorer, over a package node!" +
143                 "see: http://www.netbeans.org/issues/show_bug.cgi?id=88599",
144                 jmio.isEnabled());
145         jbo.pushMenu(sf);
146         EditorOperator eot = new EditorOperator("TestSuite"); //test suite for the package
147
assertTrue("Test suite for \"" + TEST_PACKAGE_PACKAGEGOTO_NAME +
148                  "\" (TestSuite.java) not opened!", eot.isVisible());
149         eot.close(false);
150     }
151     
152     
153
154 }
155
Popular Tags