{
/* Initial Add News */
String url = "http://www.feed-case1.com";
IFeed feed = createFeed(url);
fFactory.createNews(null, feed, new Date()).setTitle("News Title Case_1");
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/*
* Recreate the feed because the existing one got changed when it was
* saved
*/
feed = createFeed(url);
/* a) Add the same News */
fFactory.createNews(null, feed, new Date()).setTitle("News Title Case_1");
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
}
/* Case 2: News with Title and URL */
{
/* Initial Add News */
String url = "http://www.feed-case2.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_2");
news.setLink(new URI("http://www.news-case2.com/index.html"));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_2");
news.setLink(new URI("http://www.news-case2.com/index.html"));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_2 Updated");
news.setLink(new URI("http://www.news-case2.com/index.html"));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
}
/* Case 3: News with Title and Guid */
{
/* Initial Add News */
String url = "http://www.feed-case3.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_3");
fFactory.createGuid(news, "News_Case_3_Guid", null);
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_3");
fFactory.createGuid(news, "News_Case_3_Guid", null);
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_3 Updated");
fFactory.createGuid(news, "News_Case_3_Guid", null);
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
}
/* Case 4: News with Title and Publish Date */
{
/* Initial Add News */
long time = System.currentTimeMillis();
String url = "http://www.feed-case4.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_4");
news.setPublishDate(new Date(time));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_4");
news.setPublishDate(new Date(time));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Publish Date */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_4");
news.setPublishDate(new Date(System.currentTimeMillis() + 1000));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not READ!", INews.State.READ, feedRef.resolve().getNews().get(0).getState());
}
/* Case 5: News with Title, URL and Publish Date */
{
/* Initial Add News */
long time = System.currentTimeMillis();
String url = "http://www.feed-case5.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_5");
news.setLink(new URI("http://www.news-case5.com/index.html"));
news.setPublishDate(new Date(time));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_5");
news.setLink(new URI("http://www.news-case5.com/index.html"));
news.setPublishDate(new Date(time));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_5 Updated");
news.setLink(new URI("http://www.news-case5.com/index.html"));
news.setPublishDate(new Date(time));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* c) Add the same News with updated Publish Date */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_5 Updated");
news.setLink(new URI("http://www.news-case5.com/index.html"));
news.setPublishDate(new Date(System.currentTimeMillis() + 1000));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not READ!", INews.State.READ, feedRef.resolve().getNews().get(0).getState());
}
/* Case 6: News with Title, Guid and Publish Date */
{
/* Initial Add News */
long time = System.currentTimeMillis();
String url = "http://www.feed-case6.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_6");
fFactory.createGuid(news, "News_Case_6_Guid", null);
news.setPublishDate(new Date(time));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_6");
fFactory.createGuid(news, "News_Case_6_Guid", null);
news.setPublishDate(new Date(time));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_6 Updated");
fFactory.createGuid(news, "News_Case_6_Guid", null);
news.setPublishDate(new Date(time));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* c) Add the same News with updated Guid */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_6");
fFactory.createGuid(news, "News_Case_6_Guid_Updated", null);
news.setPublishDate(new Date(time));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Expected two News in this Feed!", 2, feedRef.resolve().getNews().size());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* d) Add the same News with updated Publish Date */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_6");
fFactory.createGuid(news, "News_Case_6_Guid", null);
news.setPublishDate(new Date(time + 1000));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 2, feedRef.resolve().getNews().size());
List<INews> newsRefs = feedRef.resolve().getNews();
for (INews newsRef : newsRefs) {
if ("News_Case_6_Guid".equals(newsRef.getGuid().getValue()))
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, newsRef.getState());
}
}
/* Case 7: News with Title, URL and Guid */
{
/* Initial Add News */
String url = "http://www.feed-case7.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_7");
fFactory.createGuid(news, "News_Case_7_Guid", null);
news.setLink(new URI("http://www.news-case7.com/index.html"));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_7");
fFactory.createGuid(news, "News_Case_7_Guid", null);
news.setLink(new URI("http://www.news-case7.com/index.html"));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_7 Updated");
fFactory.createGuid(news, "News_Case_7_Guid", null);
news.setLink(new URI("http://www.news-case7.com/index.html"));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* c) Add the same News with updated URL */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_7 Updated");
fFactory.createGuid(news, "News_Case_7_Guid", null);
news.setLink(new URI("http://www.news-case7.com/index-updated.html"));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not READ!", INews.State.READ, feedRef.resolve().getNews().get(0).getState());
/* d) Add the same News with updated Guid */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_7");
fFactory.createGuid(news, "News_Case_7_Guid_Updated", null);
news.setLink(new URI("http://www.news-case7.com/index.html"));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Expected two News in this Feed!", 2, feedRef.resolve().getNews().size());
}
/* Case 8: News with Title, URL, Guid and Publish Date */
{
/* Initial Add News */
long time = System.currentTimeMillis();
String url = "http://www.feed-case8.com";
IFeed feed = createFeed(url);
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_8");
news.setLink(new URI("http://www.news-case8.com/index.html"));
fFactory.createGuid(news, "News_Case_8_Guid", null);
news.setPublishDate(new Date(time));
FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
/* a) Add the same News */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_8");
news.setLink(new URI("http://www.news-case8.com/index.html"));
fFactory.createGuid(news, "News_Case_8_Guid", null);
news.setPublishDate(new Date(time));
IFeed mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* b) Add the same News with updated Title */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_8 Updated");
news.setLink(new URI("http://www.news-case8.com/index.html"));
fFactory.createGuid(news, "News_Case_8_Guid", null);
news.setPublishDate(new Date(time));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* c) Add the same News with updated Guid */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_8");
news.setLink(new URI("http://www.news-case8.com/index.html"));
fFactory.createGuid(news, "News_Case_8_Guid_Updated", null);
news.setPublishDate(new Date(time));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Expected two News in this Feed!", 2, feedRef.resolve().getNews().size());
/* Mark News Read */
news = feedRef.resolve().getNews().get(0);
news.setState(INews.State.READ);
DynamicDAO.save(news);
/* d) Add the same News with updated Publish Date */
feed = createFeed(url);
news = fFactory.createNews(null, feed, new Date());
news.setTitle("News Title Case_8");
news.setLink(new URI("http://www.news-case8.com/index.html"));
fFactory.createGuid(news, "News_Case_8_Guid", null);
news.setPublishDate(new Date(System.currentTimeMillis() + 1000));
mergedFeed = feedRef.resolve();
mergedFeed.merge(feed);
feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
assertEquals("Same News was added twice!", 2, feedRef.resolve().getNews().size());
List<INews> newsRefs = feedRef.resolve().getNews();
for (INews newsRef : newsRefs) {
if ("News_Case_8_Guid".equals(newsRef.getGuid().getValue()))
assertEquals("Existing News State is not UPDATED!", INews.State.UPDATED, newsRef.getState());
}
}