KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > gui > copypaste > PackageNodeTest


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.java.gui.copypaste;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import junit.textui.TestRunner;
27 import org.netbeans.jellytools.JellyTestCase;
28 import org.netbeans.jellytools.ProjectsTabOperator;
29 import org.netbeans.jellytools.actions.CopyAction;
30 import org.netbeans.jellytools.actions.PasteAction;
31 import org.netbeans.jellytools.nodes.Node;
32 import org.netbeans.jemmy.JemmyProperties;
33 import org.netbeans.jemmy.TestOut;
34 import org.netbeans.junit.NbTestSuite;
35 import org.netbeans.test.java.Utilities;
36 import org.netbeans.test.java.gui.GuiUtilities;
37
38
39 /**
40  * Tests copy and paste operations on a package node.
41  * @author Roman Strobl
42  */

43 public class PackageNodeTest extends JellyTestCase {
44     
45     // name of sample project
46
private static final String JavaDoc TEST_PROJECT_NAME = "default";
47     
48     // path to sample files
49
private static final String JavaDoc TEST_PACKAGE_PATH =
50             "org.netbeans.test.java.gui.copypaste";
51     
52     // name of sample package
53
private static final String JavaDoc TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test";
54     
55     // name of sample package 2
56
private static final String JavaDoc TEST_PACKAGE_NAME_2 =
57             TEST_PACKAGE_PATH+".test2";
58     
59     // name of sample class
60
private static final String JavaDoc TEST_CLASS_NAME = "TestClass";
61     
62     /**
63      * error log
64      */

65     protected static PrintStream JavaDoc err;
66     
67     /**
68      * standard log
69      */

70     protected static PrintStream JavaDoc log;
71     
72     // workdir, default /tmp, changed to NBJUnit workdir during test
73
private String JavaDoc workDir = "/tmp";
74     
75     // actual directory with project
76
private static String JavaDoc projectDir;
77     
78     
79     /**
80      * Needs to be defined because of JUnit
81      * @param name Name of test
82      */

83     public PackageNodeTest(String JavaDoc name) {
84         super(name);
85     }
86     
87     /**
88      * Adds tests into the test suite.
89      * @return suite
90      */

91     public static NbTestSuite suite() {
92         NbTestSuite suite = new NbTestSuite();
93         // prepare testing project and package - not a core test but needed
94
suite.addTest(new PackageNodeTest("testCopyPaste"));
95         return suite;
96     }
97     
98     /**
99      * Main method for standalone execution.
100      * @param args the command line arguments
101      */

102     public static void main(java.lang.String JavaDoc[] args) {
103         TestRunner.run(suite());
104     }
105     
106     /**
107      * Sets up logging facilities.
108      */

109     public void setUp() {
110         System.out.println("######## "+getName()+" #######");
111         err = getLog();
112         log = getRef();
113         JemmyProperties.getProperties().setOutput(new TestOut(null,
114                 new PrintWriter JavaDoc(err, true), new PrintWriter JavaDoc(err, false), null));
115         try {
116             File JavaDoc wd = getWorkDir();
117             workDir = wd.toString();
118         } catch (IOException JavaDoc e) { }
119     }
120     
121     /**
122      * Tests copy and paste operations on a package.
123      */

124     public void testCopyPaste() {
125         Node pn = new ProjectsTabOperator().getProjectRootNode(
126                 TEST_PROJECT_NAME);
127         pn.select();
128         
129         // perform copy
130
Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
131                 "org.netbeans.modules.java.j2seproject.Bundle",
132                 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME);
133         n.select();
134         Utilities.takeANap(3000);
135         new CopyAction().perform();
136         
137         // perform paste
138
Node n2 = new Node(pn, org.netbeans.jellytools.Bundle.getString(
139                 "org.netbeans.modules.java.j2seproject.Bundle",
140                 "NAME_test.src.dir"));
141         
142         n2.select();
143         new PasteAction().perform();
144         
145         Utilities.takeANap(1000);
146         
147         // check if created node exits
148
GuiUtilities.waitForChildNode(TEST_PROJECT_NAME,
149                 org.netbeans.jellytools.Bundle.getString(
150                 "org.netbeans.modules.java.j2seproject.Bundle",
151                 "NAME_test.src.dir"), TEST_PACKAGE_NAME);
152         Node n3 = new Node(pn, org.netbeans.jellytools.Bundle.getString(
153                 "org.netbeans.modules.java.j2seproject.Bundle",
154                 "NAME_test.src.dir")+"|"+TEST_PACKAGE_NAME);
155         n3.select();
156     }
157     
158 }
159
Popular Tags