* Test the attach method: make an inherited object persistent, detach it then attach it.
*/
public void testAttachInherited() {
logger.log(BasicLevel.DEBUG, "***************testAttachInherited*****************");
Car c = new Car("r5", 4, "red");
FormulaOne f = new FormulaOne("williams", 4, "green", 262);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
logger.log(BasicLevel.DEBUG, "make persistent the car " + c.toString() );
logger.log(BasicLevel.DEBUG, "make persistent the formula one " + f.toString());
pm.makePersistent(c);
pm.makePersistent(f);
pm.currentTransaction().commit();
//detach the car c
Car copyOfC = (Car) pm.detachCopy(c);
//print the car out
logger.log(BasicLevel.DEBUG, copyOfC.toString());
//detach the formula one f
FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
//print the formula one out
logger.log(BasicLevel.DEBUG, copyOfF.toString());
pm.currentTransaction().begin();
//attach the copied car
Car attachedCar = (Car) pm.makePersistent(copyOfC);
//attach the copied formula one
FormulaOne attachedF = (FormulaOne) pm.makePersistent(copyOfF);
pm.currentTransaction().commit();
try {
assertNotNull(attachedCar);
assertEquals(copyOfC.getColor(), attachedCar.getColor());
assertEquals(copyOfC.getName(), attachedCar.getName());
assertEquals(copyOfC.getNbOfWheels(), attachedCar.getNbOfWheels());
assertEquals(copyOfC.getType(), attachedCar.getType());
assertNotNull(attachedF);
assertEquals(copyOfF.getColor(), attachedF.getColor());
assertEquals(copyOfF.getName(), attachedF.getName());
assertEquals(copyOfF.getNbOfWheels(), attachedF.getNbOfWheels());
assertEquals(copyOfF.getType(), attachedF.getType());
assertEquals(copyOfF.getSpeedMax(), attachedF.getSpeedMax());
logger.log(BasicLevel.DEBUG,"The attached version of the car is as follows:\n " + attachedCar.toString());
logger.log(BasicLevel.DEBUG,"The attached version of the formula one is as follows:\n " + attachedF.toString());
} catch (Exception e) {
fail(e.getMessage());
} finally {
if (pm.currentTransaction().isActive())
pm.currentTransaction().rollback();