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

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/interfaceproxy/InterfaceProxyTest.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: InterfaceProxyTest.java 10976 2006-12-12 23:22:26Z steve.ebersole@jboss.com $
 
2
package org.hibernate.test.interfaceproxy;
 
3
 
 
4
import junit.framework.Test;
 
5
 
 
6
import org.hibernate.Hibernate;
 
7
import org.hibernate.Session;
 
8
import org.hibernate.Transaction;
 
9
import org.hibernate.dialect.PostgreSQLDialect;
 
10
import org.hibernate.junit.functional.FunctionalTestCase;
 
11
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
12
 
 
13
/**
 
14
 * @author Gavin King
 
15
 */
 
16
public class InterfaceProxyTest extends FunctionalTestCase {
 
17
        
 
18
        public InterfaceProxyTest(String str) {
 
19
                super(str);
 
20
        }
 
21
 
 
22
        public String[] getMappings() {
 
23
                return new String[] { "interfaceproxy/Item.hbm.xml" };
 
24
        }
 
25
 
 
26
        public String getCacheConcurrencyStrategy() {
 
27
                return null;
 
28
        }
 
29
 
 
30
        public static Test suite() {
 
31
                return new FunctionalTestClassTestSuite( InterfaceProxyTest.class );
 
32
        }
 
33
        
 
34
        public void testInterfaceProxies() {
 
35
                
 
36
                if ( getDialect() instanceof PostgreSQLDialect ) {
 
37
                        // TODO : why?
 
38
                        return;
 
39
                }
 
40
                
 
41
                Session s = openSession( new DocumentInterceptor() );
 
42
                Transaction t = s.beginTransaction();
 
43
                Document d = new DocumentImpl();
 
44
                d.setName("Hibernate in Action");
 
45
                d.setContent( Hibernate.createBlob( "blah blah blah".getBytes() ) );
 
46
                Long did = (Long) s.save(d);
 
47
                SecureDocument d2 = new SecureDocumentImpl();
 
48
                d2.setName("Secret");
 
49
                d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) );
 
50
                d2.setPermissionBits( (byte) 664 );
 
51
                d2.setOwner("gavin");
 
52
                Long d2id = (Long) s.save(d2);
 
53
                t.commit();
 
54
                s.close();
 
55
 
 
56
                s = openSession( new DocumentInterceptor() );
 
57
                t = s.beginTransaction();
 
58
                d = (Document) s.load(ItemImpl.class, did);
 
59
                assertEquals( did, d.getId() );
 
60
                assertEquals( "Hibernate in Action", d.getName() );
 
61
                assertNotNull( d.getContent() );
 
62
                
 
63
                d2 = (SecureDocument) s.load(ItemImpl.class, d2id);
 
64
                assertEquals( d2id, d2.getId() );
 
65
                assertEquals( "Secret", d2.getName() );
 
66
                assertNotNull( d2.getContent() );
 
67
                
 
68
                s.clear();
 
69
                
 
70
                d = (Document) s.load(DocumentImpl.class, did);
 
71
                assertEquals( did, d.getId() );
 
72
                assertEquals( "Hibernate in Action", d.getName() );
 
73
                assertNotNull( d.getContent() );
 
74
                
 
75
                d2 = (SecureDocument) s.load(SecureDocumentImpl.class, d2id);
 
76
                assertEquals( d2id, d2.getId() );
 
77
                assertEquals( "Secret", d2.getName() );
 
78
                assertNotNull( d2.getContent() );
 
79
                assertEquals( "gavin", d2.getOwner() );
 
80
                
 
81
                //s.clear();
 
82
                
 
83
                d2 = (SecureDocument) s.load(SecureDocumentImpl.class, did);
 
84
                assertEquals( did, d2.getId() );
 
85
                assertEquals( "Hibernate in Action", d2.getName() );
 
86
                assertNotNull( d2.getContent() );
 
87
                
 
88
                try {
 
89
                        d2.getOwner(); //CCE
 
90
                        assertFalse(true);
 
91
                }
 
92
                catch (ClassCastException cce) {
 
93
                        //correct
 
94
                }
 
95
 
 
96
                s.createQuery( "delete ItemImpl" ).executeUpdate();
 
97
                t.commit();
 
98
                s.close();
 
99
        }
 
100
}
 
101