* @throws Exception if a database error occurs.
*/
public void testFillReferencingCompositeKey() throws Exception
{
ForeignKeySchemaData.clearTablesInDatabase();
ForeignKeySchemaData testData
= ForeignKeySchemaData.getDefaultTestData();
testData.save();
Criteria criteria = new Criteria();
criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID1);
criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID2);
List<CompIntegerVarcharPk> pkList
= CompIntegerVarcharPkPeer.doSelect(criteria);
assertEquals(3, pkList.size());
assertEquals(
testData.getCompositeIntegerVarcharPkList().get(0).getPrimaryKey(),
pkList.get(0).getPrimaryKey());
// check referencing lists are not initialized
for (CompIntegerVarcharPk compIntegerVarcharPk : pkList)
{
assertFalse(compIntegerVarcharPk.isCompIntegerVarcharFksInitialized());
}
List<CompIntegerVarcharFk> referencingFkList
= CompIntegerVarcharPkPeer.fillCompIntegerVarcharFks(
pkList);
// returned list must contain compositeIntegerVarcharFk2,
// compositeIntegerVarcharFk3a, compositeIntegerVarcharFk3b
// where the order of the last two is undefined
assertEquals(3, referencingFkList.size());
assertEquals(
testData.getCompositeIntegerVarcharFkList().get(0).getId(),
referencingFkList.get(0).getId());
assertTrue(
referencingFkList.contains(
testData.getCompositeIntegerVarcharFkList().get(1)));
assertTrue(
referencingFkList.contains(
testData.getCompositeIntegerVarcharFkList().get(2)));
// The second pk entry must reference compositeIntegerVarcharFk2
// and the third pk entry must reference compositeIntegerVarcharFk3a
// and compositeIntegerVarcharFk3b
assertEquals(0, pkList.get(0).getCompIntegerVarcharFks().size());
assertEquals(1, pkList.get(1).getCompIntegerVarcharFks().size());
assertEquals(2, pkList.get(2).getCompIntegerVarcharFks().size());
assertEquals(
testData.getCompositeIntegerVarcharFkList().get(0),
pkList.get(1).getCompIntegerVarcharFks().get(0));
assertTrue(
pkList.get(2).getCompIntegerVarcharFks().contains(
testData.getCompositeIntegerVarcharFkList().get(1)));
assertTrue(
pkList.get(2).getCompIntegerVarcharFks().contains(
testData.getCompositeIntegerVarcharFkList().get(2)));
// The objects in the result list must be the same objects
// as the referenced objects in the pk list
assertSame(
referencingFkList.get(0),