KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DataLoaderTests > LoaderPoolTest > DataLoaderPoolTest_find


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 /*
21  * DataLoaderPoolTest_find.java
22  *
23  * Tests access to DataObject - recognizing, finding etc.
24  *
25  * Created on June 22, 2001, 12:25 PM
26  */

27
28 package DataLoaderTests.LoaderPoolTest;
29
30 import junit.framework.*;
31 import org.netbeans.junit.*;
32
33 public class DataLoaderPoolTest_find extends NbTestCase {
34
35     /** Creates new DataLoaderPoolTest_find */
36     public DataLoaderPoolTest_find(java.lang.String JavaDoc testName) {
37         super(testName);
38     }
39
40     /**Allows this test to be executed inside ide*/
41     public static void main(java.lang.String JavaDoc[] args) {
42         junit.textui.TestRunner.run(suite());
43     }
44     
45     /**This suite*/
46     public static Test suite() {
47         NbTestSuite suite = new NbTestSuite(DataLoaderPoolTest_find.class);
48         return suite;
49     }
50     
51     static boolean successful = true;
52     static org.openide.loaders.DataLoader textdl = null;
53     LoaderPoolTest LPT = null;
54             
55     /**
56      *Performs initializing before own tests starts
57      */

58     void prepare() {
59         try {
60             //when not in XTest harness -> woring directory will be under actual userdir
61
if (Manager.getWorkDirPath()==null) System.setProperty("nbjunit.workdir",System.getProperty("netbeans.user"));
62             //clearWorkDir();
63
LPT = new LoaderPoolTest(getName());
64             //now setting workdir - this class will write nothing into the logs, only the utility class should,
65
//however into location for this class
66
LPT.work = ""+
67                 Manager.getWorkDirPath()+
68                 java.io.File.separator + this.getClass().getName().replace('.',java.io.File.separatorChar)+
69                 java.io.File.separator + getName();
70             LPT.prepare();
71             textdl = LPT.getDataLoader("Textual");
72             LPT.textdl = textdl;
73         } catch (Exception JavaDoc e) {
74             e.printStackTrace();
75             e.printStackTrace(getRef());
76             assertTrue("Initialization of test failed! ->" + e,false);
77         }
78     }
79     
80     /**
81      *Performs clean up
82      */

83     void clean() {
84         LPT.clean();
85     }
86     
87     /**
88      *Performs waiting of current thread for time in millis
89      *@param millist integer number - time in millis to wait
90      */

91     void dummyWait(int millis) {
92         try {
93             Thread.sleep(millis);
94         } catch (Exception JavaDoc ex) {
95             LPT.printException(ex);
96         }
97     }
98     
99     /**Own test:
100      * Asks for DataObjects, asks for its type, removes DataLoader
101      * Asks again for the same and new DataObject, adds DataLoader back, asks again
102      */

103     public void testDLPFind() {
104         
105         String JavaDoc file1 = new LoaderPoolTest("x").getClass().getPackage().getName().replace('.','/') + "/textfile3.txt";
106         String JavaDoc file2 = new LoaderPoolTest("x").getClass().getPackage().getName().replace('.','/') + "/textfile4.txt";
107         System.out.println("file1:" + file1);
108         System.out.println("file2:" + file2);
109         try{
110             prepare();
111             LPT.writeRef(new LoaderPoolTest("x").getClass().getName());
112             LPT.existDataObject(file1);
113             LPT.recognizedAs(file1,textdl.getDisplayName());
114             LPT.removeDataLoader(textdl);
115             dummyWait(5000);
116             if ( LPT.noOfChanges != 1 ) {
117                 LPT.writeRef("Not registered change event over DataLoaderPool!",FAILED);
118                 //LPT.writeRef(FAILED);
119
}
120             LPT.existDataObject(file1);
121             //test the bug with dataloaderpoolrefresh
122
LPT.notRecognizedAs(file1,textdl.getDisplayName());
123             //should pass (not recognized as text)
124
LPT.existDataObject(file2);
125             LPT.notRecognizedAs(file2,textdl.getDisplayName());
126             LPT.addDataLoader("org.netbeans.modules.text");
127             dummyWait(5000);
128             if ( LPT.noOfChanges != 2 ) {
129                 LPT.writeRef("Not registered change event over DataLoaderPool!",FAILED);
130                 //LPT.writeRef(FAILED);
131
}
132             LPT.existDataObject(file1);
133             LPT.recognizedAs(file1,textdl.getDisplayName());
134             LPT.recognizedAs(file2,textdl.getDisplayName());
135             clean();
136             //do not forget to merge the results!
137
successful = successful && LPT.successful;
138             System.out.println("\n" + successful );
139         }catch(Throwable JavaDoc ee){
140             ee.printStackTrace(getRef());
141             ee.printStackTrace();
142             LPT.writeRef(FAILED);
143         }
144         
145         assertTrue("Find test failed!",successful);
146
147     }
148     
149     //if you want print exceptions into log file, put here true.
150
public static final boolean PRINT_EXCEPTIONS = true;
151     
152     public static final String JavaDoc PASSED = "passed.\n";
153     public static final String JavaDoc FAILED = "failed.\n";
154 }
155
Popular Tags