KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > lib > TestRdbPMappingStructuresManager


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.mapper.rdb.lib;
25
26 import junit.framework.TestCase;
27 import org.objectweb.jorm.api.PException;
28 import org.objectweb.util.monolog.api.Logger;
29 import org.objectweb.util.monolog.wrapper.printwriter.LoggerImpl;
30
31
32 /**
33  * Code for testing the RDB mapping structures implementation. It only tests
34  * the definition of mapping structures and does not test operations that
35  * modify the database schema.
36  * @author P. Dechamboux
37  */

38 public class TestRdbPMappingStructuresManager extends TestCase {
39     private final static String JavaDoc JCN1 = "org.objectweb.test.C1";
40     private final static String JavaDoc JCN2 = "org.objectweb.test.C2";
41
42     private final static String JavaDoc TN1 = "T1";
43     private final static String JavaDoc T1CN1 = "C11";
44     private final static String JavaDoc T1CT1 = "INTEGER";
45     private final static boolean T1CNN1 = true;
46     private final static String JavaDoc T1CN2 = "C12";
47     private final static String JavaDoc T1CT2 = "CHAR(20)";
48     private final static boolean T1CNN2 = false;
49     private final static String JavaDoc TN2 = "T2";
50     private final static String JavaDoc T2CN1 = "C21";
51     private final static String JavaDoc T2CT1 = "INTEGER";
52     private final static boolean T2CNN1 = true;
53     private final static String JavaDoc T2CN2 = "C22";
54     private final static String JavaDoc T2CT2 = "CHAR(20)";
55     private final static boolean T2CNN2 = false;
56     private Logger logger = new LoggerImpl();
57
58     public TestRdbPMappingStructuresManager(String JavaDoc testname) {
59         super(testname);
60     }
61
62     protected void setUp() {
63
64     }
65
66     protected void tearDown() {
67
68     }
69
70     public void testClusterWith1Class1Table1Column() {
71         try {
72             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
73             man.setLogger(logger);
74             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
75             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
76             assertTrue("Cluster has not been created for " + JCN1, cl != null);
77             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
78             assertTrue("Column " + T1CN1 + " into table " + JCN1 + " does not exist in cluster",
79                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
80         } catch (PException e) {
81             e.printStackTrace();
82             fail(e.getMessage());
83         }
84     }
85
86     public void testClusterWith1Class1Table1ColumnDupOK() {
87         try {
88             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
89             man.setLogger(logger);
90             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
91             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, false);
92             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
93             assertTrue("Cluster has not been created for " + JCN1, cl != null);
94             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
95             assertTrue("Column " + T1CN1 + " into table " + JCN1 + " does not exist in cluster",
96                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
97         } catch (PException e) {
98             e.printStackTrace();
99             fail(e.getMessage());
100         }
101     }
102
103     public void testClusterWith1Class1Table1ColumnDupKOnotnull() {
104         try {
105             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
106             man.setLogger(logger);
107             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
108             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, ! T1CNN1, false, true);
109             fail("Duplicate column definition with incompatible notnull");
110         } catch (PException e) {
111             assertTrue(e.getMessage(), true);
112         }
113     }
114
115     public void testClusterWith1Class1Table1ColumnDupKOtype() {
116         try {
117             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
118             man.setLogger(logger);
119             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
120             man.addTableColumn(JCN1, TN1, T1CN1, T1CT2, T1CNN1, false, true);
121             fail("Duplicate column definition with incompatible type");
122         } catch (PException e) {
123             assertTrue(e.getMessage(), true);
124         }
125     }
126
127     public void testClusterWith1Class1Table2Column() {
128         try {
129             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
130             man.setLogger(logger);
131             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
132             man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, false);
133             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
134             assertTrue("Cluster has not been created for " + JCN1, cl != null);
135             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
136             assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster",
137                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
138             assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster",
139                        cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2));
140         } catch (PException e) {
141             e.printStackTrace();
142             fail(e.getMessage());
143         }
144     }
145
146     public void testClusterWith1Class2Table2Column() {
147         try {
148             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
149             man.setLogger(logger);
150             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
151             man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true);
152             man.addTableColumn(JCN1, TN2, T2CN1, T2CT1, T2CNN1, false, true);
153             man.addTableColumn(JCN1, TN2, T2CN2, T2CT2, T2CNN2, false, true);
154             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
155             assertTrue("Cluster has not been created for " + JCN1, cl != null);
156             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
157             assertTrue("Table " + TN2 + " does not exist in cluster", cl.containTable(TN2));
158             assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster",
159                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
160             assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster",
161                        cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2));
162             assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster",
163                        cl.containColumn(TN2, T2CN1, T2CT1, T2CNN1));
164             assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster",
165                        cl.containColumn(TN2, T2CN2, T2CT2, T2CNN2));
166         } catch (PException e) {
167             e.printStackTrace();
168             fail(e.getMessage());
169         }
170     }
171
172     public void testClusterWith2Class2Table2ColumnNoMerge() {
173         try {
174             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
175             man.setLogger(logger);
176             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
177             man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true);
178             man.addTableColumn(JCN2, TN2, T2CN1, T2CT1, T2CNN1, false, true);
179             man.addTableColumn(JCN2, TN2, T2CN2, T2CT2, T2CNN2, false, true);
180             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
181             RdbPMapCluster cl2 = (RdbPMapCluster) man.getPMapCluster(JCN2);
182             assertTrue("Cluster has not been created for " + JCN1, cl != null);
183             assertTrue("Cluster has not been created for " + JCN2, cl2 != null);
184             assertTrue("The two classes are into the same cluster", cl != cl2);
185             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
186             assertTrue("Table " + TN2 + " does not exist in cluster", cl2.containTable(TN2));
187             assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster",
188                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
189             assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster",
190                        cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2));
191             assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster",
192                        cl2.containColumn(TN2, T2CN1, T2CT1, T2CNN1));
193             assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster",
194                        cl2.containColumn(TN2, T2CN2, T2CT2, T2CNN2));
195         } catch (PException e) {
196             e.printStackTrace();
197             fail(e.getMessage());
198         }
199     }
200
201     public void testClusterWith2Class2Table2ColumnMerge() {
202         try {
203             RdbPMappingStructuresManager man = new RdbPMappingStructuresManager();
204             man.setLogger(logger);
205             man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true);
206             man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true);
207             man.addTableColumn(JCN1, TN2, T2CN2, T2CT2, T2CNN2, false, true);
208             man.addTableColumn(JCN2, TN2, T2CN1, T2CT1, T2CNN1, false, true);
209             man.addTableColumn(JCN2, TN2, T2CN2, T2CT2, T2CNN2, false, false);
210             RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1);
211             RdbPMapCluster cl2 = (RdbPMapCluster) man.getPMapCluster(JCN2);
212             assertTrue("Cluster has not been created for " + JCN1, cl != null);
213             assertTrue("Cluster has not been created for " + JCN2, cl2 != null);
214             assertTrue("The two classes are not into the same cluster", cl == cl2);
215             assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1));
216             assertTrue("Table " + TN2 + " does not exist in cluster", cl.containTable(TN2));
217             assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster",
218                        cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1));
219             assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster",
220                        cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2));
221             assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster",
222                        cl.containColumn(TN2, T2CN1, T2CT1, T2CNN1));
223             assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster",
224                        cl.containColumn(TN2, T2CN2, T2CT2, T2CNN2));
225         } catch (PException e) {
226             e.printStackTrace();
227             fail(e.getMessage());
228         }
229     }
230 }
231
Popular Tags