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: package org.netbeans.jellytools;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045: import junit.textui.TestRunner;
046: import org.netbeans.jellytools.actions.CloneViewAction;
047: import org.netbeans.jellytools.actions.OpenAction;
048: import org.netbeans.jellytools.nodes.JavaNode;
049: import org.netbeans.jellytools.nodes.SourcePackagesNode;
050: import org.netbeans.jellytools.nodes.Node;
051: import org.netbeans.jemmy.EventTool;
052: import org.netbeans.junit.NbTestSuite;
053:
054: /**
055: * Test of org.netbeans.jellytools.EditorWindowOperator.
056: * Order of tests is important.
057: * @author Jiri.Skrivanek@sun.com
058: */
059: public class EditorWindowOperatorTest extends JellyTestCase {
060:
061: /** Constructor required by JUnit.
062: * @param testName method name to be used as testcase
063: */
064: public EditorWindowOperatorTest(java.lang.String testName) {
065: super (testName);
066: }
067:
068: /** Use for internal test execution inside IDE
069: * @param args command line arguments
070: */
071: public static void main(java.lang.String[] args) {
072: TestRunner.run(suite());
073: }
074:
075: /** Method used for explicit testsuite definition
076: * @return created suite
077: */
078: public static Test suite() {
079: TestSuite suite = new NbTestSuite();
080: // order of tests is important
081: suite.addTest(new EditorWindowOperatorTest("testSelectPage"));
082: suite.addTest(new EditorWindowOperatorTest("testGetEditor"));
083: suite
084: .addTest(new EditorWindowOperatorTest(
085: "testSelectDocument"));
086: suite.addTest(new EditorWindowOperatorTest("testJumpLeft"));
087: suite
088: .addTest(new EditorWindowOperatorTest(
089: "testMoveTabsRight"));
090: suite.addTest(new EditorWindowOperatorTest("testMoveTabsLeft"));
091: suite.addTest(new EditorWindowOperatorTest("testVerify"));
092: suite.addTest(new EditorWindowOperatorTest("testCloseDiscard"));
093: return suite;
094: }
095:
096: /** Redirect output to log files, wait before each test case. */
097: protected void setUp() {
098: System.out.println("### " + getName() + " ###");
099: }
100:
101: private static final String SAMPLE_CLASS_1 = "SampleClass1.java";
102: private static final String SAMPLE_CLASS_2 = "SampleClass2.java";
103:
104: /** Test of selectPage method. */
105: public void testSelectPage() {
106: // next tests depends on this
107: startTest();
108: Node sample1 = new Node(
109: new SourcePackagesNode("SampleProject"), "sample1"); // NOI18N
110: Node sample2 = new Node(
111: new SourcePackagesNode("SampleProject"),
112: "sample1.sample2"); // NOI18N
113: JavaNode sampleClass1 = new JavaNode(sample1, SAMPLE_CLASS_1);
114: OpenAction openAction = new OpenAction();
115: openAction.performAPI(sampleClass1);
116: // close all => it satisfies only sample classes are opened
117: new EditorWindowOperator().closeDiscard();
118: openAction.performAPI(sampleClass1);
119: JavaNode sampleClass2 = new JavaNode(sample2, SAMPLE_CLASS_2);
120: openAction.performAPI(sampleClass2);
121: EditorWindowOperator ewo = new EditorWindowOperator();
122: ewo.selectPage(SAMPLE_CLASS_1);
123: ewo.selectPage(SAMPLE_CLASS_2);
124: assertTrue("Page " + SAMPLE_CLASS_2 + " not selected.", ewo
125: .getEditor().getName().indexOf(SAMPLE_CLASS_2) != -1);
126: ewo.selectPage(SAMPLE_CLASS_1);
127: assertTrue("Page " + SAMPLE_CLASS_1 + " not selected.", ewo
128: .getEditor().getName().indexOf(SAMPLE_CLASS_1) != -1);
129: // finished succesfully
130: endTest();
131: }
132:
133: /** Test of txtEditorPane method. */
134: public void testGetEditor() {
135: // next tests depends on this
136: startTest();
137: EditorWindowOperator ewo = new EditorWindowOperator();
138: assertEquals("Wrong editor pane found.", SAMPLE_CLASS_1, ewo
139: .getEditor().getName());
140: ewo.selectPage(SAMPLE_CLASS_2);
141: assertEquals("Wrong editor pane found.", SAMPLE_CLASS_1, ewo
142: .getEditor(0).getName());
143: assertEquals("Wrong editor pane found.", SAMPLE_CLASS_2, ewo
144: .getEditor(SAMPLE_CLASS_2).getName());
145: // finished succesfully
146: endTest();
147: }
148:
149: /** Test of selectDocument methods. */
150: public void testSelectDocument() {
151: // this test depends on previous
152: startTest();
153: // but not block anything else
154: clearTestStatus();
155: EditorWindowOperator ewo = new EditorWindowOperator();
156: ewo.selectDocument(SAMPLE_CLASS_1);
157: assertEquals("Wrong document selected.", SAMPLE_CLASS_1, ewo
158: .getEditor().getName());
159: ewo.selectDocument(1);
160: assertEquals("Wrong document selected.", SAMPLE_CLASS_2, ewo
161: .getEditor().getName());
162: }
163:
164: /** Test of jumpLeft method. */
165: public void testJumpLeft() {
166: // next tests depends on this
167: startTest();
168: EditorWindowOperator ewo = new EditorWindowOperator();
169: // clones selected document several times to test control buttons
170: for (int i = 0; i < 10; i++) {
171: new CloneViewAction().performAPI();
172: }
173: // click on leftmost tab until is not fully visible
174: int count = 0;
175: while (ewo.jumpLeft() && count++ < 100)
176: ;
177: // if it is still possible to jump left, wait a little and do jumpLeft again
178: if (ewo.jumpLeft()) {
179: new EventTool().waitNoEvent(3000);
180: while (ewo.jumpLeft() && count++ < 100)
181: ;
182: }
183: assertFalse("Leftmost tab should not be partially hidden.", ewo
184: .jumpLeft());
185: // finished succesfully
186: endTest();
187: }
188:
189: /** Test of moveTabsRight method. */
190: public void testMoveTabsRight() {
191: // next tests depends on this
192: startTest();
193: EditorWindowOperator ewo = new EditorWindowOperator();
194: ewo.moveTabsRight();
195: assertTrue("Tabs were not moved to the right.", ewo.btLeft()
196: .isEnabled());
197: // finished succesfully
198: endTest();
199: }
200:
201: /** Test of moveTabsLeft method. */
202: public void testMoveTabsLeft() {
203: // this test depends on previous
204: startTest();
205: // but not block anything else
206: clearTestStatus();
207: EditorWindowOperator ewo = new EditorWindowOperator();
208: ewo.moveTabsLeft();
209: assertFalse("Tabs were not moved to the left.", ewo.btLeft()
210: .isEnabled());
211: }
212:
213: /** Test of verify method. */
214: public void testVerify() {
215: EditorWindowOperator ewo = new EditorWindowOperator();
216: ewo.verify();
217: }
218:
219: /** Test of closeDiscard method. */
220: public void testCloseDiscard() {
221: new EditorWindowOperator().closeDiscard();
222: }
223: }
|