KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_NbClassPath


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 gui.propertyeditors;
21
22 import gui.propertyeditors.utilities.CoreSupport;
23
24 import org.netbeans.junit.NbTestSuite;
25
26 import org.netbeans.jellytools.properties.editors.ClasspathCustomEditorOperator;
27 import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator;
28
29 /**
30  * Tests of NbClassPath Property Editor.
31  *
32  * @author Marian.Mirilovic@Sun.Com
33  */

34 public class PropertyType_NbClassPath extends PropertyEditorsTest {
35
36     public String JavaDoc propertyName_L;
37     public String JavaDoc propertyValue_L;
38     public String JavaDoc propertyValueExpectation_L;
39     
40     public boolean waitDialog = false;
41     
42     private final String JavaDoc ADDDIRECTORY = "Add Directory:";
43     private final String JavaDoc ADDJAR = "Add JAR:";
44     private final String JavaDoc REMOVE = "Remove:";
45     private final String JavaDoc UP = "Up:";
46     private final String JavaDoc DOWN = "Down:";
47     
48     private static String JavaDoc directoryPath;
49     private static String JavaDoc dataJarPath;
50     
51     private static String JavaDoc delim;
52     
53     /** Creates a new instance of PropertyType_NbClassPath */
54     public PropertyType_NbClassPath(String JavaDoc testName) {
55         super(testName);
56         directoryPath = CoreSupport.getSampleProjectPath(this);
57         dataJarPath = directoryPath + System.getProperty("file.separator") + "data.jar";
58         
59         log("======= Directory Path={"+directoryPath+"}");
60         log("======= Data.jar Path={"+dataJarPath+"}");
61         
62         String JavaDoc os = System.getProperty("os.name");
63         System.err.println("Os name = {"+os+"}");
64         
65         if(os.indexOf("Win")!=-1)
66             delim = ";";
67         else
68             delim = ":";
69            
70         System.err.println("delim={"+delim+"}");
71
72         propertyName_L = "NbClassPath";
73     }
74     
75     
76     public static NbTestSuite suite() {
77         
78         NbTestSuite suite = new NbTestSuite();
79         suite.addTest(new PropertyType_NbClassPath("testByInPlace"));
80         suite.addTest(new PropertyType_NbClassPath("verifyCustomizer"));
81         suite.addTest(new PropertyType_NbClassPath("testCustomizerCancel"));
82         suite.addTest(new PropertyType_NbClassPath("testCustomizerAddDirectory"));
83         suite.addTest(new PropertyType_NbClassPath("testCustomizerRemove"));
84         suite.addTest(new PropertyType_NbClassPath("testCustomizerUp"));
85         suite.addTest(new PropertyType_NbClassPath("testCustomizerAddJar"));
86         
87         // must rewrite test specs to add this test
88
//suite.addTest(new PropertyType_NbClassPath("testCustomizerDown"));
89
return suite;
90     }
91     
92     
93     public void testCustomizerAddDirectory() {
94         propertyValue_L = ADDDIRECTORY + directoryPath;
95         propertyValueExpectation_L = "one.jar"+delim+"two.zip" + delim + directoryPath;
96         waitDialog = false;
97         setByCustomizerOk(propertyName_L, true);
98     }
99     
100     public void testCustomizerAddJar() {
101         propertyValue_L = ADDJAR + dataJarPath;
102         propertyValueExpectation_L = "two.zip"+delim+"one.jar"+ delim + dataJarPath;
103         waitDialog = false;
104         setByCustomizerOk(propertyName_L, true);
105     }
106     
107     public void testCustomizerRemove() {
108         propertyValue_L = REMOVE + directoryPath;
109         //propertyValueExpectation_L = "one.jar:two.zip:" + FS_Data_path_data_jar;
110
propertyValueExpectation_L = "one.jar"+delim+"two.zip";
111         waitDialog = false;
112         setByCustomizerOk(propertyName_L, true);
113     }
114
115     public void testCustomizerUp() {
116         propertyValue_L = UP + "two.zip";
117         //propertyValueExpectation_L = "two.zip:one.jar:" + FS_Data_path_data_jar;
118
propertyValueExpectation_L = "two.zip"+delim+"one.jar";
119         waitDialog = false;
120         setByCustomizerOk(propertyName_L, true);
121     }
122     
123     public void testCustomizerDown() {
124         propertyValue_L = DOWN + "one.jar";
125         propertyValueExpectation_L = "two.zip" + delim + dataJarPath + delim + "one.jar" ;
126         waitDialog = false;
127         setByCustomizerOk(propertyName_L, true);
128     }
129     
130     public void testCustomizerCancel(){
131         propertyValue_L = REMOVE + "one.jar";
132         propertyValueExpectation_L = propertyValue_L;
133         waitDialog = false;
134         setByCustomizerCancel(propertyName_L, false);
135     }
136     
137     public void testByInPlace(){
138         propertyValue_L = "one.jar"+delim+"two.zip";
139         propertyValueExpectation_L = propertyValue_L;
140         waitDialog = false;
141         setByInPlace(propertyName_L, propertyValue_L, true);
142     }
143     
144     public void verifyCustomizer() {
145         verifyCustomizer(propertyName_L);
146     }
147     
148     public void setCustomizerValue() {
149         ClasspathCustomEditorOperator customizer = new ClasspathCustomEditorOperator(propertyCustomizer);
150         
151         if(propertyValue_L.startsWith(ADDDIRECTORY)){
152             err.println("========== ADDING DIRECTORY =======");
153             customizer.addDirectory(getPath(propertyValue_L, ADDDIRECTORY));
154         }
155         
156         if(propertyValue_L.startsWith(ADDJAR)){
157             err.println("========== ADDING JAR =======");
158 // customizer.addJARZIP(getPath(propertyValue_L, ADDJAR));
159
// hack because previously code fails
160
FileCustomEditorOperator editor=customizer.addJARZIP();
161             editor.fileChooser().chooseFile(getPath(propertyValue_L, ADDJAR));
162             customizer.ok();
163         }
164         
165         if(propertyValue_L.startsWith(REMOVE)){
166             err.println("========== REMOVE =======");
167             customizer.remove(getPath(propertyValue_L,REMOVE));
168         }
169         
170         if(propertyValue_L.startsWith(UP)){
171             err.println("========== UP =======");
172             customizer.lstClasspath().selectItem(getPath(propertyValue_L,UP));
173             customizer.moveUp();
174         }
175         
176         if(propertyValue_L.startsWith(DOWN)){
177             err.println("========== DOWN =======");
178             customizer.lstClasspath().selectItem(getPath(propertyValue_L,DOWN));
179             customizer.moveDown();
180         }
181         
182     }
183     
184     public void verifyPropertyValue(boolean expectation) {
185         verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
186     }
187     
188     
189     private String JavaDoc getPath(String JavaDoc str, String JavaDoc delim) {
190         int index = str.indexOf(delim);
191
192         if(index > -1)
193             return str.substring(index + delim.length());
194         
195         return str;
196     }
197     
198     public void verifyCustomizerLayout() {
199         ClasspathCustomEditorOperator customizer = new ClasspathCustomEditorOperator(propertyCustomizer);
200         customizer.verify();
201         customizer.btOK();
202         customizer.btCancel();
203     }
204     
205     /** Test could be executed internaly in Forte without XTest
206      * @param args arguments from command line
207      */

208     public static void main(String JavaDoc[] args) {
209         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_NbClassPath.class));
210
junit.textui.TestRunner.run(suite());
211     }
212     
213 }
214
Popular Tags