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: /*
043: * DataLoaderPoolTest_find.java
044: *
045: * Tests access to DataObject - recognizing, finding etc.
046: *
047: * Created on June 22, 2001, 12:25 PM
048: */
049:
050: package DataLoaderTests.LoaderPoolTest;
051:
052: import junit.framework.*;
053: import org.netbeans.junit.*;
054:
055: public class DataLoaderPoolTest_find extends NbTestCase {
056:
057: /** Creates new DataLoaderPoolTest_find */
058: public DataLoaderPoolTest_find(java.lang.String testName) {
059: super (testName);
060: }
061:
062: /**Allows this test to be executed inside ide*/
063: public static void main(java.lang.String[] args) {
064: junit.textui.TestRunner.run(suite());
065: }
066:
067: /**This suite*/
068: public static Test suite() {
069: NbTestSuite suite = new NbTestSuite(
070: DataLoaderPoolTest_find.class);
071: return suite;
072: }
073:
074: static boolean successful = true;
075: static org.openide.loaders.DataLoader textdl = null;
076: LoaderPoolTest LPT = null;
077:
078: /**
079: *Performs initializing before own tests starts
080: */
081: void prepare() {
082: try {
083: //when not in XTest harness -> woring directory will be under actual userdir
084: if (Manager.getWorkDirPath() == null)
085: System.setProperty("nbjunit.workdir", System
086: .getProperty("netbeans.user"));
087: //clearWorkDir();
088: LPT = new LoaderPoolTest(getName());
089: //now setting workdir - this class will write nothing into the logs, only the utility class should,
090: //however into location for this class
091: LPT.work = ""
092: + Manager.getWorkDirPath()
093: + java.io.File.separator
094: + this .getClass().getName().replace('.',
095: java.io.File.separatorChar)
096: + java.io.File.separator + getName();
097: LPT.prepare();
098: textdl = LPT.getDataLoader("Textual");
099: LPT.textdl = textdl;
100: } catch (Exception e) {
101: e.printStackTrace();
102: e.printStackTrace(getRef());
103: assertTrue("Initialization of test failed! ->" + e, false);
104: }
105: }
106:
107: /**
108: *Performs clean up
109: */
110: void clean() {
111: LPT.clean();
112: }
113:
114: /**
115: *Performs waiting of current thread for time in millis
116: *@param millist integer number - time in millis to wait
117: */
118: void dummyWait(int millis) {
119: try {
120: Thread.sleep(millis);
121: } catch (Exception ex) {
122: LPT.printException(ex);
123: }
124: }
125:
126: /**Own test:
127: * Asks for DataObjects, asks for its type, removes DataLoader
128: * Asks again for the same and new DataObject, adds DataLoader back, asks again
129: */
130: public void testDLPFind() {
131:
132: String file1 = new LoaderPoolTest("x").getClass().getPackage()
133: .getName().replace('.', '/')
134: + "/textfile3.txt";
135: String file2 = new LoaderPoolTest("x").getClass().getPackage()
136: .getName().replace('.', '/')
137: + "/textfile4.txt";
138: System.out.println("file1:" + file1);
139: System.out.println("file2:" + file2);
140: try {
141: prepare();
142: LPT.writeRef(new LoaderPoolTest("x").getClass().getName());
143: LPT.existDataObject(file1);
144: LPT.recognizedAs(file1, textdl.getDisplayName());
145: LPT.removeDataLoader(textdl);
146: dummyWait(5000);
147: if (LPT.noOfChanges != 1) {
148: LPT
149: .writeRef(
150: "Not registered change event over DataLoaderPool!",
151: FAILED);
152: //LPT.writeRef(FAILED);
153: }
154: LPT.existDataObject(file1);
155: //test the bug with dataloaderpoolrefresh
156: LPT.notRecognizedAs(file1, textdl.getDisplayName());
157: //should pass (not recognized as text)
158: LPT.existDataObject(file2);
159: LPT.notRecognizedAs(file2, textdl.getDisplayName());
160: LPT.addDataLoader("org.netbeans.modules.text");
161: dummyWait(5000);
162: if (LPT.noOfChanges != 2) {
163: LPT
164: .writeRef(
165: "Not registered change event over DataLoaderPool!",
166: FAILED);
167: //LPT.writeRef(FAILED);
168: }
169: LPT.existDataObject(file1);
170: LPT.recognizedAs(file1, textdl.getDisplayName());
171: LPT.recognizedAs(file2, textdl.getDisplayName());
172: clean();
173: //do not forget to merge the results!
174: successful = successful && LPT.successful;
175: System.out.println("\n" + successful);
176: } catch (Throwable ee) {
177: ee.printStackTrace(getRef());
178: ee.printStackTrace();
179: LPT.writeRef(FAILED);
180: }
181:
182: assertTrue("Find test failed!", successful);
183:
184: }
185:
186: //if you want print exceptions into log file, put here true.
187: public static final boolean PRINT_EXCEPTIONS = true;
188:
189: public static final String PASSED = "passed.\n";
190: public static final String FAILED = "failed.\n";
191: }
|