KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > fos > lib > TestFosPMappingStructuresManager


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

35 public class TestFosPMappingStructuresManager extends TestCase {
36     private final static String JavaDoc JCN1 = "org.objectweb.test.C1";
37     private final static String JavaDoc JCN2 = "org.objectweb.test.C2";
38
39     private final static String JavaDoc D1 = "org/d1";
40     private final static String JavaDoc D2 = "org/d2long";
41     private final static String JavaDoc D11 = "org/d1/d1";
42
43     public TestFosPMappingStructuresManager(String JavaDoc testname) {
44         super(testname);
45     }
46
47     protected void setUp() {
48
49     }
50
51     protected void tearDown() {
52
53     }
54
55     public void testClusterWith1Class1Dir() {
56         try {
57             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
58             man.addDirName(JCN1, D1);
59             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
60             assertTrue("Cluster has not been created for " + JCN1, cl != null);
61             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
62         } catch (PException e) {
63             e.printStackTrace();
64             fail(e.getMessage());
65         }
66     }
67
68     public void testClusterWith1Class1DirDup() {
69         try {
70             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
71             man.addDirName(JCN1, D1);
72             man.addDirName(JCN1, D1);
73             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
74             assertTrue("Cluster has not been created for " + JCN1, cl != null);
75             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
76         } catch (PException e) {
77             e.printStackTrace();
78             fail(e.getMessage());
79         }
80     }
81
82     public void testClusterWith1Class2DirSubBefore() {
83         try {
84             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
85             man.addDirName(JCN1, D1);
86             man.addDirName(JCN1, D11);
87             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
88             assertTrue("Cluster has not been created for " + JCN1, cl != null);
89             assertTrue("Directory " + D11 + " does not exist in cluster", cl.containDirectory(D11));
90             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
91         } catch (PException e) {
92             e.printStackTrace();
93             fail(e.getMessage());
94         }
95     }
96
97     public void testClusterWith1Class2DirSubAfter() {
98         try {
99             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
100             man.addDirName(JCN1, D1);
101             man.addDirName(JCN1, D11);
102             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
103             assertTrue("Cluster has not been created for " + JCN1, cl != null);
104             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
105             assertTrue("Directory " + D11 + " does not exist in cluster", cl.containDirectory(D11));
106         } catch (PException e) {
107             e.printStackTrace();
108             fail(e.getMessage());
109         }
110     }
111
112     public void testClusterWith2Class2DirNoMerge() {
113         try {
114             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
115             man.addDirName(JCN1, D1);
116             man.addDirName(JCN2, D2);
117             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
118             FosPMapCluster cl2 = (FosPMapCluster) man.getPMapCluster(JCN2);
119             assertTrue("Cluster has not been created for " + JCN1, cl != null);
120             assertTrue("Cluster has not been created for " + JCN2, cl2 != null);
121             assertTrue("The two classes are into the same cluster", cl != cl2);
122             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
123             assertTrue("Directory " + D2 + " does not exist in cluster", cl2.containDirectory(D2));
124         } catch (PException e) {
125             e.printStackTrace();
126             fail(e.getMessage());
127         }
128     }
129
130     public void testClusterWith2Class3DirMerge() {
131         try {
132             FosPMappingStructuresManager man = new FosPMappingStructuresManager();
133             man.addDirName(JCN1, D1);
134             man.addDirName(JCN1, D2);
135             man.addDirName(JCN2, D11);
136             FosPMapCluster cl = (FosPMapCluster) man.getPMapCluster(JCN1);
137             FosPMapCluster cl2 = (FosPMapCluster) man.getPMapCluster(JCN2);
138             assertTrue("Cluster has not been created for " + JCN1, cl != null);
139             assertTrue("Cluster has not been created for " + JCN2, cl2 != null);
140             assertTrue("The two classes are not into the same cluster", cl == cl2);
141             assertTrue("Directory " + D1 + " does not exist in cluster", cl.containDirectory(D1));
142             assertTrue("Directory " + D2 + " does not exist in cluster", cl.containDirectory(D2));
143             assertTrue("Directory " + D11 + " does not exist in cluster", cl.containDirectory(D11));
144         } catch (PException e) {
145             e.printStackTrace();
146             fail(e.getMessage());
147         }
148     }
149 }
150
Popular Tags