KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > entity > Java5FeaturesTest


1 //$Id: Java5FeaturesTest.java,v 1.4 2005/07/16 16:50:30 epbernard Exp $
2
package org.hibernate.test.annotations.entity;
3
4 import org.hibernate.Session;
5 import org.hibernate.Transaction;
6 import org.hibernate.test.annotations.TestCase;
7
8 /**
9  * @author Emmanuel Bernard
10  */

11 public class Java5FeaturesTest extends TestCase {
12     public void testInterface() throws Exception JavaDoc {
13         Session s;
14         Transaction tx;
15         s = openSession();
16         tx = s.beginTransaction();
17         Race r = new Race();
18         r.setId( new Integer JavaDoc(1) );
19         r.setLength( new Long JavaDoc( 3 ) );
20         s.persist( r );
21         tx.commit();
22         s.close();
23
24         s = openSession();
25         tx = s.beginTransaction();
26         r = (Race) s.get( Race.class, r.getId() );
27         assertEquals( new Long JavaDoc(3), r.getLength() );
28         tx.commit();
29         s.close();
30
31     }
32
33     public void testEnums() throws Exception JavaDoc {
34         Session s;
35         Transaction tx;
36         s = openSession();
37         tx = s.beginTransaction();
38         Bid bid = new Bid();
39         bid.setId( new Integer JavaDoc(1) );
40         bid.setDescription("My best one");
41         bid.setNote(Starred.OK);
42         bid.setEditorsNote(Starred.GOOD);
43         s.persist( bid );
44         tx.commit();
45         s.close();
46
47         s = openSession();
48         tx = s.beginTransaction();
49         bid = (Bid) s.get( Bid.class, bid.getId() );
50         assertEquals( Starred.OK, bid.getNote() );
51         assertEquals( Starred.GOOD, bid.getEditorsNote() );
52         s.delete( bid );
53         tx.commit();
54         s.close();
55     }
56
57     public void testAutoboxing() throws Exception JavaDoc {
58         Session s;
59         Transaction tx;
60         s = openSession();
61         tx = s.beginTransaction();
62         Bid bid = new Bid();
63         bid.setId( new Integer JavaDoc(2) );
64         bid.setDescription("My best one");
65         bid.setNote(Starred.OK);
66         bid.setEditorsNote(Starred.GOOD);
67         bid.setApproved( null );
68         s.persist( bid );
69         tx.commit();
70         s.close();
71
72         s = openSession();
73         tx = s.beginTransaction();
74         bid = (Bid) s.get( Bid.class, bid.getId() );
75         assertEquals( null, bid.getApproved() );
76         s.delete( bid );
77         tx.commit();
78         s.close();
79     }
80     public Java5FeaturesTest(String JavaDoc x) {
81         super( x );
82     }
83
84     protected Class JavaDoc[] getMappings() {
85         return new Class JavaDoc[] {
86             Race.class,
87             Bid.class
88         };
89     }
90 }
91
Popular Tags