KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > verifier > VerifierCentral


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.verifier;
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 VerifierCentral testcase verifies that the parser module works without
44  * Value or Class Mapping, but the Verifier module must verify all of these:<ul>
45  * <li>RefGenClass (defined by a RefClass) without ClassMapping
46  * <li>Class without ClassMapping
47  * <li>PrimitiveType without ValueMapping
48  * <li>RefGenClass (defined by a PrimitiveType) without ClassMapping
49  * </ul>
50  * @author X. Spengler
51  */

52 public class VerifierCentral extends TestCase {
53
54     /**
55      * prefix defines the path to the persistence description files
56      */

57     private static String JavaDoc prefix =
58             "test/deviance/org/objectweb/jorm/verifier/";
59
60     /**
61      * properties defines the name of the jorm properties file
62      */

63     private static String JavaDoc properties =
64             prefix + "jorm.properties";
65
66     /**
67      * mapperOption defines the name of the class which manages the mapper
68      * option
69      */

70     private static String JavaDoc mapperOption =
71             "org.objectweb.jorm.cmdline.rdb.RdbMapperOption";
72
73     /**
74      * dbprop defines the name of the property which manages the name of the
75      * database
76      */

77     private static String JavaDoc dbprop = "DBName";
78
79     /**
80      * dbname defines the name of the database
81      */

82     private static String JavaDoc dbname = "postgres";
83
84     /**
85      * Builds a new VerifierCentral testcase
86      */

87     public VerifierCentral(String JavaDoc name) {
88         super(name);
89     }
90
91     /**
92      * main method to launch the tests manually
93      */

94     public static void main(String JavaDoc[] args) {
95         TestRunner.run(suite());
96     }
97
98     /**
99      * Sets up the current test
100      */

101     protected void setUp() {
102     }
103
104     /**
105      * Creates a TestSuite object with the current tests
106      */

107     public static Test suite() {
108         return new TestSuite(VerifierCentral.class);
109     }
110
111     /**
112      * Tests when a RefGenClass does not define a ClassMapping.
113      * The parser does not return an error, but the Verifer module must verify
114      * this section.
115      */

116     public void testRefGenClass_RefClass_WithoutClassMapping() {
117         Compiler JavaDoc comp = new Compiler JavaDoc(properties);
118         comp.addInputFileName(prefix+"RefGenClass_RefClass.pd");
119         comp.addInputFileName(prefix+"aRefClass.pd");
120         try {
121             CmdLineParser clp = (CmdLineParser)
122                     comp.getClassLoader().load(mapperOption);
123             comp.getCompilerParameter().addCPExtension(
124                     mapperOption,clp);
125
126             clp.parseProperty(dbprop, dbname);
127         } catch (Exception JavaDoc e) {
128
129         }
130
131         try {
132         assertTrue("a RefGenClass without a ClassMapping (for rdb) does not work",
133                 comp.execute());
134         } catch (Exception JavaDoc e) {
135         }
136     }
137
138     /**
139      * Tests when a Class does not define a ClassMapping.
140      * The parser does not return an error, but the Verifer module must verify
141      * this section.
142      */

143     public void testClassWithoutClassMapping() {
144         Compiler JavaDoc comp = new Compiler JavaDoc(properties);
145         comp.addInputFileName(prefix+"WithoutClassMapping.pd");
146         try {
147             CmdLineParser clp = (CmdLineParser)
148                     comp.getClassLoader().load(mapperOption);
149             comp.getCompilerParameter().addCPExtension(
150                     mapperOption,clp);
151
152             clp.parseProperty(dbprop, dbname);
153         } catch (Exception JavaDoc e) {
154
155         }
156
157         assertTrue("Without ClassMapping does not work", comp.execute());
158     }
159
160     /**
161      * Tests when a PrimitiveType does not define a ValueMapping.
162      * The parser does not return an error, but the Verifer module must verify
163      * this section.
164      */

165     public void testPrimitiveWithoutMapping() {
166         Compiler JavaDoc comp = new Compiler JavaDoc(properties);
167         comp.addInputFileName(prefix+"PrimitiveWithoutMapping.pd");
168         try {
169             CmdLineParser clp = (CmdLineParser)
170                     comp.getClassLoader().load(mapperOption);
171             comp.getCompilerParameter().addCPExtension(
172                     mapperOption,clp);
173
174             clp.parseProperty(dbprop, dbname);
175         } catch (Exception JavaDoc e) {
176
177         }
178
179         assertTrue("A PrimitiveType without ValueMapping does not work",
180                 comp.execute());
181     }
182
183     /**
184      * Tests when a RefGenClass does not define a ClassMapping.
185      * The parser does not return an error, but the Verifer module must verify
186      * this section.
187      * A Field is defined by a RefGenClass which is defined by a PrimitiveType,
188      * the RefGenClass does not declare the corresponding ClassMapping.
189      */

190     public void testRefGenClass_Primitive_WithoutClassMapping() {
191         Compiler JavaDoc comp = new Compiler JavaDoc(properties);
192         comp.addInputFileName(prefix+"RefGenClass_Primitive.pd");
193         try {
194             CmdLineParser clp = (CmdLineParser)
195                     comp.getClassLoader().load(mapperOption);
196             comp.getCompilerParameter().addCPExtension(
197                     mapperOption,clp);
198
199             clp.parseProperty(dbprop, dbname);
200         } catch (Exception JavaDoc e) {
201
202         }
203
204         assertTrue("A RefGenClass without a ClassMapping (for rdb) does not work",
205                 comp.execute());
206     }
207 }
208
Popular Tags