KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.URLMapper;
31
32 /** Functionality tests for saving and loading Group configuration data
33  *
34  * @author Marek Slama
35  */

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

63     public void testLoadGroup01 () throws Exception JavaDoc {
64         System.out.println("");
65         System.out.println("GroupParserTest.testLoadGroup01 START");
66         
67         GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group01");
68         
69         GroupConfig groupCfg = groupParser.load();
70         
71         //Check loaded data
72
assertNotNull("Could not load data.",groupCfg);
73         
74         InternalConfig internalCfg = groupParser.getInternalConfig();
75         
76         assertNotNull("Could not load internal data.",internalCfg);
77         
78         //Check internal data
79
assertEquals("moduleCodeNameBase","org.netbeans.modules.form",internalCfg.moduleCodeNameBase);
80         assertEquals("moduleCodeNameBase","2",internalCfg.moduleCodeNameRelease);
81         assertEquals("moduleCodeNameBase","1.7",internalCfg.moduleSpecificationVersion);
82         
83         assertTrue("opened",groupCfg.opened);
84         
85         System.out.println("GroupParserTest.testLoadGroup01 FINISH");
86     }
87     
88     /** Test of loaded data
89      */

90     public void testLoadGroup02 () throws Exception JavaDoc {
91         System.out.println("");
92         System.out.println("GroupParserTest.testLoadGroup02 START");
93         
94         GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group02");
95         
96         GroupConfig groupCfg = groupParser.load();
97         
98         //Check loaded data
99
assertNotNull("Could not load data.",groupCfg);
100         
101         InternalConfig internalCfg = groupParser.getInternalConfig();
102         
103         assertNotNull("Could not load internal data.",internalCfg);
104         
105         //Check internal data
106
assertEquals("moduleCodeNameBase","org.netbeans.modules.form",internalCfg.moduleCodeNameBase);
107         assertEquals("moduleCodeNameBase","2",internalCfg.moduleCodeNameRelease);
108         assertEquals("moduleCodeNameBase","1.7",internalCfg.moduleSpecificationVersion);
109         
110         assertFalse("opened",groupCfg.opened);
111         
112         System.out.println("GroupParserTest.testLoadGroup02 FINISH");
113     }
114     
115     /** Test of saving
116      */

117     public void testSaveGroup01 () throws Exception JavaDoc {
118         System.out.println("");
119         System.out.println("GroupParserTest.testSaveGroup01 START");
120         
121         GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group01");
122         
123         GroupConfig groupCfg1 = groupParser.load();
124         
125         groupParser.save(groupCfg1);
126         
127         GroupConfig groupCfg2 = groupParser.load();
128         
129         //Compare data
130
assertTrue("Compare configuration data",groupCfg1.equals(groupCfg2));
131                 
132         System.out.println("GroupParserTest.testSaveGroup01 FINISH");
133     }
134     
135     /** Test of saving
136      */

137     public void testSaveGroup02 () throws Exception JavaDoc {
138         System.out.println("");
139         System.out.println("GroupParserTest.testSaveGroup02 START");
140         
141         GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group02");
142         
143         GroupConfig groupCfg1 = groupParser.load();
144         
145         groupParser.save(groupCfg1);
146         
147         GroupConfig groupCfg2 = groupParser.load();
148         
149         //Compare data
150
assertTrue("Compare configuration data",groupCfg1.equals(groupCfg2));
151                 
152         System.out.println("GroupParserTest.testSaveGroup02 FINISH");
153     }
154     
155     ////////////////////////////////
156
//Testing INVALID data
157
////////////////////////////////
158
/** Test of missing file
159      */

160     public void testLoadGroup01Invalid () throws Exception JavaDoc {
161         System.out.println("");
162         System.out.println("GroupParserTest.testLoadGroup01Invalid START");
163         
164         GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group01");
165         
166         try {
167             groupParser.load();
168         } catch (FileNotFoundException JavaDoc exc) {
169             //Missing file detected
170
//ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
171
System.out.println("GroupParserTest.testLoadGroup01Invalid FINISH");
172             return;
173         }
174         
175         fail("Missing file was not detected.");
176     }
177     
178     /** Test of empty file
179      */

180     public void testLoadGroup02Invalid () throws Exception JavaDoc {
181         System.out.println("");
182         System.out.println("GroupParserTest.testLoadGroup02Invalid START");
183         
184         GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group02");
185         
186         try {
187             groupParser.load();
188         } catch (IOException JavaDoc exc) {
189             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
190
System.out.println("GroupParserTest.testLoadGroup02Invalid FINISH");
191             return;
192         }
193         
194         fail("Empty file was not detected.");
195     }
196     
197     /** Test of missing required attribute "unique" of element "name".
198      */

199     public void testLoadGroup03Invalid () throws Exception JavaDoc {
200         System.out.println("");
201         System.out.println("GroupParserTest.testLoadGroup03Invalid START");
202         
203         GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group03");
204         
205         try {
206             groupParser.load();
207         } catch (IOException JavaDoc exc) {
208             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
209
System.out.println("GroupParserTest.testLoadGroup03Invalid FINISH");
210             return;
211         }
212         
213         fail("Missing required attribute \"name\" of element \"properties\" was not detected.");
214     }
215     
216     /** Test of file name and value of attribute "unique" mismatch.
217      */

218     public void testLoadGroup04Invalid () throws Exception JavaDoc {
219         System.out.println("");
220         System.out.println("GroupParserTest.testLoadGroup04Invalid START");
221         
222         GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group04");
223         
224         try {
225             groupParser.load();
226         } catch (IOException JavaDoc exc) {
227             //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
228
System.out.println("GroupParserTest.testLoadGroup04Invalid FINISH");
229             return;
230         }
231         
232         fail("Mismatch of file name and value of attribute \"name\" of element \"properties\" was not detected.");
233     }
234     
235     private GroupParser createGroupParser (String JavaDoc path, String JavaDoc name) {
236         URL JavaDoc url;
237         url = GroupParserTest.class.getResource(path);
238         assertNotNull("url not found.",url);
239         
240         FileObject parentFolder = URLMapper.findFileObject(url);
241         assertNotNull("Test parent folder not found. ParentFolder is null. for " + url, parentFolder);
242         
243         GroupParser groupParser = new GroupParser(name);
244         groupParser.setInLocalFolder(true);
245         groupParser.setLocalParentFolder(parentFolder);
246         
247         return groupParser;
248     }
249     
250 }
251
Popular Tags