KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_Filesystem


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.jellytools.properties.editors.FileCustomEditorOperator;
25 import org.netbeans.jellytools.properties.editors.FilesystemCustomEditorOperator;
26
27 import org.netbeans.jemmy.EventTool;
28
29 import org.netbeans.junit.NbTestSuite;
30
31
32 /**
33  * Tests of Identifier Array Property Editor.
34  *
35  * @author Marian.Mirilovic@Sun.Com
36  */

37 public class PropertyType_Filesystem extends PropertyEditorsTest {
38
39     public String JavaDoc propertyName_L;
40     public String JavaDoc propertyValue_L;
41     public String JavaDoc propertyValueExpectation_L;
42     
43     public boolean waitDialog = false;
44     
45     private final String JavaDoc ADDDIRECTORY = "Add Directory:";
46     private final String JavaDoc ADDJAR = "Add JAR:";
47     
48     private static String JavaDoc FS_Data_path;
49     private static String JavaDoc FS_Data_path_data_jar;
50     
51     /** Creates a new instance of PropertyType_Filesystem */
52     public PropertyType_Filesystem(String JavaDoc testName) {
53         super(testName);
54     }
55     
56     
57     public void setUp(){
58         propertyName_L = "Filesystem";
59         super.setUp();
60     }
61     
62     public static NbTestSuite suite() {
63         
64         //TODO write new way for promoD
65
//String path = CoreSupport.getSystemPath("gui/data", CoreSupport.beanName, "java");
66
String JavaDoc path = "";
67         
68         FS_Data_path = path.substring(0,path.lastIndexOf(System.getProperty("file.separator")));
69         FS_Data_path_data_jar = FS_Data_path + System.getProperty("file.separator") + "data.jar";
70         
71         NbTestSuite suite = new NbTestSuite();
72         suite.addTest(new PropertyType_Filesystem("verifyCustomizer"));
73         suite.addTest(new PropertyType_Filesystem("testCustomizerCancel"));
74         suite.addTest(new PropertyType_Filesystem("testCustomizerAddDirectory"));
75         suite.addTest(new PropertyType_Filesystem("testCustomizerAddJar"));
76         return suite;
77     }
78     
79     
80     public void testCustomizerAddDirectory() {
81         propertyValue_L = ADDDIRECTORY + FS_Data_path;
82         propertyValueExpectation_L = getOSDependentFilesystem(FS_Data_path);
83         waitDialog = false;
84         setByCustomizerOk(propertyName_L, true);
85     }
86     
87     public void testCustomizerAddJar() {
88         propertyValue_L = ADDJAR + FS_Data_path_data_jar;
89         propertyValueExpectation_L = FS_Data_path_data_jar;
90         waitDialog = false;
91         setByCustomizerOk(propertyName_L, true);
92     }
93     
94     public void testCustomizerCancel(){
95         propertyValue_L = ADDJAR + FS_Data_path_data_jar;
96         propertyValueExpectation_L = propertyValue_L;
97         waitDialog = false;
98         setByCustomizerCancel(propertyName_L, false);
99     }
100     
101     public void verifyCustomizer() {
102         verifyCustomizer(propertyName_L);
103     }
104     
105     public void setCustomizerValue() {
106         FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(propertyCustomizer);
107         
108         if(propertyValue_L.startsWith(ADDDIRECTORY)){
109             err.println("== ADDING DIRECTORY ============");
110             customizer.addLocalDirectory();
111             customizer.btBrowse().pushNoBlock();
112             FileCustomEditorOperator dialog = new FileCustomEditorOperator("Add Local Directory");
113             dialog.setFileValue(getPath(propertyValue_L, ADDDIRECTORY));
114             new EventTool().waitNoEvent(500);
115             dialog.ok();
116             //customizer.setDirectory(getPath(propertyValue_L, ADDDIRECTORY));
117
}
118         
119         if(propertyValue_L.startsWith(ADDJAR)){
120             err.println("== ADDING JAR ============");
121             customizer.addJARFile();
122             customizer.btBrowse2().pushNoBlock();
123             FileCustomEditorOperator dialog = new FileCustomEditorOperator("Add JAR File");
124             dialog.fileChooser().chooseFile(getPath(propertyValue_L, ADDJAR));
125             //new EventTool().waitNoEvent(500);
126
//dialog.ok();
127
//customizer.setJARFile(getPath(propertyValue_L, ADDJAR));
128
}
129         
130         
131     }
132     
133     public void verifyPropertyValue(boolean expectation) {
134         //verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
135

136         if(expectation){
137             String JavaDoc newValue = getValue(propertyName_L);
138             String JavaDoc log = "Actual value is {"+newValue+"} - set value is {"+propertyValue_L+"} / expectation value is {"+propertyValueExpectation_L+"}";
139             
140             err.println("=========================== Trying to verify value ["+log+"].");
141             
142             if(newValue.indexOf(propertyValueExpectation_L)!=-1) {
143                 log(log + " --> PASS");
144             }else {
145                 fail(log + " --> FAIL");
146             }
147         }else {
148             verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
149         }
150         
151     }
152     
153     
154     private String JavaDoc getPath(String JavaDoc str, String JavaDoc delim) {
155         int index = str.indexOf(delim);
156         
157         err.println("============================= Try to set path="+str);
158         
159         if(index > -1)
160             return str.substring(index + delim.length());
161         
162         return str;
163     }
164     
165     private String JavaDoc getOSDependentFilesystem(String JavaDoc path) {
166         String JavaDoc os = System.getProperty("os.name");
167         err.println("Os name = {"+os+"}");
168         
169         if(os.indexOf("Win")!=-1)
170             return path.replace('\\','/');
171         
172         return path;
173     }
174     
175     public void verifyCustomizerLayout() {
176         FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(propertyCustomizer);
177         customizer.verify();
178         customizer.btOK();
179         customizer.btCancel();
180     }
181     
182     /** Test could be executed internaly in Forte without XTest
183      * @param args arguments from command line
184      */

185     public static void main(String JavaDoc[] args) {
186         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Filesystem.class));
187
junit.textui.TestRunner.run(suite());
188     }
189     
190 }
191
Popular Tags