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:
042: package gui.propertyeditors;
043:
044: import gui.propertyeditors.utilities.CoreSupport;
045:
046: import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator;
047: import org.netbeans.jellytools.properties.editors.FilesystemCustomEditorOperator;
048:
049: import org.netbeans.jemmy.EventTool;
050:
051: import org.netbeans.junit.NbTestSuite;
052:
053: /**
054: * Tests of Identifier Array Property Editor.
055: *
056: * @author Marian.Mirilovic@Sun.Com
057: */
058: public class PropertyType_Filesystem extends PropertyEditorsTest {
059:
060: public String propertyName_L;
061: public String propertyValue_L;
062: public String propertyValueExpectation_L;
063:
064: public boolean waitDialog = false;
065:
066: private final String ADDDIRECTORY = "Add Directory:";
067: private final String ADDJAR = "Add JAR:";
068:
069: private static String FS_Data_path;
070: private static String FS_Data_path_data_jar;
071:
072: /** Creates a new instance of PropertyType_Filesystem */
073: public PropertyType_Filesystem(String testName) {
074: super (testName);
075: }
076:
077: public void setUp() {
078: propertyName_L = "Filesystem";
079: super .setUp();
080: }
081:
082: public static NbTestSuite suite() {
083:
084: //TODO write new way for promoD
085: //String path = CoreSupport.getSystemPath("gui/data", CoreSupport.beanName, "java");
086: String path = "";
087:
088: FS_Data_path = path.substring(0, path.lastIndexOf(System
089: .getProperty("file.separator")));
090: FS_Data_path_data_jar = FS_Data_path
091: + System.getProperty("file.separator") + "data.jar";
092:
093: NbTestSuite suite = new NbTestSuite();
094: suite.addTest(new PropertyType_Filesystem("verifyCustomizer"));
095: suite.addTest(new PropertyType_Filesystem(
096: "testCustomizerCancel"));
097: suite.addTest(new PropertyType_Filesystem(
098: "testCustomizerAddDirectory"));
099: suite.addTest(new PropertyType_Filesystem(
100: "testCustomizerAddJar"));
101: return suite;
102: }
103:
104: public void testCustomizerAddDirectory() {
105: propertyValue_L = ADDDIRECTORY + FS_Data_path;
106: propertyValueExpectation_L = getOSDependentFilesystem(FS_Data_path);
107: waitDialog = false;
108: setByCustomizerOk(propertyName_L, true);
109: }
110:
111: public void testCustomizerAddJar() {
112: propertyValue_L = ADDJAR + FS_Data_path_data_jar;
113: propertyValueExpectation_L = FS_Data_path_data_jar;
114: waitDialog = false;
115: setByCustomizerOk(propertyName_L, true);
116: }
117:
118: public void testCustomizerCancel() {
119: propertyValue_L = ADDJAR + FS_Data_path_data_jar;
120: propertyValueExpectation_L = propertyValue_L;
121: waitDialog = false;
122: setByCustomizerCancel(propertyName_L, false);
123: }
124:
125: public void verifyCustomizer() {
126: verifyCustomizer(propertyName_L);
127: }
128:
129: public void setCustomizerValue() {
130: FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(
131: propertyCustomizer);
132:
133: if (propertyValue_L.startsWith(ADDDIRECTORY)) {
134: err.println("== ADDING DIRECTORY ============");
135: customizer.addLocalDirectory();
136: customizer.btBrowse().pushNoBlock();
137: FileCustomEditorOperator dialog = new FileCustomEditorOperator(
138: "Add Local Directory");
139: dialog.setFileValue(getPath(propertyValue_L, ADDDIRECTORY));
140: new EventTool().waitNoEvent(500);
141: dialog.ok();
142: //customizer.setDirectory(getPath(propertyValue_L, ADDDIRECTORY));
143: }
144:
145: if (propertyValue_L.startsWith(ADDJAR)) {
146: err.println("== ADDING JAR ============");
147: customizer.addJARFile();
148: customizer.btBrowse2().pushNoBlock();
149: FileCustomEditorOperator dialog = new FileCustomEditorOperator(
150: "Add JAR File");
151: dialog.fileChooser().chooseFile(
152: getPath(propertyValue_L, ADDJAR));
153: //new EventTool().waitNoEvent(500);
154: //dialog.ok();
155: //customizer.setJARFile(getPath(propertyValue_L, ADDJAR));
156: }
157:
158: }
159:
160: public void verifyPropertyValue(boolean expectation) {
161: //verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
162:
163: if (expectation) {
164: String newValue = getValue(propertyName_L);
165: String log = "Actual value is {" + newValue
166: + "} - set value is {" + propertyValue_L
167: + "} / expectation value is {"
168: + propertyValueExpectation_L + "}";
169:
170: err
171: .println("=========================== Trying to verify value ["
172: + log + "].");
173:
174: if (newValue.indexOf(propertyValueExpectation_L) != -1) {
175: log(log + " --> PASS");
176: } else {
177: fail(log + " --> FAIL");
178: }
179: } else {
180: verifyExpectationValue(propertyName_L, expectation,
181: propertyValueExpectation_L, propertyValue_L,
182: waitDialog);
183: }
184:
185: }
186:
187: private String getPath(String str, String delim) {
188: int index = str.indexOf(delim);
189:
190: err.println("============================= Try to set path="
191: + str);
192:
193: if (index > -1)
194: return str.substring(index + delim.length());
195:
196: return str;
197: }
198:
199: private String getOSDependentFilesystem(String path) {
200: String os = System.getProperty("os.name");
201: err.println("Os name = {" + os + "}");
202:
203: if (os.indexOf("Win") != -1)
204: return path.replace('\\', '/');
205:
206: return path;
207: }
208:
209: public void verifyCustomizerLayout() {
210: FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(
211: propertyCustomizer);
212: customizer.verify();
213: customizer.btOK();
214: customizer.btCancel();
215: }
216:
217: /** Test could be executed internaly in Forte without XTest
218: * @param args arguments from command line
219: */
220: public static void main(String[] args) {
221: //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Filesystem.class));
222: junit.textui.TestRunner.run(suite());
223: }
224:
225: }
|