KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MultipleObject testcase verifies the behavior when many objects from the
44  * same type are defined more than one time: <ul>
45  * <li>more than one Class
46  * <li>more than one GenClass
47  * <li>more than one Extension on Class object
48  * <li>more than one PrimitiveType on Field object
49  * </ul>
50  * @author X. Spengler
51  */

52 public class MultipleObject 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/parser/lib/";
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 MultipleObject testcase
86      */

87     public MultipleObject(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(MultipleObject.class);
109     }
110
111     /**
112      * Tests when a second Class is defined after a parsed Class
113      */

114     public void testMultipleClass() {
115         try {
116             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
117             comp.addInputFileName(prefix+"MultipleClass.pd");
118
119             CmdLineParser clp = (CmdLineParser)
120                     comp.getClassLoader().load(mapperOption);
121             comp.getCompilerParameter().addCPExtension(
122                     mapperOption,clp);
123
124             clp.parseProperty(dbprop, dbname);
125             assertTrue("Multiple Classes does not work", comp.execute());
126         } catch (Exception JavaDoc e) {
127
128         }
129     }
130
131     /**
132      * Tests when a second GenClass object is defined after a parsed GenClass
133      */

134     public void testMultipleGenClass() {
135         try {
136             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
137             comp.addInputFileName(prefix+"MultipleGenClass.pd");
138
139             CmdLineParser clp = (CmdLineParser)
140                     comp.getClassLoader().load(mapperOption);
141             comp.getCompilerParameter().addCPExtension(
142                     mapperOption,clp);
143
144             clp.parseProperty(dbprop, dbname);
145             assertTrue("Multiple GenClasses does not work", comp.execute());
146         } catch (Exception JavaDoc e) {
147
148         }
149     }
150
151     /**
152      * Tests when a lot of extensions are defined for a given Class object
153      */

154     public void testMultipleExtension() {
155         try {
156             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
157             comp.addInputFileName(prefix+"MultipleExtension.pd");
158
159             CmdLineParser clp = (CmdLineParser)
160                     comp.getClassLoader().load(mapperOption);
161             comp.getCompilerParameter().addCPExtension(
162                     mapperOption,clp);
163
164             clp.parseProperty(dbprop, dbname);
165             assertTrue("Multiple Extension does not work", comp.execute());
166         } catch (Exception JavaDoc e) {
167
168         }
169     }
170
171     /**
172      * Tests when a second PrimitiveType object is defined after a parsed
173      * PrimitiveType object
174      */

175     public void testMultiplePrimitive() {
176         try {
177             Compiler JavaDoc comp = new Compiler JavaDoc(properties,"config/logSystem.properties");
178             comp.addInputFileName(prefix+"MultiplePrimitive.pd");
179
180             CmdLineParser clp = (CmdLineParser)
181                     comp.getClassLoader().load(mapperOption);
182             comp.getCompilerParameter().addCPExtension(
183                     mapperOption,clp);
184
185             clp.parseProperty(dbprop, dbname);
186             assertTrue("Multiple Primitive does not work", comp.execute());
187         } catch (Exception JavaDoc e) {
188
189         }
190     }
191 }
192
Popular Tags