~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/cut/CompositeUserTypeTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: CompositeUserTypeTest.java 10976 2006-12-12 23:22:26Z steve.ebersole@jboss.com $
 
2
package org.hibernate.test.cut;
 
3
 
 
4
import java.math.BigDecimal;
 
5
import java.util.Currency;
 
6
import java.util.List;
 
7
 
 
8
import junit.framework.Test;
 
9
 
 
10
import org.hibernate.Session;
 
11
import org.hibernate.dialect.HSQLDialect;
 
12
import org.hibernate.dialect.Oracle9Dialect;
 
13
import org.hibernate.junit.functional.FunctionalTestCase;
 
14
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
15
 
 
16
/**
 
17
 * @author Gavin King
 
18
 */
 
19
public class CompositeUserTypeTest extends FunctionalTestCase {
 
20
        
 
21
        public CompositeUserTypeTest(String str) {
 
22
                super(str);
 
23
        }
 
24
 
 
25
        public String[] getMappings() {
 
26
                return new String[] { "cut/types.hbm.xml", "cut/Transaction.hbm.xml" };
 
27
        }
 
28
 
 
29
        public static Test suite() {
 
30
                return new FunctionalTestClassTestSuite( CompositeUserTypeTest.class );
 
31
        }
 
32
        
 
33
        public void testCompositeUserType() {
 
34
                Session s = openSession();
 
35
                org.hibernate.Transaction t = s.beginTransaction();
 
36
                
 
37
                Transaction tran = new Transaction();
 
38
                tran.setDescription("a small transaction");
 
39
                tran.setValue( new MonetoryAmount( new BigDecimal(1.5), Currency.getInstance("USD") ) );
 
40
                s.persist(tran);
 
41
                
 
42
                List result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'").list();
 
43
                assertEquals( result.size(), 1 );
 
44
                tran.getValue().setCurrency( Currency.getInstance("AUD") );
 
45
                result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list();
 
46
                assertEquals( result.size(), 1 );
 
47
                
 
48
                if ( !(getDialect() instanceof HSQLDialect) && ! (getDialect() instanceof Oracle9Dialect) ) {
 
49
                
 
50
                        result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list();
 
51
                        assertEquals( result.size(), 1 );
 
52
                        result = s.createQuery("from Transaction where value = (1.5, 'AUD')").list();
 
53
                        assertEquals( result.size(), 1 );
 
54
                        
 
55
                }
 
56
                
 
57
                s.delete(tran);
 
58
                t.commit();
 
59
                s.close();
 
60
        }
 
61
 
 
62
}
 
63