Package org.rssowl.core.model.reference

Examples of org.rssowl.core.model.reference.NewsReference


  @Test
  public void testRemoveNewsWithoutFeed() throws Exception {
    IFeed feed = createFeed("http://www.rssowl.org");
    fFactory.createNews(null, feed, new Date());
    IFeed savedFeed = fDao.saveFeed(feed);
    fDao.deleteNews(new NewsReference(feed.getNews().get(0).getId()));
    savedFeed = fDao.loadFeed(savedFeed.getId());
    assertNotNull(savedFeed);
  }
View Full Code Here


      final IAttachment attachment0 = fFactory.createAttachment(null, news);
      attachment0.setUrl(new URI("http://www.attachment1.com"));
      final IAttachment attachment1 = fFactory.createAttachment(null, news);
      attachment1.setUrl(new URI("http://www.attachment1.com"));
      fDao.saveFeed(feed);
      NewsReference newsRef = new NewsReference(feed.getNews().get(0).getId());
      AttachmentReference attachmentRef0 = new AttachmentReference(news.getAttachments().get(0).getId());
      AttachmentReference attachmentRef1 = new AttachmentReference(news.getAttachments().get(1).getId());
     
      final boolean[] newsDeleted = new boolean[1];
      newsListener = new NewsListener() {
        public void newsDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());
            if (event.getEntity().getTitle().equals(news.getTitle()))
              newsDeleted[0] = true;

            try {
              assertEquals(new URL("http://www.foobar.com").toString(),
                  event.getEntity().getFeedReference().getLink().toString());
            } catch (MalformedURLException e) {
              fail(e.getMessage());
            }
          }
        }
        public void newsUpdated(Set<NewsEvent> events) {
          fail("Unexpected event");
        }
        public void newsAdded(Set<NewsEvent> events) {
          fail("Unexpected event");
        }
      };
      fModel.addNewsListener(newsListener);

      /* Check Attachments Added */
      final boolean attachmentDeleted[] = new boolean[2];
      attachmentListener = new AttachmentAdapter() {
        @Override
        public void attachmentDeleted(Set<AttachmentEvent> events) {
          for (AttachmentEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            IAttachment attachment = event.getEntity();

            if (attachment.getUrl().equals(attachment0.getUrl()))
              attachmentDeleted[0] = true;
            if (attachment.getUrl().equals(attachment1.getUrl()))
              attachmentDeleted[1] = true;
          }
        }
      };
      fModel.addAttachmentListener(attachmentListener);

      fDao.deleteFeed(new FeedReference(feed.getId()));
      assertNull(fDao.loadFeed(feed.getId()));
      assertNull(fDao.loadNews(newsRef.getId()));
      assertNull(fDao.loadAttachment(attachmentRef0.getId()));
      assertNull(fDao.loadAttachment(attachmentRef1.getId()));
     
      assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
      assertTrue("Missed attachmentDeleted Event in PersonListener!", attachmentDeleted[0]);
View Full Code Here

      final NewsReference[] newsRef = new NewsReference[1];
      newsAdapter = new NewsAdapter() {
        @Override
        public void newsAdded(Set<NewsEvent> events) {
          assertEquals(1, events.size());
          newsRef[0] = new NewsReference(events.iterator().next().getEntity().getId());
        }
      };
      fModel.addNewsListener(newsAdapter);
      /* Must save parent because it gets changed during creation of news */
      fDao.saveFeed(feedRef.resolve());
      final NewsReference newsRef1 = newsRef[0];
      final PersonReference personRef2 = new PersonReference(newsRef1.resolve().getAuthor().getId());

      final INews news2 = fFactory.createNews(null, feedRef.resolve(), new Date());
      news2.setTitle("News2 Title");
      news2.setLink(new URI("http://www.news.com/news2.html"));
      fFactory.createSource(news2).setUrl(new URI("http://www.source2.com"));
      fFactory.createGuid(news2, "Guid2");
      /* Must save parent because it gets changed during creation of news */
      fDao.saveFeed(feedRef.resolve());
      final NewsReference newsRef2 = newsRef[0];

      final INews news3 = fFactory.createNews(null, feedRef.resolve(), new Date());
      news3.setTitle("News3 Title");
      news3.setLink(new URI("http://www.news.com/news3.html"));
      fFactory.createSource(news3).setUrl(new URI("http://www.source3.com"));
      fFactory.createGuid(news3, "Guid3");
      /* Must save parent because it gets changed during creation of news */
      fDao.saveFeed(feedRef.resolve());
      final NewsReference newsRef3 = newsRef[0];

      final boolean newsDeleted[] = new boolean[3];
      newsListener = new NewsAdapter() {
        @Override
        public void newsDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            NewsReference newsRef = new NewsReference(event.getEntity().getId());

            if (newsRef.equals(newsRef1))
              newsDeleted[0] = true;

            else if (newsRef.equals(newsRef2))
              newsDeleted[1] = true;

            else if (newsRef.equals(newsRef3))
              newsDeleted[2] = true;
          }

          if (events.size() == 3)
            newsDeletedFromFeed[0] = true;
