KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > xml2mi > lib > EmptyObject


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.xml2mi.lib;
25
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28 import junit.framework.TestSuite;
29 import junit.textui.TestRunner;
30 import org.objectweb.jorm.metainfo.api.Manager;
31 import org.objectweb.jorm.metainfo.lib.JormManager;
32 import org.objectweb.jorm.xml2mi.api.Parser;
33 import org.objectweb.jorm.util.lib.BasicClassLoader;
34 import org.objectweb.jorm.util.lib.CompilerLogger;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.api.Logger;
37 import org.objectweb.jorm.compiler.lib.Compiler;
38 import org.objectweb.jorm.cmdline.api.CmdLineParser;
39
40 import java.util.Vector JavaDoc;
41
42 /**
43  * The EmptyObject testcase tests cases when object are empty but works for
44  * the dtd parsing. In a first time, all these tests fail, because the verifier
45  * is not yet implemented. When this part will be done all these tests must
46  * work well.
47  * Tested objects are :<ul>
48  * <li>Class
49  * <li>GenClass
50  * <li>PrimitiveField
51  * <li>a Mapping without Rdb part
52  * <li>an Rdb Mapping without Column object
53  * <li>NameDef
54  * <li>NameDef and ClassMapping
55  * <li>Package
56  * <li>ScalarField without Mapping
57  * </ul>
58  * @author X. Spengler
59  */

