@Inner("Solve the problem of lazy loading of classes; e.g. no SuperclassTableInheritanceJDO#ChildToParentWithoutDiscriminator")
public class MigratorTest extends JDOTestCase {
public void testMigrateOneToOneUni() {
// Persist Parent+Child (1-1 relation) to old storage version
PersistenceManagerFactory oldPMF = JDOHelper.getPersistenceManagerFactory("originalStorageVersion");
PersistenceManager oldPM = oldPMF.getPersistenceManager();
MigratorOneToOneParent p = new MigratorOneToOneParent();
p.setName("First Parent");
MigratorOneToOneChild c = new MigratorOneToOneChild();
c.setName("Child 1");
p.setChild(c);
beginTxn();
oldPM.makePersistent(p);
commitTxn();
ObjectIdentity pId = (ObjectIdentity)oldPM.getObjectId(p);
ObjectIdentity cId = (ObjectIdentity)oldPM.getObjectId(c);
Key pIdKey = (Key)pId.getKey();
Key cIdKey = (Key)cId.getKey();
oldPM.close();
// Migrate the data
Migrator migrator = new Migrator(((JDOPersistenceManagerFactory)oldPMF).getNucleusContext());
try {
// Migrate the parent
Entity pEntity = ds.get(pIdKey);
boolean changed = migrator.migrate(pEntity, MigratorOneToOneParent.class);
assertTrue("Parent entity should have been changed but wasnt", changed);
if (changed) {
ds.put(pEntity);
}
// Migrate the child
Entity cEntity = ds.get(cIdKey);
changed = migrator.migrate(cEntity, MigratorOneToOneChild.class);
assertFalse("Child entity shouldnt have been changed but was", changed);
if (changed) {
ds.put(cEntity);
}
assertTrue("Child keys property not added to parent", pEntity.hasProperty("child_id_OID"));
Object propValue = pEntity.getProperty("child_id_OID");
assertNotNull(propValue);
assertEquals("Child key property value is not the same as the child key", cIdKey, propValue);
} catch (EntityNotFoundException enfe) {
fail("Some entity was not found");
}
oldPMF.close();
}