View Full Code Here

      fFactory.createAttachment(null, news);
      fFactory.createAttachment(null, news);
      fFactory.createAttachment(null, news);

      /* Save News */
      final NewsReference newsRef = new NewsReference(fDao.saveNews(news).getId());

      final PersonReference personRef = new PersonReference(fDao.loadNews(newsRef.getId()).getAuthor().getId());
      final AttachmentReference attachmentRef1 = new AttachmentReference(fDao.loadNews(newsRef.getId()).getAttachments().get(0).getId());
      final AttachmentReference attachmentRef2 = new AttachmentReference(fDao.loadNews(newsRef.getId()).getAttachments().get(1).getId());
      final AttachmentReference attachmentRef3 = new AttachmentReference(fDao.loadNews(newsRef.getId()).getAttachments().get(2).getId());
      final CategoryReference categoryRef = new CategoryReference(fDao.loadNews(newsRef.getId()).getCategories().get(0).getId());

      /* Check News Deleted */
      final boolean newsDeleted[] = new boolean[1];
      newsListener = new NewsAdapter() {
        @Override
        public void newsDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertTrue("Expected this Event to be Root Event", event.isRoot());
            if (newsRef.references(event.getEntity()))
              newsDeleted[0] = true;

            try {
              assertEquals(new URL("http://www.foobar.com").toString(),
                  event.getEntity().getFeedReference().getLink().toString());
View Full Code Here

          }
        }
      };
      fModel.addNewsListener(newsListener);

      NewsReference newsReference1 = new NewsReference(fDao.saveNews(news1).getId());
      NewsReference newsReference2 = new NewsReference(fDao.saveNews(news2).getId());
      NewsReference newsReference3 = new NewsReference(fDao.saveNews(news3).getId());

      assertEquals(INews.State.DELETED, fDao.loadFeed(feedRef.getId()).getNews().get(0).getState());
      assertEquals(INews.State.DELETED, fDao.loadFeed(feedRef.getId()).getNews().get(1).getState());
      assertEquals(INews.State.READ, fDao.loadFeed(feedRef.getId()).getNews().get(2).getState());

      /* Check Deleted News now being Deleted from DB */
      feed = fFactory.createFeed(null, new URL("http://www.feed.com"));
      List<INews> removedNews = feedRef.resolve().mergeAndCleanUp(feed);
      fAppLayer.saveFeed(feed, removedNews);

      /* Asserts follow */
      assertEquals(1, fDao.loadFeed(feedRef.getId()).getNews().size());
      assertNull(fDao.loadNews(newsReference1.getId()));
      assertNull(fDao.loadNews(newsReference2.getId()));
      assertNotNull(fDao.loadNews(newsReference3.getId()));

      for (int i = 0; i < newsUpdatedEvents.length; i++)
        if (!newsUpdatedEvents[i])
          fail("Missing newsUpdated event in NewsListener!");
    } catch (PersistenceException e) {
View Full Code Here

      /* Add */
      final IFeed feed = fDao.saveFeed(fFactory.createFeed(null, new URL("http://www.feed.com")));
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("News");
      final boolean newsEvents[] = new boolean[3];
      final NewsReference newsReference[] = new NewsReference[1];
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertTrue("Expected this Event to be Root Event", event.isRoot());
            assertEquals(feed.getLink(), event.getEntity().getFeedReference().getLink());
            newsEvents[0] = true;
          }
        }

        public void newsDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertTrue("Expected this Event to be Root Event", event.isRoot());
            assertEquals(feed.getLink(), event.getEntity().getFeedReference().getLink());
            if (newsReference[0].references(event.getEntity()))
              newsEvents[1] = true;
          }
        }

        public void newsUpdated(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertTrue("Expected this Event to be Root Event", event.isRoot());
            assertEquals(feed.getLink(), event.getEntity().getFeedReference().getLink());
            if (newsReference[0].references(event.getEntity()))
              newsEvents[2] = true;
          }
        }
      };
      fModel.addNewsListener(newsListener);
      newsReference[0] = new NewsReference(fDao.saveNews(news).getId());

      /* Update */
      news = newsReference[0].resolve();
      news.setTitle("News Updated");
      fDao.saveNews(news);