60 public class EmptyObject extends TestCase {
61
62     /**
63      * prefix defines the path to the persistence description files
64      */

65     private static String JavaDoc prefix =
66             "test/deviance/org/objectweb/jorm/parser/lib/";
67
68     /**
69      * properties defines the name of the jorm properties file
70      */

71     private static String JavaDoc properties =
72             prefix + "jorm.properties";
73
74     /**
75      * mapperOption defines the name of the class which manages the mapper
76      * option
77      */

78     private static String JavaDoc mapperOption =
79             "org.objectweb.jorm.cmdline.rdb.RdbMapperOption";
80
81     /**
82      * dbprop defines the name of the property which manages the name of the
83      * database
84      */

85     private static String JavaDoc dbprop = "DBName";
86
87     /**
88      * dbname defines the name of the database
89      */

90     private static String JavaDoc dbname = "postgres";
91
92     /**
93      * Builds a new EmptyObject testcase object
94      */

95     public EmptyObject(String JavaDoc name) {
96         super(name);
97     }
98
99     /**
100      * main method to launch the tests manually
101      */

102     public static void main(String JavaDoc[] args) {
103         TestRunner.run(suite());
104     }
105
106     /**
107      * Sets up the current test.
108      */

109     protected void setUp() {
110     }
111
112     /**
113      * Creates a TestSuite object with the current tests
114      */

115     public static Test suite() {
116         return new TestSuite(EmptyObject.class);
117     }
118
119     /**
120      * Tests when the Class is empty, just the declaration.
121      */

122     public void testEmptyClass() {
123         try {
124             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
125             comp.addInputFileName(prefix+"EmptyClass.pd");
126             CmdLineParser clp = (CmdLineParser)
127                     comp.getClassLoader().load(mapperOption);
128             comp.getCompilerParameter().addCPExtension(
129                     mapperOption,clp);
130
131             clp.parseProperty(dbprop, dbname);
132             assertTrue("an empty Class does not work", comp.execute());
133         } catch (Exception JavaDoc e) {
134
135         }
136
137
138     }
139
140     /**
141      * Tests when the GenClass is empty, just the declaration.
142      */

143     public void testEmptyGenClass() {
144         try {
145             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
146             comp.addInputFileName(prefix+"EmptyGenClass.pd");
147
148             CmdLineParser clp = (CmdLineParser)
149                     comp.getClassLoader().load(mapperOption);
150             comp.getCompilerParameter().addCPExtension(
151                     mapperOption,clp);
152
153             clp.parseProperty(dbprop, dbname);
154             assertTrue("an empty GenClass does not work", comp.execute());
155         } catch (Exception JavaDoc e) {
156
157         }
158     }
159
160     /**
161      * Tests when the PrimitiveType is empty, just the definition of the class,
162      * and the declaration of the field.
163      */

164     public void testEmptyPrimitiveType() {
165         try {
166             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
167             comp.addInputFileName(prefix+"EmptyPrimitiveType.pd");
168
169             CmdLineParser clp = (CmdLineParser)
170                     comp.getClassLoader().load(mapperOption);
171             comp.getCompilerParameter().addCPExtension(
172                     mapperOption,clp);
173
174             clp.parseProperty(dbprop, dbname);
175             assertTrue("an empty PrimitiveType does not work", comp.execute());
176         } catch (Exception JavaDoc e) {
177
178         }
179     }
180
181     /**
182      * Tests when a Mapping is created without reference to the name of the
183      * mapping (rdb).
184      * The parser does not return an error, but the verifier must verify this
185      * section. A Class is created, a Field is declared, and a PrimitiveType is
186      * created with only the declaration of the ValueMapping.
187      */

188     public void testMappingWithoutRdb() {
189         try {
190             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
191             comp.addInputFileName(prefix+"MappingWithoutRdb.pd");
192
193             CmdLineParser clp = (CmdLineParser)
194                     comp.getClassLoader().load(mapperOption);
195             comp.getCompilerParameter().addCPExtension(
196                     mapperOption,clp);
197
198             clp.parseProperty(dbprop, dbname);
199             assertTrue("A ValueMapping without RdbValueMapping does not work",
200                     comp.execute());
201         } catch (Exception JavaDoc e) {
202
203         }
204     }
205
206     /**
207      * Tests when a rdbMapping is created without the corresponding Column tag.
208      * The parser does not return an error, but the Verifier module must verify
209      * this section.
210      * A Class is created, a Field is declared with a PrimitiveType, a
211      * ValueMapping is associated with a RdbValueMapping but no ColumnSpec.
212      */

213     public void testRdbMappingWithoutColumn() {
214         try {
215             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
216             comp.addInputFileName(prefix+"RdbMappingWithoutColumn.pd");
217
218             CmdLineParser clp = (CmdLineParser)
219                     comp.getClassLoader().load(mapperOption);
220             comp.getCompilerParameter().addCPExtension(
221                     mapperOption,clp);
222
223             clp.parseProperty(dbprop, dbname);
224             assertTrue("An RdbValueMapping without RdbColumnSpec does not work",
225                     comp.execute());
226         } catch (Exception JavaDoc e) {
227
228         }
229     }
230
231     /**
232      * Tests when no NameDef object are declared for a Class.
233      * The parser does not return an error, but the Verifier must verify this
234      * section.
235      */

236     public void testWithoutNameDef() {
237         try {
238             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
239             comp.addInputFileName(prefix+"WithoutNameDef.pd");
240
241             CmdLineParser clp = (CmdLineParser)
242                     comp.getClassLoader().load(mapperOption);
243             comp.getCompilerParameter().addCPExtension(
244                     mapperOption,clp);
245
246             clp.parseProperty(dbprop, dbname);
247             assertTrue("Without NameDef does not work", comp.execute());
248         } catch (Exception JavaDoc e) {
249
250         }
251     }
252
253     /**
254      * Tests when no NameDef and ClassMapping are declared for a given Class.
255      * The parser does not return an error, but the Verifier must verify this
256      * section.
257      */

258     public void testWithoutNameDefClassMapping() {
259         try {
260             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
261             comp.addInputFileName(prefix+"WithoutNameDefClassMapping.pd");
262
263             CmdLineParser clp = (CmdLineParser)
264                     comp.getClassLoader().load(mapperOption);
265             comp.getCompilerParameter().addCPExtension(
266                     mapperOption,clp);
267
268             clp.parseProperty(dbprop, dbname);
269             assertTrue("Without NameDef and ClassMapping does not work",
270                     comp.execute());
271         } catch (Exception JavaDoc e) {
272
273         }
274     }
275
276     /**
277      * Tests when the Package is not specified in the persistence description
278      * file.
279      */

280     public void testWithoutSchema() {
281         try {
282             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
283             comp.addInputFileName(prefix+"WithoutSchema.pd");
284
285             CmdLineParser clp = (CmdLineParser)
286                     comp.getClassLoader().load(mapperOption);
287             comp.getCompilerParameter().addCPExtension(
288                     mapperOption,clp);
289
290             clp.parseProperty(dbprop, dbname);
291             assertTrue("Without Package does not work", comp.execute());
292         } catch (Exception JavaDoc e) {
293
294         }
295     }
296
297     /**
298      * Tests when a GenClass is defined by a ScalarField and the corresponding
299      * mapping is not specified.
300      * The parser module does not return an error, but the verifier has to
301      * verify it.
302      */

303     public void testScalarWithoutMapping() {
304         try {
305             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
306             comp.addInputFileName(prefix+"ScalarWithoutMapping.pd");
307
308             CmdLineParser clp = (CmdLineParser)
309                     comp.getClassLoader().load(mapperOption);
310             comp.getCompilerParameter().addCPExtension(
311                     mapperOption,clp);
312
313             clp.parseProperty(dbprop, dbname);
314             assertTrue("ScalarField Without ValueMapping does not work", comp.execute());
315         } catch (Exception JavaDoc e) {
316
317         }
318     }
319 }
320
Popular Tags