Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test
In directory sc8-pr-cvs1:/tmp/cvs-serv578/test
Modified Files:
Baz.hbm.xml Baz.java FooBarTest.java
Log Message:
added tests for proxies in collections
Index: Baz.hbm.xml
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Baz.hbm.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Baz.hbm.xml 1 Feb 2003 00:17:17 -0000 1.7
--- Baz.hbm.xml 1 Feb 2003 10:42:29 -0000 1.8
***************
*** 107,110 ****
--- 107,115 ----
</array>
+ <bag name="fooBag" lazy="true" table="baz_foo" cascade="all">
+ <key column="baz" />
+ <many-to-many class="net.sf.hibernate.test.Foo" column="foo" length="36" outer-join="true"/>
+ </bag>
+
<array name="stringArray">
<key column="id_" />
Index: Baz.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Baz.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Baz.java 20 Jan 2003 18:45:18 -0000 1.4
--- Baz.java 1 Feb 2003 10:42:29 -0000 1.5
***************
*** 28,31 ****
--- 28,32 ----
private Map glarchToFoo;
private List fees;
+ private Collection fooBag;
Baz() {}
***************
*** 235,238 ****
--- 236,247 ----
public void setFees(List fees) {
this.fees = fees;
+ }
+
+ public Collection getFooBag() {
+ return fooBag;
+ }
+
+ public void setFooBag(Collection fooBag) {
+ this.fooBag = fooBag;
}
Index: FooBarTest.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/FooBarTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** FooBarTest.java 31 Jan 2003 08:49:50 -0000 1.17
--- FooBarTest.java 1 Feb 2003 10:42:29 -0000 1.18
***************
*** 45,48 ****
--- 45,49 ----
import net.sf.hibernate.dialect.SAPDBDialect;
import net.sf.hibernate.dialect.SybaseDialect;
+ import net.sf.hibernate.proxy.HibernateProxy;
import net.sf.hibernate.type.DateType;
import net.sf.hibernate.type.EntityType;
***************
*** 2887,2890 ****
--- 2888,2935 ----
t.commit();
s.close();
+ }
+
+ public void testProxiesInCollections() throws Exception {
+ Session s = sessions.openSession();
+ Baz baz = new Baz();
+ Bar bar = new Bar();
+ Bar bar2 = new Bar();
+ s.save(bar);
+ Serializable bar2id = s.save(bar2);
+ baz.setFooArray( new Foo[] { bar, bar2 } );
+ HashSet set = new HashSet();
+ bar = new Bar();
+ s.save(bar);
+ set.add(bar);
+ baz.setFooSet(set);
+ set = new HashSet();
+ set.add( new Bar() );
+ set.add( new Bar() );
+ baz.setCascadingBars(set);
+ ArrayList list = new ArrayList();
+ list.add( new Foo() );
+ baz.setFooBag(list);
+ Serializable id = s.save(baz);
+ Serializable bid = ( (Bar) baz.getCascadingBars().iterator().next() ).getKey();
+ s.flush();
+ s.connection().commit();
+
+ s = sessions.openSession();
+ BarProxy barprox = (BarProxy) s.load(Bar.class, bid);
+ BarProxy bar2prox = (BarProxy) s.load(Bar.class, bar2id);
+ assertTrue(bar2prox instanceof HibernateProxy);
+ assertTrue(barprox instanceof HibernateProxy);
+ baz = (Baz) s.load(Baz.class, id);
+ Iterator i = baz.getCascadingBars().iterator();
+ BarProxy b1 = (BarProxy) i.next();
+ BarProxy b2 = (BarProxy) i.next();
+ assertTrue( ( b1==barprox && !(b2 instanceof HibernateProxy) ) || ( b2==barprox && !(b1 instanceof HibernateProxy) ) ); //one-to-many
+ assertTrue( baz.getFooArray()[0] instanceof HibernateProxy ); //many-to-many
+ assertTrue( baz.getFooArray()[1]==bar2prox );
+ assertTrue( !(baz.getFooBag().iterator().next() instanceof HibernateProxy) ); //many-to-many outer-join="true"
+ assertTrue( !(baz.getFooSet().iterator().next() instanceof HibernateProxy) ); //one-to-many
+ s.delete("from o in class java.lang.Object");
+ s.flush();
+ s.connection().commit();
}
|