KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > usercollection > UserCollectionTypeTest


1 //$Id$
2
package org.hibernate.test.usercollection;
3
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.hibernate.Hibernate;
8 import org.hibernate.Session;
9 import org.hibernate.Transaction;
10 import org.hibernate.test.TestCase;
11
12 /**
13  * @author Max Rydahl Andersen
14  */

15 public class UserCollectionTypeTest extends TestCase {
16     
17     public UserCollectionTypeTest(String JavaDoc str) {
18         super(str);
19     }
20
21     public void testBasicOperation() {
22         Session s = openSession();
23         Transaction t = s.beginTransaction();
24         User u = new User("max");
25         u.getEmailAddresses().add( new Email("max@hibernate.org") );
26         u.getEmailAddresses().add( new Email("max.andersen@jboss.com") );
27         s.persist(u);
28         t.commit();
29         s.close();
30         
31         s = openSession();
32         t = s.beginTransaction();
33         User u2 = (User) s.createCriteria(User.class).uniqueResult();
34         assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
35         assertEquals( u2.getEmailAddresses().size(), 2 );
36         s.delete(u2);
37         t.commit();
38         s.close();
39     }
40     
41         
42     protected String JavaDoc[] getMappings() {
43         return new String JavaDoc[] { "usercollection/UserPermissions.hbm.xml" };
44     }
45
46     public static Test suite() {
47         return new TestSuite(UserCollectionTypeTest.class);
48     }
49
50 }
51
52
Popular Tags