KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > persistence > TCRefParserTest


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 package org.netbeans.core.windows.persistence;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import org.netbeans.junit.NbTest;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29
30 import org.netbeans.core.windows.persistence.TCRefConfig;
31
32 import org.openide.ErrorManager;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.URLMapper;
35
36 /** Functionality tests for saving and loading TCRef configuration data
37  *
38  * @author Marek Slama
39  */

40 public class TCRefParserTest extends NbTestCase {
41     
42     public TCRefParserTest() {
43         super("");
44     }
45     
46     public TCRefParserTest(java.lang.String JavaDoc testName) {
47         super(testName);
48     }
49     
50     public static void main(java.lang.String JavaDoc[] args) {
51         junit.textui.TestRunner.run(suite());
52     }
53     
54     public static NbTest suite() {
55         NbTestSuite suite = new NbTestSuite(TCRefParserTest.class);
56         return suite;
57     }
58
59     protected void setUp () throws Exception JavaDoc {
60     }
61     
62     ////////////////////////////////
63
//Testing CORRECT data
64
////////////////////////////////
65
/** Test of loaded data
66      */

67     public void testLoadTCRef00 () throws Exception JavaDoc {
68         System.out.println("");
69         System.out.println("TCRefParserTest.testLoadTCRef00 START");
70         
71         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref00");
72         
73         TCRefConfig tcRefCfg = tcRefParser.load();
74         
75         //Check loaded data
76
assertNotNull("Could not load data.", tcRefCfg);
77         
78         assertTrue("TopComponent is opened.", tcRefCfg.opened);
79         
80         System.out.println("TCRefParserTest.testLoadTCRef00 FINISH");
81     }
82     
83     /** Test of loaded data
84      */

85     public void testLoadTCRef01 () throws Exception JavaDoc {
86         System.out.println("");
87         System.out.println("TCRefParserTest.testLoadTCRef01 START");
88         
89         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref01");
90         
91         TCRefConfig tcRefCfg = tcRefParser.load();
92         
93         //Check loaded data
94
assertNotNull("Could not load data.", tcRefCfg);
95         
96         assertFalse("TopComponent is closed.", tcRefCfg.opened);
97         
98         System.out.println("TCRefParserTest.testLoadTCRef01 FINISH");
99     }
100     
101     /** Test of loaded data
102      */

103     public void testLoadTCRef03 () throws Exception JavaDoc {
104         System.out.println("");
105         System.out.println("TCRefParserTest.testLoadTCRef03 START");
106         
107         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref03");
108         
109         TCRefConfig tcRefCfg = tcRefParser.load();
110         
111         //Check loaded data
112
assertNotNull("Could not load data.", tcRefCfg);
113         
114         assertFalse("TopComponent is closed.", tcRefCfg.opened);
115         
116         assertEquals("Previous mode.", "explorer", tcRefCfg.previousMode);
117         assertEquals("Tab index in previous mode.", 2, tcRefCfg.previousIndex);
118         
119         assertTrue("TopComponent is docked in maximized mode.", tcRefCfg.dockedInMaximizedMode);
120         assertFalse("TopComponent is slided-out in default mode.", tcRefCfg.dockedInDefaultMode);
121         
122         assertTrue("TopComponent is maximized when slided-in.", tcRefCfg.slidedInMaximized);
123         
124         System.out.println("TCRefParserTest.testLoadTCRef03 FINISH");
125     }
126     
127     /** Test of saving
128      */

129     public void testSaveTCRef00 () throws Exception JavaDoc {
130         System.out.println("");
131         System.out.println("TCRefParserTest.testSaveTCRef00 START");
132         
133         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref00");
134         
135         TCRefConfig tcRefCfg1 = tcRefParser.load();
136         
137         tcRefParser.save(tcRefCfg1);
138         
139         TCRefConfig tcRefCfg2 = tcRefParser.load();
140         
141         //Compare data
142
assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2));
143                 
144         System.out.println("TCRefParserTest.testSaveTCRef00 FINISH");
145     }
146     
147     /** Test of saving
148      */

149     public void testSaveTCRef01 () throws Exception JavaDoc {
150         System.out.println("");
151         System.out.println("TCRefParserTest.testSaveTCRef01 START");
152         
153         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref01");
154         
155         TCRefConfig tcRefCfg1 = tcRefParser.load();
156         
157         tcRefParser.save(tcRefCfg1);
158         
159         TCRefConfig tcRefCfg2 = tcRefParser.load();
160         
161         //Compare data
162
assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2));
163         
164         System.out.println("TCRefParserTest.testSaveTCRef01 FINISH");
165     }
166     
167     /** Test of saving with ugly nasty special characters like & and '
168      */

