KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > id > MultipleHiLoPerTableGeneratorTest


1 //$Id: MultipleHiLoPerTableGeneratorTest.java,v 1.4 2005/02/21 14:40:59 oneovthafew Exp $
2
package org.hibernate.test.id;
3
4 import org.hibernate.test.TestCase;
5 import org.hibernate.Session;
6 import org.hibernate.Transaction;
7 import junit.framework.Test;
8 import junit.framework.TestSuite;
9
10 /**
11  * @author Emmanuel Bernard
12  */

13 public class MultipleHiLoPerTableGeneratorTest extends TestCase {
14     public MultipleHiLoPerTableGeneratorTest(String JavaDoc x) {
15         super(x);
16     }
17
18     protected String JavaDoc[] getMappings() {
19         return new String JavaDoc[]{
20             "id/Car.hbm.xml",
21             "id/Plane.hbm.xml",
22             "id/Radio.hbm.xml"
23         };
24     }
25
26     public void testDistinctId() throws Exception JavaDoc {
27         Session s = openSession();
28         Transaction tx = s.beginTransaction();
29         int testLength = 3;
30         Car[] cars = new Car[testLength];
31         Plane[] planes = new Plane[testLength];
32         for (int i = 0; i < testLength ; i++) {
33             cars[i] = new Car();
34             cars[i].setColor("Color" + i);
35             planes[i] = new Plane();
36             planes[i].setNbrOfSeats(i);
37             s.persist(cars[i]);
38             s.persist(planes[i]);
39         }
40         tx.commit();
41         s.close();
42         for (int i = 0; i < testLength ; i++) {
43             assertEquals(i+1, cars[i].getId().intValue());
44             assertEquals(i+1, planes[i].getId().intValue());
45         }
46     }
47
48     public void testAllParams() throws Exception JavaDoc {
49         Session s = openSession();
50         Transaction tx = s.beginTransaction();
51         Radio radio = new Radio();
52         radio.setFrequency("32 MHz");
53         s.persist(radio);
54         assertEquals( new Integer JavaDoc(1), radio.getId() );
55         radio = new Radio();
56         radio.setFrequency("32 MHz");
57         s.persist(radio);
58         assertEquals( new Integer JavaDoc(2), radio.getId() );
59         tx.commit();
60         s.close();
61     }
62
63     public static Test suite() {
64         return new TestSuite(MultipleHiLoPerTableGeneratorTest.class);
65     }
66 }
67
Popular Tags