KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > extendshbm > ExtendsTest


1 //$Id: ExtendsTest.java,v 1.7 2005/04/11 12:37:24 maxcsaucdk Exp $
2
package org.hibernate.test.extendshbm;
3
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.cfg.Configuration;
9 import org.hibernate.test.TestCase;
10
11 /**
12  * @author Gavin King
13  */

14 public class ExtendsTest extends TestCase {
15     
16     public ExtendsTest(String JavaDoc str) {
17         super(str);
18     }
19     
20     public void testAllInOne() {
21         assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Customer"));
22         assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Person"));
23         assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Employee"));
24     }
25     
26     public void testOutOfOrder() {
27         Configuration cfg = new Configuration();
28         
29         try {
30             cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");
31             assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
32             cfg.addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml");
33             cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");
34             
35             cfg.buildSessionFactory();
36         
37             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
38             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));
39             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));
40             
41         } catch(HibernateException e) {
42             fail("should not fail with exception! " + e);
43         }
44         
45     }
46
47     public void testNwaitingForSuper() {
48         Configuration cfg = new Configuration();
49         
50         try {
51             cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");
52             assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
53             cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");
54             assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));
55             cfg.addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml");
56             
57             cfg.buildMappings();
58         
59             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));
60             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));
61             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
62             
63             
64         } catch(HibernateException e) {
65             e.printStackTrace();
66             fail("should not fail with exception! " + e);
67             
68         }
69         
70     }
71     
72     public void testMissingSuper() {
73         Configuration cfg = new Configuration();
74         
75         try {
76             cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");
77             assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
78             cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");
79             
80             cfg.buildSessionFactory();
81         
82             fail("Should not be able to build sessionfactory without a Person");
83         } catch(HibernateException e) {
84             
85         }
86         
87     }
88     
89     public void testAllSeparateInOne() {
90         Configuration cfg = new Configuration();
91         
92         try {
93             cfg.addResource(getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml");
94             
95             cfg.buildSessionFactory();
96         
97             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
98             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));
99             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));
100             
101         } catch(HibernateException e) {
102             fail("should not fail with exception! " + e);
103         }
104         
105     }
106     
107     public void testJoinedSubclassAndEntityNamesOnly() {
108         Configuration cfg = new Configuration();
109         
110         try {
111             cfg.addResource(getBaseForMappings() + "extendshbm/entitynames.hbm.xml");
112             
113             cfg.buildMappings();
114         
115             assertNotNull(cfg.getClassMapping("EntityHasName"));
116             assertNotNull(cfg.getClassMapping("EntityCompany"));
117             
118         } catch(HibernateException e) {
119             e.printStackTrace();
120             fail("should not fail with exception! " + e);
121             
122         }
123     }
124    
125
126     public void testUnionSubclass() {
127         Configuration cfg = new Configuration();
128         
129         try {
130             cfg.addResource(getBaseForMappings() + "extendshbm/unionsubclass.hbm.xml");
131             
132             cfg.buildMappings();
133         
134             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));
135             assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));
136             
137         } catch(HibernateException e) {
138             e.printStackTrace();
139             fail("should not fail with exception! " + e);
140             
141         }
142     }
143     protected String JavaDoc[] getMappings() {
144         return new String JavaDoc[] { "extendshbm/allinone.hbm.xml" };
145     }
146
147     public static Test suite() {
148         return new TestSuite(ExtendsTest.class);
149     }
150
151 }
152
153
Popular Tags