FileDocCategorySizeDatePackage
PersistentIdBagTest.javaAPI DocHibernate 3.2.52000Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.collection.idbag

PersistentIdBagTest

public class PersistentIdBagTest extends org.hibernate.junit.functional.FunctionalTestCase
Tests related to operations on a PersistentIdentifierBag
author
Steve Ebersole

Fields Summary
Constructors Summary
public PersistentIdBagTest(String name)

		super( name );
	
Methods Summary
public java.lang.String[]getMappings()

		return new String[] { "collection/idbag/Mappings.hbm.xml" };
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( PersistentIdBagTest.class );
	
public voidtestWriteMethodDirtying()

		IdbagOwner parent = new IdbagOwner( "root" );
		IdbagOwner child = new IdbagOwner( "c1" );
		parent.getChildren().add( child );
		IdbagOwner otherChild = new IdbagOwner( "c2" );

		Session session = openSession();
		session.beginTransaction();
		session.save( parent );
		session.flush();
		// at this point, the list on parent has now been replaced with a PersistentBag...
		PersistentIdentifierBag children = ( PersistentIdentifierBag ) parent.getChildren();

		assertFalse( children.remove( otherChild ) );
		assertFalse( children.isDirty() );

		ArrayList otherCollection = new ArrayList();
		otherCollection.add( child );
		assertFalse( children.retainAll( otherCollection ) );
		assertFalse( children.isDirty() );

		otherCollection = new ArrayList();
		otherCollection.add( otherChild );
		assertFalse( children.removeAll( otherCollection ) );
		assertFalse( children.isDirty() );

		children.clear();
		session.delete( child );
		assertTrue( children.isDirty() );

		session.flush();

		children.clear();
		assertFalse( children.isDirty() );

		session.delete( parent );
		session.getTransaction().commit();
		session.close();