1
//$Id: InterfaceProxyTest.java 10976 2006-12-12 23:22:26Z steve.ebersole@jboss.com $
2
package org.hibernate.test.interfaceproxy;
4
import junit.framework.Test;
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;
16
public class InterfaceProxyTest extends FunctionalTestCase {
18
public InterfaceProxyTest(String str) {
22
public String[] getMappings() {
23
return new String[] { "interfaceproxy/Item.hbm.xml" };
26
public String getCacheConcurrencyStrategy() {
30
public static Test suite() {
31
return new FunctionalTestClassTestSuite( InterfaceProxyTest.class );
34
public void testInterfaceProxies() {
36
if ( getDialect() instanceof PostgreSQLDialect ) {
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();
49
d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) );
50
d2.setPermissionBits( (byte) 664 );
52
Long d2id = (Long) s.save(d2);
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() );
63
d2 = (SecureDocument) s.load(ItemImpl.class, d2id);
64
assertEquals( d2id, d2.getId() );
65
assertEquals( "Secret", d2.getName() );
66
assertNotNull( d2.getContent() );
70
d = (Document) s.load(DocumentImpl.class, did);
71
assertEquals( did, d.getId() );
72
assertEquals( "Hibernate in Action", d.getName() );
73
assertNotNull( d.getContent() );
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() );
83
d2 = (SecureDocument) s.load(SecureDocumentImpl.class, did);
84
assertEquals( did, d2.getId() );
85
assertEquals( "Hibernate in Action", d2.getName() );
86
assertNotNull( d2.getContent() );
92
catch (ClassCastException cce) {
96
s.createQuery( "delete ItemImpl" ).executeUpdate();