169     public void testSaveTCRef02 () throws Exception JavaDoc {
170         System.out.println("");
171         System.out.println("TCRefParserTest.testSaveTCRef02 START");
172         
173         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref02&'");
174         
175         TCRefConfig tcRefCfg1 = tcRefParser.load();
176         
177         tcRefParser.save(tcRefCfg1);
178         
179         TCRefConfig tcRefCfg2 = tcRefParser.load();
180 System.out.println("tcrefcfg1: " + tcRefCfg1);
181 System.out.println("tcrefcfg2: " + tcRefCfg2);
182         //Compare data
183
assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2));
184         
185         System.out.println("TCRefParserTest.testSaveTCRef02 FINISH");
186     }
187     
188     public void testSaveTCRef03 () throws Exception JavaDoc {
189         System.out.println("");
190         System.out.println("TCRefParserTest.testSaveTCRef03 START");
191         
192         TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref03");
193         
194         TCRefConfig tcRefCfg1 = tcRefParser.load();
195         
196         tcRefParser.save(tcRefCfg1);
197         
198         TCRefConfig tcRefCfg2 = tcRefParser.load();
199         
200         //Compare data
201
assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2));
202         
203         System.out.println("TCRefParserTest.testSaveTCRef03 FINISH");
204     }
205     
206     ////////////////////////////////
207
//Testing INCORRECT data
208
////////////////////////////////
209
/** Test of missing file
210      */

211     public void testLoadTCRef00Invalid () throws Exception JavaDoc {
212         System.out.println("");
213         System.out.println("TCRefParserTest.testLoadTCRef00Invalid START");
214         
215         TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref00");
216         
217         try {
218             tcRefParser.load();
219         } catch (FileNotFoundException JavaDoc exc) {
220             //Missing file detected
221
//ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
222
System.out.println("TCRefParserTest.testLoadTCRef00Invalid FINISH");
223             return;
224         }
225         
226         fail("Missing file was not detected.");
227     }
228     
229     /** Test of empty file
230      */

231     public void testLoadTCRef01Invalid () throws Exception JavaDoc {
232         System.out.println("");
233         System.out.println("TCRefParserTest.testLoadTCRef01Invalid START");
234         
235         TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref01");
236         
237         try {
238             tcRefParser.load();
239         } catch (IOException JavaDoc exc) {
240             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
241
System.out.println("TCRefParserTest.testLoadTCRef01Invalid FINISH");
242             return;
243         }
244         
245         fail("Empty file was not detected.");
246     }
247     
248     /** Test of missing required attribute "id" of element "properties".
249      */

250     public void testLoadTCRef02Invalid () throws Exception JavaDoc {
251         System.out.println("");
252         System.out.println("TCRefParserTest.testLoadTCRef02Invalid START");
253         
254         TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref02");
255         
256         try {
257             tcRefParser.load();
258         } catch (IOException JavaDoc exc) {
259             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
260
System.out.println("TCRefParserTest.testLoadTCRef02Invalid FINISH");
261             return;
262         }
263         
264         fail("Missing required attribute \"id\" of element \"properties\" was not detected.");
265     }
266     
267     /** Test of file name and "id" mismatch.
268      */

269     public void testLoadTCRef03Invalid () throws Exception JavaDoc {
270         System.out.println("");
271         System.out.println("TCRefParserTest.testLoadTCRef03Invalid START");
272         
273         TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref03");
274         
275         try {
276             tcRefParser.load();
277         } catch (IOException JavaDoc exc) {
278             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
279
System.out.println("TCRefParserTest.testLoadTCRef03Invalid FINISH");
280             return;
281         }
282         
283         fail("Mismatch of file name and value of attribute \"id\" of element \"properties\" was not detected.");
284     }
285     
286     private TCRefParser createRefParser (String JavaDoc path, String JavaDoc name) {
287         URL JavaDoc url;
288         url = TCRefParserTest.class.getResource(path);
289         assertNotNull("url not found.",url);
290         
291         FileObject [] foArray = URLMapper.findFileObjects(url);
292         assertNotNull("Test parent folder not found. Array is null.",foArray);
293         assertTrue("Test parent folder not found. Array is empty.",foArray.length > 0);
294         
295         FileObject parentFolder = foArray[0];
296         assertNotNull("Test parent folder not found. ParentFolder is null.",parentFolder);
297         
298         TCRefParser tcRefParser = new TCRefParser(name);
299         tcRefParser.setInLocalFolder(true);
300         tcRefParser.setLocalParentFolder(parentFolder);
301         
302         return tcRefParser;
303     }
304     
305 }
306
Popular Tags