FolderListener folderListener = null;
BookMarkListener bookMarkListener = null;
SearchMarkListener searchMarkListener = null;
try {
/* Add */
final IFolder oldParent = fFactory.createFolder(null, null, "Old parent");
FeedReference feedRef = new FeedReference(Long.MAX_VALUE);
final IBookMark bookMark = fFactory.createBookMark(null, oldParent,
new URL("http://www.link.com"), feedRef, "bookmark");
final ISearchMark searchMark = fFactory.createSearchMark(null, oldParent, "searchmark");
fDao.saveFolder(oldParent);
final IFolder newParent = fFactory.createFolder(null, null, "New parent");
fFactory.createFolder(null, newParent, "New parent child");
fDao.saveFolder(newParent);
final boolean[] bookMarkUpdateEventOccurred = new boolean[1];
bookMarkListener = new BookMarkListener() {
public void bookMarkAdded(Set<BookMarkEvent> events) {
fail("Unexpected event");
}
public void bookMarkDeleted(Set<BookMarkEvent> events) {
fail("Unexpected event");
}
public void bookMarkUpdated(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(oldParent, event.getOldParent());
assertEquals(newParent, event.getEntity().getFolder());
}
};
final boolean[] searchMarkUpdateEventOccurred = new boolean[1];
searchMarkListener = new SearchMarkListener() {
public void searchMarkAdded(Set<SearchMarkEvent> events) {
fail("Unexpected event");
}
public void searchMarkDeleted(Set<SearchMarkEvent> events) {
fail("Unexpected event");
}
public void searchMarkUpdated(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(oldParent, event.getOldParent());
assertEquals(newParent, event.getEntity().getFolder());
}
};
final boolean[] folderUpdateEventOccurred = new boolean[1];
folderListener = new FolderListener() {
public void folderAdded(Set<FolderEvent> events) {
fail("Unexpected event");
}
public void folderDeleted(Set<FolderEvent> events) {
fail("Unexpected event");
}
public void folderUpdated(Set<FolderEvent> events) {
folderUpdateEventOccurred[0] = true;
assertEquals(3, events.size());
for (FolderEvent event : events) {
assertFalse("Expected this Event to be NO Root Event", event.isRoot());
}
}
};
fModel.addFolderListener(folderListener);
fModel.addBookMarkListener(bookMarkListener);
fModel.addSearchMarkListener(searchMarkListener);
Map<IMark, IFolder> markFoldersMap = new HashMap<IMark, IFolder>();
markFoldersMap.put(bookMark, newParent);
markFoldersMap.put(searchMark, newParent);
fAppLayer.reparentMark(markFoldersMap);
/* Asserts Follow */
assertFalse(oldParent.getFolders().contains(bookMark));
assertFalse(oldParent.getFolders().contains(searchMark));
assertEquals(0, oldParent.getMarks().size());
assertTrue(newParent.getMarks().contains(bookMark));
assertTrue(newParent.getMarks().contains(searchMark));
assertEquals(newParent, bookMark.getFolder());
assertEquals(newParent, searchMark.getFolder());
assertEquals(2, newParent.getMarks().size());
assertTrue("Missing folderUpdated Event", folderUpdateEventOccurred[0]);
assertTrue("Missing bookMarkUpdated Event", bookMarkUpdateEventOccurred[0]);
assertTrue("Missing searchMarkUpdated Event", searchMarkUpdateEventOccurred[0]);
fModel.removeFolderListener(folderListener);
fModel.removeBookMarkListener(bookMarkListener);
fModel.removeSearchMarkListener(searchMarkListener);
/* Delete */
fDao.deleteFolder(new FolderReference(newParent.getId()));
fDao.deleteFolder(new FolderReference(oldParent.getId()));
} finally {
/* Cleanup */
if (folderListener != null)
fModel.removeFolderListener(folderListener);