KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DataLoaderTests > LoaderPoolTest > DataLoaderPoolTest_create


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_create.java
22  *
23  * Tests creation and recognization of DataObjects.
24  *
25  * Created on June 22, 2001, 12:26 PM
26  */

27
28 package DataLoaderTests.LoaderPoolTest;
29
30 import junit.framework.*;
31 import org.netbeans.junit.*;
32
33 public class DataLoaderPoolTest_create extends NbTestCase {
34
35     /** Creates new DataLoaderPoolTest_create */
36     public DataLoaderPoolTest_create(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_create.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      *Creates DataObject, Creates again with failure, removes DataLoader, sweep memory
101      *Creates again, creates new DataObject, adds Loader back, creates both DataObjects again
102      */

103     public void testDLPCreate() {
104         
105         String JavaDoc file1 = new LoaderPoolTest("x").getClass().getPackage().getName().replace('.','/') + "/textfile1.txt";
106         String JavaDoc file2 = new LoaderPoolTest("x").getClass().getPackage().getName().replace('.','/') + "/textfile2.txt";
107         
108         try{
109             prepare();
110             LPT.writeRef(new LoaderPoolTest("x").getClass().getName());
111             LPT.createDataObject(file1,textdl);
112             LPT.notCreateDataObject(file1,textdl);
113             LPT.removeDataLoader(textdl);
114             dummyWait(5000);
115             if ( LPT.noOfChanges != 1 ) {
116                 LPT.writeRef("Not registered change event over DataLoaderPool!",FAILED);
117                 //LPT.writeRef(FAILED);
118
}
119             LPT.eatMemory(2000);
120             LPT.sweepMemory();
121             
122             //LPT.notCreateDataObject(file1,textdl);
123
//created data objects aren't referenced any more, and the DataLoader
124
//was removed from LoderPool, so creation should be successful
125
LPT.createDataObject(file1,textdl);
126             
127             LPT.createDataObject(file2,textdl);
128             LPT.addDataLoader("org.netbeans.modules.text");
129             dummyWait(5000);
130             if ( LPT.noOfChanges != 2 ) {
131                 LPT.writeRef("Not registered change event over DataLoaderPool!",FAILED);
132                 //LPT.writeRef(FAILED);
133
}
134             LPT.eatMemory(2000);
135             LPT.sweepMemory();
136             
137             //LPT.notCreateDataObject(file1,textdl);
138
//LPT.notCreateDataObject(file2,textdl);
139
//the same reason as above
140
LPT.createDataObject(file1,textdl);
141             LPT.createDataObject(file2,textdl);
142             
143             clean();
144             //do not forget to merge the results!
145
successful = successful && LPT.successful;
146             System.out.println("\n" + successful );
147         }catch(Throwable JavaDoc ee){
148             ee.printStackTrace(getRef());
149             ee.printStackTrace();
150             LPT.writeRef(FAILED);
151         }
152         
153         assertTrue("Create test failed!",successful);
154
155     }
156     
157     //if you want print exceptions into log file, put here true.
158
public static final boolean PRINT_EXCEPTIONS = true;
159     
160     public static final String JavaDoc PASSED = "passed.\n";
161     public static final String JavaDoc FAILED = "failed.\n";
162 }
163
Popular Tags