public void testPersistSubclass() {
Object id = null;
try {
getPM().currentTransaction().begin();
Kitchen kitchen = new Kitchen(1);
MultifunctionOven oven = new MultifunctionOven("Westinghouse", "Economy");
oven.setMicrowave(true);
oven.setCapabilities("TIMER,CLOCK");
kitchen.setOven(oven);
getPM().makePersistent(kitchen);
getPM().currentTransaction().commit();
id = getPM().getObjectId(kitchen);
}
catch (Exception e) {
fail("Exception on persist : " + e.getMessage());
}
finally {
if (getPM().currentTransaction().isActive()) {
getPM().currentTransaction().rollback();
}
}
getPM().currentTransaction().begin();
Kitchen kitchen = (Kitchen)getPM().getObjectById(id);
assertEquals("Id of object is incorrect", 1, kitchen.getId());
Oven oven = kitchen.getOven();
assertNotNull("Oven of Kitchen is null!", oven);
assertEquals("Oven is of incorrect type", MultifunctionOven.class.getName(),
oven.getClass().getName());
MultifunctionOven multioven = (MultifunctionOven)oven;
assertEquals("Oven make is incorrect", "Westinghouse", multioven.getMake());
assertEquals("Oven model is incorrect", "Economy", multioven.getModel());
assertEquals("Oven microwave setting is incorrect", true, multioven.getMicrowave());
assertEquals("Oven capabilities is incorrect", "TIMER,CLOCK", multioven.getCapabilities());
getPM().currentTransaction().commit();
}