IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
fFactory.createNews(null, feed, new Date());
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
IBookMark mark = fFactory.createBookMark(null, root, new FeedLinkReference(feed.getLink()), "BookMark");
root = DynamicDAO.save(root);
mark = (IBookMark) root.getMarks().get(0);
assertEquals(1, new FeedReference(feed.getId()).resolve().getNews().size());
NewsReference newsRef = new NewsReference(feedRef.resolve().getNews().get(0).getId());
DynamicDAO.delete(root);
assertNull("Expected this Entity to be NULL", new FolderReference(root.getId()).resolve());
assertNull("Expected this Entity to be NULL", new BookMarkReference(mark.getId()).resolve());
assertNull("Expected this Entity to be NULL", feedRef.resolve());
assertNull("Expected this Entity to be NULL", newsRef.resolve());
}
/* Root Folder, Folder, BookMark, Feed, News (Folder Deleted) */
{
IFolder root = fFactory.createFolder(null, null, "Root");
root = DynamicDAO.save(root);
IFolder folder = fFactory.createFolder(null, root, "Folder");
folder = DynamicDAO.save(folder);
IFeed feed = fFactory.createFeed(null, new URI("http://www.feed2.com"));
fFactory.createNews(null, feed, new Date());
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
IBookMark mark = fFactory.createBookMark(null, folder, new FeedLinkReference(feed.getLink()), "BookMark");
folder = DynamicDAO.save(folder);
mark = (IBookMark) folder.getMarks().get(0);
assertEquals(1, new FeedReference(feed.getId()).resolve().getNews().size());
NewsReference newsRef = new NewsReference(feedRef.resolve().getNews().get(0).getId());
DynamicDAO.delete(folder);
assertNull("Expected this Entity to be NULL", new FolderReference(folder.getId()).resolve());
assertNull("Expected this Entity to be NULL", new BookMarkReference(mark.getId()).resolve());
assertNull("Expected this Entity to be NULL", feedRef.resolve());
assertNull("Expected this Entity to be NULL", newsRef.resolve());
}
/* Root Folder, Folder, BookMark, Feed, News (Folder Deleted #2) */
{
IFolder root = fFactory.createFolder(null, null, "Root");
root = DynamicDAO.save(root);
IFolder folder = fFactory.createFolder(null, root, "Folder");
folder = DynamicDAO.save(folder);
IFeed feed = fFactory.createFeed(null, new URI("http://www.feed3.com"));
fFactory.createNews(null, feed, new Date());
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
IBookMark mark = fFactory.createBookMark(null, folder, new FeedLinkReference(feed.getLink()), "BookMark");
folder = DynamicDAO.save(folder);
mark = (IBookMark) folder.getMarks().get(0);
assertEquals(1, new FeedReference(feed.getId()).resolve().getNews().size());
NewsReference newsRef = new NewsReference(feedRef.resolve().getNews().get(0).getId());
/* Delete by calling delete */
DynamicDAO.delete(folder);
final long rootFolderId = root.getId();
FolderListener folderListener = new FolderAdapter() {
@Override
public void entitiesUpdated(Set<FolderEvent> events) {
for (FolderEvent event : events) {
if (event.getEntity().getId() == rootFolderId)
assertTrue(event.isRoot());
else
assertFalse(event.isRoot());
}
}
};
DynamicDAO.addEntityListener(IFolder.class, folderListener);
try {
DynamicDAO.save(root);
} finally {
DynamicDAO.removeEntityListener(IFolder.class, folderListener);
}
assertNull("Expected this Entity to be NULL", new FolderReference(folder.getId()).resolve());
assertNull("Expected this Entity to be NULL", new BookMarkReference(mark.getId()).resolve());
assertNull("Expected this Entity to be NULL", feedRef.resolve());
assertNull("Expected this Entity to be NULL", newsRef.resolve());
}
/* Folder, BookMark, Feed, News (BookMark Deleted) */
{
IFolder root = fFactory.createFolder(null, null, "Root");
root = DynamicDAO.save(root);
IFeed feed = fFactory.createFeed(null, new URI("http://www.feed4.com"));
fFactory.createNews(null, feed, new Date());
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
IBookMark mark = fFactory.createBookMark(null, root, new FeedLinkReference(feed.getLink()), "BookMark");
root = DynamicDAO.save(root);
mark = (IBookMark) root.getMarks().get(0);
assertEquals(1, new FeedReference(feed.getId()).resolve().getNews().size());
NewsReference newsRef = new NewsReference(feedRef.resolve().getNews().get(0).getId());
DynamicDAO.delete(mark);
assertNull("Expected this Entity to be NULL", new BookMarkReference(mark.getId()).resolve());
assertNull("Expected this Entity to be NULL", feedRef.resolve());
assertNull("Expected this Entity to be NULL", newsRef.resolve());
}
/* Folder, BookMark, Feed, News (BookMark Deleted #2) */
{
IFolder root = fFactory.createFolder(null, null, "Root");
root = DynamicDAO.save(root);
IFeed feed = fFactory.createFeed(null, new URI("http://www.feed5.com"));
fFactory.createNews(null, feed, new Date());
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
IBookMark mark = fFactory.createBookMark(null, root, new FeedLinkReference(feed.getLink()), "BookMark");
root = DynamicDAO.save(root);
mark = (IBookMark) root.getMarks().get(0);
assertEquals(1, new FeedReference(feed.getId()).resolve().getNews().size());
NewsReference newsRef = new NewsReference(feedRef.resolve().getNews().get(0).getId());
/* Delete by calling delete */
DynamicDAO.delete(mark);
assertNull("Expected this Entity to be NULL", new BookMarkReference(mark.getId()).resolve());
assertNull("Expected this Entity to be NULL", feedRef.resolve());
assertNull("Expected this Entity to be NULL", newsRef.resolve());
}
/* Feed, News (Feed Deleted) */