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.util.Arrays;
044: import org.netbeans.jellytools.actions.CopyAction;
045: import org.netbeans.jellytools.actions.DeleteAction;
046: import org.netbeans.jellytools.actions.OpenAction;
047: import org.netbeans.jellytools.actions.PasteActionNoBlock;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jellytools.nodes.SourcePackagesNode;
050: import org.netbeans.jemmy.operators.JButtonOperator;
051: import org.netbeans.junit.NbTest;
052: import org.netbeans.junit.NbTestSuite;
053:
054: /** Test DocumentsDialogOperator.
055: *
056: * @author Jiri.Skrivanek@sun.com
057: */
058: public class DocumentsDialogOperatorTest extends JellyTestCase {
059:
060: public DocumentsDialogOperatorTest(java.lang.String testName) {
061: super (testName);
062: }
063:
064: public static void main(java.lang.String[] args) {
065: junit.textui.TestRunner.run(suite());
066: }
067:
068: public static NbTest suite() {
069: NbTestSuite suite = new NbTestSuite();
070: // test cases have to be in particular order
071: suite.addTest(new DocumentsDialogOperatorTest("testInvoke"));
072: suite.addTest(new DocumentsDialogOperatorTest("testVerify"));
073: suite.addTest(new DocumentsDialogOperatorTest(
074: "testSelectDocument"));
075: suite.addTest(new DocumentsDialogOperatorTest(
076: "testSelectDocuments"));
077: suite.addTest(new DocumentsDialogOperatorTest(
078: "testGetDescription"));
079: suite.addTest(new DocumentsDialogOperatorTest(
080: "testSaveDocuments"));
081: suite.addTest(new DocumentsDialogOperatorTest(
082: "testCloseDocuments"));
083: suite.addTest(new DocumentsDialogOperatorTest(
084: "testSwitchToDocument"));
085: return suite;
086: }
087:
088: /** Print out test name. */
089: public void setUp() {
090: System.out.println("### " + getName() + " ###");
091: }
092:
093: private static DocumentsDialogOperator documentsOper;
094: private static Node editableSourceNode;
095:
096: /**
097: * Test of invoke method.
098: */
099: public void testInvoke() {
100: EditorOperator.closeDiscardAll();
101: Node sample1 = new Node(
102: new SourcePackagesNode("SampleProject"), "sample1"); // NOI18N
103: Node sample2 = new Node(
104: new SourcePackagesNode("SampleProject"),
105: "sample1.sample2"); // NOI18N
106: Node node = new Node(sample1, "SampleClass1");// NOI18N
107: new OpenAction().performAPI(node);
108: node = new Node(sample2, "SampleClass2");// NOI18N
109: new OpenAction().performAPI(node);
110: // copy node to be able to write in
111: new CopyAction().performAPI(node);
112: new PasteActionNoBlock().performAPI(sample2);
113: String copyClassTitle = Bundle.getString(
114: "org.netbeans.modules.refactoring.java.ui.Bundle",
115: "LBL_CopyClass");
116: NbDialogOperator copyClassOper = new NbDialogOperator(
117: copyClassTitle);
118: // "Refactor"
119: String refactorLabel = Bundle.getStringTrimmed(
120: "org.netbeans.modules.refactoring.spi.impl.Bundle",
121: "CTL_Finish");
122: new JButtonOperator(copyClassOper, refactorLabel).push();
123: copyClassOper.getTimeouts().setTimeout("Waiter.WaitingTime",
124: 30000);
125: copyClassOper.waitClosed();
126: editableSourceNode = new Node(sample2, "SampleClass21");// NOI18N
127: new OpenAction().performAPI(editableSourceNode);
128: documentsOper = DocumentsDialogOperator.invoke();
129: }
130:
131: /**
132: * Test of verify method.
133: */
134: public void testVerify() {
135: documentsOper.verify();
136: }
137:
138: /**
139: * Test of selectDocument method.
140: */
141: public void testSelectDocument() {
142: documentsOper.selectDocument("SampleClass1.java"); // NOI18N
143: assertEquals("Wrong document selected.", "SampleClass1.java",
144: documentsOper.lstDocuments().getSelectedValue()
145: .toString()); // NOI18N
146: documentsOper.selectDocument(2);
147: assertEquals("Wrong document selected.", 2, documentsOper
148: .lstDocuments().getSelectedIndex()); // NOI18N
149: }
150:
151: /**
152: * Test of selectDocuments method.
153: */
154: public void testSelectDocuments() {
155: String[] documents = { "SampleClass1.java", "SampleClass2.java" }; // NOI18N
156: documentsOper.selectDocuments(documents);
157: Object[] selected = documentsOper.lstDocuments()
158: .getSelectedValues();
159: for (int i = 0; i < selected.length; i++) {
160: assertEquals("Wrong document selected by names.",
161: documents[i], selected[i].toString());
162: }
163: // test one document
164: documentsOper
165: .selectDocuments(new String[] { "SampleClass21.java" }); // NOI18N
166: assertEquals("Wrong document selected.", "SampleClass21.java",
167: documentsOper.lstDocuments().getSelectedValue()
168: .toString()); // NOI18N
169:
170: int[] indexes = { 0, 1 };
171: documentsOper.selectDocuments(indexes);
172: assertTrue("Wrong documents selected by indexes.", Arrays
173: .equals(indexes, documentsOper.lstDocuments()
174: .getSelectedIndices())); // NOI18N
175: // test one document
176: documentsOper.selectDocuments(new int[] { 2 });
177: assertEquals("Wrong document selected.", 2, documentsOper
178: .lstDocuments().getSelectedIndex()); // NOI18N
179: }
180:
181: /**
182: * Test of getDescription method.
183: */
184: public void testGetDescription() {
185: documentsOper.selectDocument("SampleClass1.java"); // NOI18N
186: assertTrue("Wrong description obtain.", documentsOper
187: .getDescription().indexOf("SampleClass1.java") > -1); // NOI18N
188: }
189:
190: /**
191: * Test of saveDocuments method.
192: */
193: public void testSaveDocuments() {
194: EditorOperator eo = new EditorOperator("SampleClass21.java"); // NOI18N
195: eo.insert("//dummy\n", 1, 1); // NOI18N
196: documentsOper.selectDocument("SampleClass21.java"); // NOI18N
197: documentsOper.saveDocuments();
198: boolean modified = eo.isModified();
199: eo.closeDiscard();
200: assertFalse("Document is not saved.", modified);//NOI18N
201: }
202:
203: /**
204: * Test of closeDocuments method.
205: */
206: public void testCloseDocuments() {
207: documentsOper.selectDocument("SampleClass2.java"); // NOI18N
208: documentsOper.closeDocuments();
209: assertTrue("Document was not closed.", documentsOper
210: .lstDocuments().getModel().getSize() == 1);
211: }
212:
213: /**
214: * Test of switchToDocument method.
215: */
216: public void testSwitchToDocument() {
217: documentsOper.selectDocument("SampleClass1.java"); //NOI18N
218: documentsOper.switchToDocument();
219: // clean up - delete editable source
220: new DeleteAction().performAPI(editableSourceNode);
221: // "Safe Delete"
222: String safeDeleteTitle = Bundle.getString(
223: "org.netbeans.modules.refactoring.spi.impl.Bundle",
224: "LBL_SafeDel"); // NOI18N
225: new NbDialogOperator(safeDeleteTitle).ok();
226: }
227: }
|