KickJava   Java API By Example, From Geeks To Geeks.

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


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.jorm.util.api.Loggable;
36 import org.objectweb.util.monolog.api.BasicLevel;
37 import org.objectweb.util.monolog.api.Logger;
38 import org.objectweb.jorm.compiler.lib.Compiler;
39 import org.objectweb.jorm.cmdline.api.CmdLineParser;
40
41 import java.util.Vector JavaDoc;
42 import java.util.Properties JavaDoc;
43 import java.io.FileInputStream JavaDoc;
44
45 /**
46  * SameObject testcase test cases where objects are defined two times.
47  * This testcase concerns:<ul>
48  * <li>two PrimitiveType objects
49  * <li>two PrimitiveType objects (just identical by their Names)
50  * <li>two NameDef objects in the same Class
51  * <li>two ScalarField in the same GenClass
52  * </ul>
53  * @author X. Spengler
54  */

55 public class SameObject extends TestCase {
56
57     /**
58      * prefix defines the path to the persistence description files
59      */

60     private static String JavaDoc prefix =
61             "test/deviance/org/objectweb/jorm/parser/lib/";
62
63     /**
64      * properties defines the name of the jorm properties file
65      */

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

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

80     private static String JavaDoc dbprop = "DBName";
81
82     /**
83      * dbname defines the name of the database
84      */

85     private static String JavaDoc dbname = "postgres";
86
87     /**
88      * Builds a new SameObject testcase
89      */

90     public SameObject(String JavaDoc name) {
91         super(name);
92     }
93
94     /**
95      * main method to launch the tests manually
96      */

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

104     protected void setUp() {
105     }
106
107     /**
108      * Creates a TestSuite object with the current tests
109      */

110     public static Test suite() {
111         return new TestSuite(SameObject.class);
112     }
113
114     /**
115      * Tests When the same PrimitiveType is defined more than one time.
116      */

117     public void test2Primitive() {
118         try {
119             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
120             comp.addInputFileName(prefix+"2Primitive.pd");
121
122             CmdLineParser clp = (CmdLineParser)
123                     comp.getClassLoader().load(mapperOption);
124             Logger logger = null;
125             try {
126                 Properties JavaDoc p = new Properties JavaDoc();
127                 p.load(new FileInputStream JavaDoc("config/logSystem.properties"));
128                 CompilerLogger.configure(p);
129                 logger =
130                         CompilerLogger.getLoggerFactory().
131                         getLogger("org.objectweb.jorm.compiler");
132
133             } catch (Exception JavaDoc e) {}
134
135             comp.getCompilerParameter().addCPExtension(
136                     mapperOption,clp);
137
138             clp.parseProperty(dbprop, dbname);
139             assertTrue("2 identical primitive type must be catched",
140                     comp.execute());
141         } catch (Exception JavaDoc e) {
142
143         }
144
145     }
146
147     /**
148      * Tests when the same PrimitiveType is defined more than one time but the
149      * two objects just have the name in common.
150      */

151     public void testNot2Primitive() {
152         try {
153             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
154             comp.addInputFileName(prefix+"Not2Primitive.pd");
155
156             CmdLineParser clp = (CmdLineParser)
157                     comp.getClassLoader().load(mapperOption);
158
159             Logger logger = null;
160             try {
161                 Properties JavaDoc p = new Properties JavaDoc();
162                 p.load(new FileInputStream JavaDoc("config/logSystem.properties"));
163                 CompilerLogger.configure(p);
164                 logger =
165                         CompilerLogger.getLoggerFactory().
166                         getLogger("org.objectweb.jorm.compiler");
167
168             } catch (Exception JavaDoc e) {}
169
170             comp.getCompilerParameter().addCPExtension(
171                     mapperOption,clp);
172
173             clp.parseProperty(dbprop, dbname);
174
175             assertTrue("2 identical primitive name type must be catched",
176                     comp.execute());
177         } catch (Exception JavaDoc e) {
178
179         }
180     }
181
182     /**
183      * Tests when the same NameDef object is defined more than one time for a
184      * given Class object.
185      */

186     public void testSameNameDef() {
187         try {
188             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
189             comp.addInputFileName(prefix+"SameNameDef.pd");
190
191             CmdLineParser clp = (CmdLineParser)
192                     comp.getClassLoader().load(mapperOption);
193
194             Logger logger = null;
195             try {
196                 Properties JavaDoc p = new Properties JavaDoc();
197                 p.load(new FileInputStream JavaDoc("config/logSystem.properties"));
198                 CompilerLogger.configure(p);
199                 logger =
200                         CompilerLogger.getLoggerFactory().
201                         getLogger("org.objectweb.jorm.compiler");
202
203             } catch (Exception JavaDoc e) {}
204
205             comp.getCompilerParameter().addCPExtension(
206                     mapperOption,clp);
207
208             clp.parseProperty(dbprop, dbname);
209             assertTrue("2 identical NameDef must be catched",
210                     comp.execute());
211         } catch (Exception JavaDoc e) {
212
213         }
214     }
215
216     /**
217      * Tests when a GenClass object defines more than one time a ScalarField
218      * objects.
219      */

220     public void test2ScalarField() {
221         try {
222             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
223             comp.addInputFileName(prefix+"2ScalarField.pd");
224
225             CmdLineParser clp = (CmdLineParser)
226                     comp.getClassLoader().load(mapperOption);
227
228             Logger logger = null;
229             try {
230                 Properties JavaDoc p = new Properties JavaDoc();
231                 p.load(new FileInputStream JavaDoc("config/logSystem.properties"));
232                 CompilerLogger.configure(p);
233                 logger =
234                         CompilerLogger.getLoggerFactory().
235                         getLogger("org.objectweb.jorm.compiler");
236
237             } catch (Exception JavaDoc e) {}
238
239             comp.getCompilerParameter().addCPExtension(
240                     mapperOption,clp);
241
242             clp.parseProperty(dbprop, dbname);
243             assertTrue("2 identical ScalarField must be catched",
244                     comp.execute());
245
246         } catch (Exception JavaDoc e) {
247
248         }
249     }
250 }
251
Popular Tags