1 package org.hibernate.test.interfaceproxy; 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.dialect.PostgreSQLDialect; 11 import org.hibernate.test.TestCase; 12 13 16 public class InterfaceProxyTest extends TestCase { 17 18 public InterfaceProxyTest(String str) { 19 super(str); 20 } 21 22 public void testInterfaceProxies() { 23 24 if ( getDialect() instanceof PostgreSQLDialect ) return; 25 26 Session s = openSession( new DocumentInterceptor() ); 27 Transaction t = s.beginTransaction(); 28 Document d = new DocumentImpl(); 29 d.setName("Hibernate in Action"); 30 d.setContent( Hibernate.createBlob( "blah blah blah".getBytes() ) ); 31 Long did = (Long ) s.save(d); 32 SecureDocument d2 = new SecureDocumentImpl(); 33 d2.setName("Secret"); 34 d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) ); 35 d2.setPermissionBits( (byte) 664 ); 36 d2.setOwner("gavin"); 37 Long d2id = (Long ) s.save(d2); 38 t.commit(); 39 s.close(); 40 41 s = openSession( new DocumentInterceptor() ); 42 t = s.beginTransaction(); 43 d = (Document) s.load(ItemImpl.class, did); 44 assertEquals( did, d.getId() ); 45 assertEquals( "Hibernate in Action", d.getName() ); 46 assertNotNull( d.getContent() ); 47 48 d2 = (SecureDocument) s.load(ItemImpl.class, d2id); 49 assertEquals( d2id, d2.getId() ); 50 assertEquals( "Secret", d2.getName() ); 51 assertNotNull( d2.getContent() ); 52 53 s.clear(); 54 55 d = (Document) s.load(DocumentImpl.class, did); 56 assertEquals( did, d.getId() ); 57 assertEquals( "Hibernate in Action", d.getName() ); 58 assertNotNull( d.getContent() ); 59 60 d2 = (SecureDocument) s.load(SecureDocumentImpl.class, d2id); 61 assertEquals( d2id, d2.getId() ); 62 assertEquals( "Secret", d2.getName() ); 63 assertNotNull( d2.getContent() ); 64 assertEquals( "gavin", d2.getOwner() ); 65 66 68 d2 = (SecureDocument) s.load(SecureDocumentImpl.class, did); 69 assertEquals( did, d2.getId() ); 70 assertEquals( "Hibernate in Action", d2.getName() ); 71 assertNotNull( d2.getContent() ); 72 73 try { 74 d2.getOwner(); assertFalse(true); 76 } 77 catch (ClassCastException cce) { 78 } 80 81 82 t.commit(); 83 s.close(); 84 } 85 86 87 protected String [] getMappings() { 88 return new String [] { "interfaceproxy/Item.hbm.xml" }; 89 } 90 91 public static Test suite() { 92 return new TestSuite(InterfaceProxyTest.class); 93 } 94 95 public String getCacheConcurrencyStrategy() { 96 return null; 97 } 98 } 99 100 | Popular Tags |