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.junit.NbTestSuite;
047:
048: import org.netbeans.jellytools.properties.editors.ClasspathCustomEditorOperator;
049: import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator;
050:
051: /**
052: * Tests of NbClassPath Property Editor.
053: *
054: * @author Marian.Mirilovic@Sun.Com
055: */
056: public class PropertyType_NbClassPath extends PropertyEditorsTest {
057:
058: public String propertyName_L;
059: public String propertyValue_L;
060: public String propertyValueExpectation_L;
061:
062: public boolean waitDialog = false;
063:
064: private final String ADDDIRECTORY = "Add Directory:";
065: private final String ADDJAR = "Add JAR:";
066: private final String REMOVE = "Remove:";
067: private final String UP = "Up:";
068: private final String DOWN = "Down:";
069:
070: private static String directoryPath;
071: private static String dataJarPath;
072:
073: private static String delim;
074:
075: /** Creates a new instance of PropertyType_NbClassPath */
076: public PropertyType_NbClassPath(String testName) {
077: super (testName);
078: directoryPath = CoreSupport.getSampleProjectPath(this );
079: dataJarPath = directoryPath
080: + System.getProperty("file.separator") + "data.jar";
081:
082: log("======= Directory Path={" + directoryPath + "}");
083: log("======= Data.jar Path={" + dataJarPath + "}");
084:
085: String os = System.getProperty("os.name");
086: System.err.println("Os name = {" + os + "}");
087:
088: if (os.indexOf("Win") != -1)
089: delim = ";";
090: else
091: delim = ":";
092:
093: System.err.println("delim={" + delim + "}");
094:
095: propertyName_L = "NbClassPath";
096: }
097:
098: public static NbTestSuite suite() {
099:
100: NbTestSuite suite = new NbTestSuite();
101: suite.addTest(new PropertyType_NbClassPath("testByInPlace"));
102: suite.addTest(new PropertyType_NbClassPath("verifyCustomizer"));
103: suite.addTest(new PropertyType_NbClassPath(
104: "testCustomizerCancel"));
105: suite.addTest(new PropertyType_NbClassPath(
106: "testCustomizerAddDirectory"));
107: suite.addTest(new PropertyType_NbClassPath(
108: "testCustomizerRemove"));
109: suite.addTest(new PropertyType_NbClassPath("testCustomizerUp"));
110: suite.addTest(new PropertyType_NbClassPath(
111: "testCustomizerAddJar"));
112:
113: // must rewrite test specs to add this test
114: //suite.addTest(new PropertyType_NbClassPath("testCustomizerDown"));
115: return suite;
116: }
117:
118: public void testCustomizerAddDirectory() {
119: propertyValue_L = ADDDIRECTORY + directoryPath;
120: propertyValueExpectation_L = "one.jar" + delim + "two.zip"
121: + delim + directoryPath;
122: waitDialog = false;
123: setByCustomizerOk(propertyName_L, true);
124: }
125:
126: public void testCustomizerAddJar() {
127: propertyValue_L = ADDJAR + dataJarPath;
128: propertyValueExpectation_L = "two.zip" + delim + "one.jar"
129: + delim + dataJarPath;
130: waitDialog = false;
131: setByCustomizerOk(propertyName_L, true);
132: }
133:
134: public void testCustomizerRemove() {
135: propertyValue_L = REMOVE + directoryPath;
136: //propertyValueExpectation_L = "one.jar:two.zip:" + FS_Data_path_data_jar;
137: propertyValueExpectation_L = "one.jar" + delim + "two.zip";
138: waitDialog = false;
139: setByCustomizerOk(propertyName_L, true);
140: }
141:
142: public void testCustomizerUp() {
143: propertyValue_L = UP + "two.zip";
144: //propertyValueExpectation_L = "two.zip:one.jar:" + FS_Data_path_data_jar;
145: propertyValueExpectation_L = "two.zip" + delim + "one.jar";
146: waitDialog = false;
147: setByCustomizerOk(propertyName_L, true);
148: }
149:
150: public void testCustomizerDown() {
151: propertyValue_L = DOWN + "one.jar";
152: propertyValueExpectation_L = "two.zip" + delim + dataJarPath
153: + delim + "one.jar";
154: waitDialog = false;
155: setByCustomizerOk(propertyName_L, true);
156: }
157:
158: public void testCustomizerCancel() {
159: propertyValue_L = REMOVE + "one.jar";
160: propertyValueExpectation_L = propertyValue_L;
161: waitDialog = false;
162: setByCustomizerCancel(propertyName_L, false);
163: }
164:
165: public void testByInPlace() {
166: propertyValue_L = "one.jar" + delim + "two.zip";
167: propertyValueExpectation_L = propertyValue_L;
168: waitDialog = false;
169: setByInPlace(propertyName_L, propertyValue_L, true);
170: }
171:
172: public void verifyCustomizer() {
173: verifyCustomizer(propertyName_L);
174: }
175:
176: public void setCustomizerValue() {
177: ClasspathCustomEditorOperator customizer = new ClasspathCustomEditorOperator(
178: propertyCustomizer);
179:
180: if (propertyValue_L.startsWith(ADDDIRECTORY)) {
181: err.println("========== ADDING DIRECTORY =======");
182: customizer.addDirectory(getPath(propertyValue_L,
183: ADDDIRECTORY));
184: }
185:
186: if (propertyValue_L.startsWith(ADDJAR)) {
187: err.println("========== ADDING JAR =======");
188: // customizer.addJARZIP(getPath(propertyValue_L, ADDJAR));
189: // hack because previously code fails
190: FileCustomEditorOperator editor = customizer.addJARZIP();
191: editor.fileChooser().chooseFile(
192: getPath(propertyValue_L, ADDJAR));
193: customizer.ok();
194: }
195:
196: if (propertyValue_L.startsWith(REMOVE)) {
197: err.println("========== REMOVE =======");
198: customizer.remove(getPath(propertyValue_L, REMOVE));
199: }
200:
201: if (propertyValue_L.startsWith(UP)) {
202: err.println("========== UP =======");
203: customizer.lstClasspath().selectItem(
204: getPath(propertyValue_L, UP));
205: customizer.moveUp();
206: }
207:
208: if (propertyValue_L.startsWith(DOWN)) {
209: err.println("========== DOWN =======");
210: customizer.lstClasspath().selectItem(
211: getPath(propertyValue_L, DOWN));
212: customizer.moveDown();
213: }
214:
215: }
216:
217: public void verifyPropertyValue(boolean expectation) {
218: verifyExpectationValue(propertyName_L, expectation,
219: propertyValueExpectation_L, propertyValue_L, waitDialog);
220: }
221:
222: private String getPath(String str, String delim) {
223: int index = str.indexOf(delim);
224:
225: if (index > -1)
226: return str.substring(index + delim.length());
227:
228: return str;
229: }
230:
231: public void verifyCustomizerLayout() {
232: ClasspathCustomEditorOperator customizer = new ClasspathCustomEditorOperator(
233: propertyCustomizer);
234: customizer.verify();
235: customizer.btOK();
236: customizer.btCancel();
237: }
238:
239: /** Test could be executed internaly in Forte without XTest
240: * @param args arguments from command line
241: */
242: public static void main(String[] args) {
243: //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_NbClassPath.class));
244: junit.textui.TestRunner.run(suite());
245: }
246:
247: }
|