View Full Code Here

  public void testFlatAttachmentEvents() throws Exception {
    AttachmentListener attachmentListener = null;
    try {
      /* Add */
      FeedReference feedRef = new FeedReference(fDao.saveFeed(fFactory.createFeed(null, new URL("http://www.feed1.com"))).getId());
      NewsReference newsRef = new NewsReference(fDao.saveNews(fFactory.createNews(null, feedRef.resolve(), new Date())).getId());
      IAttachment attachment = fFactory.createAttachment(null, newsRef.resolve());
      attachment.setUrl(new URI("http://www.attachment.com"));
      final boolean attachmentEvents[] = new boolean[3];
      final AttachmentReference attachmentReference[] = new AttachmentReference[1];
      attachmentListener = new AttachmentAdapter() {
        @Override
View Full Code Here

  public void testFlatCategoryEvents() throws Exception {
    CategoryListener categoryListener = null;
    try {
      /* Add */
      FeedReference feedRef = new FeedReference(fDao.saveFeed(fFactory.createFeed(null, new URL("http://www.feed2.com"))).getId());
      NewsReference newsRef = new NewsReference(fDao.saveNews(fFactory.createNews(null, feedRef.resolve(), new Date())).getId());
      ICategory category1 = fFactory.createCategory(null, feedRef.resolve());
      category1.setName("Category");
      ICategory category2 = fFactory.createCategory(null, newsRef.resolve());
      category2.setName("Category");
      final boolean categoryEvents[] = new boolean[6];
      final CategoryReference categoryReference[] = new CategoryReference[2];
      categoryListener = new CategoryListener() {
        public void categoryAdded(Set<CategoryEvent> events) {
View Full Code Here

  public void testFlatPersonEvents() throws Exception {
    PersonListener personListener = null;
    try {
      /* Add */
      FeedReference feedRef = new FeedReference(fDao.saveFeed(fFactory.createFeed(null, new URL("http://www.feed4.com"))).getId());
      NewsReference newsRef = new NewsReference(fDao.saveNews(fFactory.createNews(null, feedRef.resolve(), new Date())).getId());
      IPerson person1 = fFactory.createPerson(null, feedRef.resolve());
      person1.setName("Person1");
      IPerson person2 = fFactory.createPerson(null, newsRef.resolve());
      person2.setName("Person2");
      final boolean personEvents[] = new boolean[6];
      final PersonReference personReference[] = new PersonReference[2];
      personListener = new PersonListener() {
        public void personAdded(Set<PersonEvent> events) {
View Full Code Here

      news.setProperty("String", "Foo");
      news.setProperty("Integer", 1);
      news.setProperty("Boolean", true);
      news.setProperty("Double", 2.2D);
      news.setProperty("Float", 3.3F);
      NewsReference newsRef = new NewsReference(fDao.saveNews(news).getId());
      news = newsRef.resolve();
      assertEquals("Foo", news.getProperty("String"));
      assertEquals(1, news.getProperty("Integer"));
      assertEquals(true, news.getProperty("Boolean"));
      assertEquals(2.2D, news.getProperty("Double"));
      assertEquals(3.3F, news.getProperty("Float"));

      /* Add Properties to an Attachment */
      IAttachment attachment = fFactory.createAttachment(null, newsRef.resolve());
      attachment.setUrl(new URI("http://www.attachment.com"));
      attachment.setProperty("String", "Foo");
      attachment.setProperty("Integer", 1);
      attachment.setProperty("Boolean", true);
      attachment.setProperty("Double", 2.2D);
View Full Code Here

TOP

Related Classes of org.rssowl.core.model.reference.NewsReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.