templateDef.setEnabled(true);
templateDef.setDriftHandlingMode(normal);
templateDef.setInterval(2400L);
templateDef.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));
final DriftDefinitionTemplate template = templateMgr.createTemplate(getOverlord(), resourceType.getId(), true,
templateDef);
// next create some resource level definitions
final DriftDefinition attachedDef1 = createDefinition(template, NAME_PREFIX + "attachedDef1", true);
final DriftDefinition attachedDef2 = createDefinition(template, NAME_PREFIX + "attachedDef2", true);
final DriftDefinition detachedDef1 = createDefinition(template, NAME_PREFIX + "detachedDef1", false);
final DriftDefinition detachedDef2 = createDefinition(template, NAME_PREFIX + "detachedDef2", false);
// create some change sets
final JPADriftChangeSet changeSet0 = new JPADriftChangeSet(resource, 0, COVERAGE, attachedDef1);
driftFile1 = new JPADriftFile(driftFile1Hash);
drift1 = new JPADrift(changeSet0, drift1Path, FILE_ADDED, null, driftFile1);
final JPADriftSet driftSet0 = new JPADriftSet();
driftSet0.addDrift(drift1);
final JPADriftChangeSet changeSet1 = new JPADriftChangeSet(resource, 0, DRIFT, detachedDef1);
driftFile2 = new JPADriftFile(driftFile2Hash);
drift2 = new JPADrift(changeSet1, drift2Path, FILE_ADDED, null, driftFile2);
final JPADriftSet driftSet1 = new JPADriftSet();
driftSet1.addDrift(drift2);
executeInTransaction(false, new TransactionCallback() {
@Override
public void execute() throws Exception {
em.persist(attachedDef1);
em.persist(attachedDef2);
em.persist(detachedDef1);
em.persist(detachedDef2);
em.persist(driftFile1);
em.persist(driftFile2);
em.persist(changeSet0);
em.persist(driftSet0);
changeSet0.setInitialDriftSet(driftSet0);
em.merge(changeSet0);
em.persist(changeSet1);
em.persist(driftSet1);
changeSet1.setInitialDriftSet(driftSet1);
em.merge(changeSet1);
}
});
// delete the template
templateMgr.deleteTemplate(getOverlord(), template.getId());
// verify that attached definitions along with their change sets have
// been deleted
assertNull("Change sets belonging to attached definitions should be deleted", loadChangeSet(changeSet0.getId()));
assertNull("Attached definition " + toString(attachedDef1) + " should be deleted",
loadDefinition(attachedDef1.getId()));
assertNull("Attached definition " + toString(attachedDef2) + " should be deleted",
loadDefinition(attachedDef2.getId()));
// verify that detached definitions along with their change sets have not been deleted
assertNotNull("Change sets belonging to detached definitions should not be deleted",
loadChangeSet(changeSet1.getId()));
assertDetachedDefinitionNotDeleted(detachedDef1.getId());
assertDetachedDefinitionNotDeleted(detachedDef2.getId());
// verify that the template itself has been deleted
assertNull("The template " + toString(template) + " should have been deleted",
loadTemplate(template.getName(), false));
}