KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > inheritance > union > SubclassTest


1 //$Id: SubclassTest.java,v 1.2 2005/06/12 20:50:47 oneovthafew Exp $
2
package org.hibernate.test.annotations.inheritance.union;
3
4 import java.util.List JavaDoc;
5
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.hibernate.test.annotations.TestCase;
9
10 /**
11  * @author Emmanuel Bernard
12  */

13 public class SubclassTest extends TestCase {
14
15     public SubclassTest(String JavaDoc x) {
16         super(x);
17     }
18
19     public void testDefault() throws Exception JavaDoc {
20         Session s;
21         Transaction tx;
22         s = openSession();
23         tx = s.beginTransaction();
24         File doc = new Document("Enron Stuff To Shred", 1000);
25         Folder folder = new Folder("Enron");
26         s.persist(doc);
27         s.persist(folder);
28         tx.commit();
29         s.close();
30
31         s = openSession();
32         tx = s.beginTransaction();
33         List JavaDoc result = s.createCriteria(File.class).list();
34         assertNotNull(result);
35         assertEquals( 2, result.size() );
36         File f2 = (File) result.get(0);
37         checkClassType(f2, doc, folder);
38         f2 = (File) result.get(1);
39         checkClassType(f2, doc, folder);
40         tx.commit();
41         s.close();
42     }
43
44     private void checkClassType(File fruitToTest, File f, Folder a) {
45         if ( fruitToTest.getName().equals( f.getName() ) ) {
46             assertFalse(fruitToTest instanceof Folder);
47         } else if ( fruitToTest.getName().equals( a.getName() ) ) {
48             assertTrue(fruitToTest instanceof Folder);
49         } else {
50             fail("Result does not contains the previously inserted elements");
51         }
52     }
53
54     /**
55      * @see org.hibernate.test.annotations.TestCase#getMappings()
56      */

57     protected Class JavaDoc[] getMappings() {
58         return new Class JavaDoc[] {
59             File.class,
60             Folder.class,
61             Document.class,
62             SymbolicLink.class
63         };
64     }
65
66 }
67
Popular Tags