KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > ConfigurationTest


1 //$Id: ConfigurationTest.java,v 1.1 2005/05/12 13:33:52 epbernard Exp $
2
package org.hibernate.test.annotations;
3
4 import org.hibernate.MappingException;
5 import org.hibernate.Query;
6 import org.hibernate.Session;
7 import org.hibernate.SessionFactory;
8 import org.hibernate.Transaction;
9 import org.hibernate.cfg.AnnotationConfiguration;
10 import org.hibernate.cfg.Configuration;
11 import org.hibernate.cfg.Environment;
12
13 /**
14  * @author Emmanuel Bernard
15  */

16 public class ConfigurationTest extends junit.framework.TestCase {
17     public void testDeclarativeMix() throws Exception JavaDoc {
18         AnnotationConfiguration cfg = new AnnotationConfiguration();
19         cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml");
20         cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
21         SessionFactory sf = cfg.buildSessionFactory();
22         assertNotNull(sf);
23         Session s = sf.openSession();
24         Transaction tx = s.beginTransaction();
25         Query q = s.createQuery("from Boat");
26         assertEquals(0, q.list().size());
27         q = s.createQuery("from Plane");
28         assertEquals(0, q.list().size());
29         tx.commit();
30         s.close();
31         sf.close();
32     }
33
34     public void testDeclarativeAnnWoAnnConfig() throws Exception JavaDoc {
35         Configuration cfg = new Configuration ();
36         try {
37             cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml");
38             fail("Configuration object should fail when finding annotated elements declarations");
39         } catch (MappingException e) {
40             //success
41
}
42     }
43 }
44
Popular Tags