}
public void testAutoFix() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
Node root = s.getRootNode();
// add nodes /test and /test/missing
Node test = root.addNode("test");
Node missing = test.addNode("missing");
missing.addMixin("mix:referenceable");
UUID id = UUID.fromString(missing.getIdentifier());
s.save();
s.logout();
destroyBundle(id, "workspaces/default");
// login and try the operation
s = openSession(rep, false);
test = s.getRootNode().getNode("test");
// try to add a node with the same name
try {
test.addNode("missing");
s.save();
} catch (RepositoryException e) {
// expected
}
s.logout();
s = openSession(rep, true);
test = s.getRootNode().getNode("test");
// iterate over all child nodes fixes the corruption
NodeIterator it = test.getNodes();
while (it.hasNext()) {
it.nextNode();
}
// try to add a node with the same name
test.addNode("missing");
s.save();
// try to delete the parent node
test.remove();
s.save();
s.logout();
rep.shutdown();
FileUtils.deleteDirectory(new File("repository"));
}