FolderListener folderListener = null;
BookMarkListener bookMarkListener = null;
SearchMarkListener searchMarkListener = null;
try {
/* Add */
final IFolder oldMarkParent = fFactory.createFolder(null, null, "Old parent");
final IBookMark bookMark = fFactory.createBookMark(null, oldMarkParent, new FeedLinkReference(new URI("http://www.link.com")), "bookmark");
final ISearchMark searchMark = fFactory.createSearchMark(null, oldMarkParent, "searchmark");
DynamicDAO.save(oldMarkParent);
final IFolder newMarkParent = fFactory.createFolder(null, null, "New parent");
fFactory.createFolder(null, newMarkParent, "New parent child");
DynamicDAO.save(newMarkParent);
/* Add */
final IFolder oldFolderParent = fFactory.createFolder(null, null, "Old parent");
final IFolder folder = fFactory.createFolder(null, oldFolderParent, "Folder");
DynamicDAO.save(oldFolderParent);
final IFolder newFolderParent = fFactory.createFolder(null, null, "New parent");
fFactory.createFolder(null, newFolderParent, "New parent child");
DynamicDAO.save(newFolderParent);
final boolean[] folderUpdateEventOccurred = new boolean[1];
folderListener = new FolderListener() {
public void entitiesAdded(Set<FolderEvent> events) {
fail("Unexpected event");
}
public void entitiesDeleted(Set<FolderEvent> events) {
fail("Unexpected event");
}
public void entitiesUpdated(Set<FolderEvent> events) {
folderUpdateEventOccurred[0] = true;
assertEquals(7, events.size());
boolean foundFolder = false;
for (FolderEvent event : events) {
if (event.getEntity().equals(folder)) {
foundFolder = true;
assertTrue("Expected this Event to be Root Event", event.isRoot());
assertEquals(oldFolderParent, event.getOldParent());
assertEquals(newFolderParent, event.getEntity().getParent());
} else
assertFalse("Expected this Event to be NO Root Event", event.isRoot());
}
assertTrue("No event was issued for folder", foundFolder);
}
};
final boolean[] bookMarkUpdateEventOccurred = new boolean[1];
bookMarkListener = new BookMarkListener() {
public void entitiesAdded(Set<BookMarkEvent> events) {
fail("Unexpected event");
}
public void entitiesDeleted(Set<BookMarkEvent> events) {
fail("Unexpected event");
}
public void entitiesUpdated(Set<BookMarkEvent> events) {
bookMarkUpdateEventOccurred[0] = true;
assertEquals(1, events.size());
BookMarkEvent event = events.iterator().next();
assertEquals(bookMark, event.getEntity());
assertTrue("Expected this Event to be Root Event", event.isRoot());
assertEquals(oldMarkParent, event.getOldParent());
assertEquals(newMarkParent, event.getEntity().getParent());
}
};
final boolean[] searchMarkUpdateEventOccurred = new boolean[1];
searchMarkListener = new SearchMarkListener() {
public void entitiesAdded(Set<SearchMarkEvent> events) {
fail("Unexpected event");
}
public void entitiesDeleted(Set<SearchMarkEvent> events) {
fail("Unexpected event");
}
public void entitiesUpdated(Set<SearchMarkEvent> events) {
searchMarkUpdateEventOccurred[0] = true;
assertEquals(1, events.size());
SearchMarkEvent event = events.iterator().next();
assertEquals(searchMark, event.getEntity());
assertTrue("Expected this Event to be Root Event", event.isRoot());
assertEquals(oldMarkParent, event.getOldParent());
assertEquals(newMarkParent, event.getEntity().getParent());
}
public void resultsChanged(Set<SearchMarkEvent> events) {
fail("Unexpected event");
}
};
DynamicDAO.addEntityListener(IFolder.class, folderListener);
DynamicDAO.addEntityListener(IBookMark.class, bookMarkListener);
DynamicDAO.addEntityListener(ISearchMark.class, searchMarkListener);
List<ReparentInfo<IFolderChild, IFolder>> reparentInfos = new ArrayList<ReparentInfo<IFolderChild, IFolder>>();
reparentInfos.add(new ReparentInfo<IFolderChild, IFolder>(folder, newFolderParent, null, null));
reparentInfos.add(new ReparentInfo<IFolderChild, IFolder>(bookMark, newMarkParent, null, null));
reparentInfos.add(new ReparentInfo<IFolderChild, IFolder>(searchMark, newMarkParent, null, null));
Owl.getPersistenceService().getDAOService().getFolderDAO().reparent(reparentInfos);
/* Asserts Follow */
/* Folder reparenting */
assertFalse(oldFolderParent.getFolders().contains(folder));
assertEquals(0, oldFolderParent.getFolders().size());
assertTrue(newFolderParent.getFolders().contains(folder));
assertEquals(newFolderParent, folder.getParent());
assertEquals(2, newFolderParent.getFolders().size());
/* Marks reparenting */
assertFalse(oldMarkParent.getFolders().contains(bookMark));
assertFalse(oldMarkParent.getFolders().contains(searchMark));
assertEquals(0, oldMarkParent.getMarks().size());