Package org.rssowl.ui.internal.services

Examples of org.rssowl.ui.internal.services.SyncService


    /* Create the Download Service */
    fDownloadService = new DownloadService();

    /* Create the Sync Service */
    if (!InternalOwl.TESTING)
      fSyncService = new SyncService();

    /* Register Listeners */
    registerListeners();

    /* Load Contributed News Share Providers */
 
View Full Code Here


    if (newNews.isEmpty())
      return; //Only works if some new news are present

    /* Test Outgoing Sync (mark read) */
    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    List<SyncItem> syncItems = new ArrayList<SyncItem>();
    for (INews news : newNews) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setMarkedRead();
      syncItems.add(item);
    }

    service.testSync(syncItems);

    /* Assert Status */
    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertTrue(status.isOK());
    assertEquals(newNews.size(), status.getItemCount());
    assertEquals(newNews.size(), status.getTotalItemCount());

    /* Simulate incoming sync (merge read state) */
    Controller.getDefault().reload(bm, null, null);

    assertNotNull(feed.getTitle());
    assertNotNull(feed.getPublishDate());
    assertFalse(feed.getNews().isEmpty());

    /* Assert Read State */
    for (INews news : feed.getNews()) {
      if (news.getState() == INews.State.NEW)
        fail("Unexpected state");
    }

    /* Test Mark Unread */
    syncItems = new ArrayList<SyncItem>();
    for (INews news : newNews) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setMarkedUnread();
      syncItems.add(item);
    }

    service.testSync(syncItems);

    /* Assert Status */
    assertNotNull(service.getStatus());
    status = service.getStatus();
    assertTrue(status.isOK());
    assertEquals(newNews.size(), status.getItemCount());
    assertEquals(newNews.size() * 2, status.getTotalItemCount());

    /* Simulate incoming sync (merge read state) */
    Controller.getDefault().reload(bm, null, null);

    assertNotNull(feed.getTitle());
    assertNotNull(feed.getPublishDate());
    assertFalse(feed.getNews().isEmpty());

    /* Assert Read State */
    List<INews> unreadNews = new ArrayList<INews>();
    for (INews news : feed.getNews()) {
      if (news.getState() == INews.State.UNREAD)
        unreadNews.add(news);
    }

    assertTrue(unreadNews.size() == newNews.size());

    /* Test Outgoing Sync (mark read) */
    syncItems = new ArrayList<SyncItem>();
    for (INews news : unreadNews) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setMarkedRead();
      syncItems.add(item);
    }

    service.testSync(syncItems);

    /* Assert Status */
    assertNotNull(service.getStatus());
    status = service.getStatus();
    assertTrue(status.isOK());
    assertEquals(unreadNews.size(), status.getItemCount());
    assertEquals(unreadNews.size() * 3, status.getTotalItemCount());

    /* Simulate incoming sync (merge read state) */
 
View Full Code Here

    assertNotNull(feed.getTitle());
    assertNotNull(feed.getPublishDate());
    assertFalse(feed.getNews().isEmpty());

    /* Test Outgoing Sync */
    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    List<INews> newsToSync = new ArrayList<INews>();
    List<SyncItem> syncItems = new ArrayList<SyncItem>();
    Set<String> guids = new HashSet<String>();
    for (int i = 0; i < 20; i++) {
      INews newsitem = feed.getNews().get(i);
      SyncItem item = SyncItem.toSyncItem(newsitem);
      newsToSync.add(newsitem);
      item.setStarred();
      item.addLabel("Testing");
      item.addLabel("Hello World");
      syncItems.add(item);
      guids.add(newsitem.getGuid().getValue());
    }

    service.testSync(syncItems);

    /* Assert Status */
    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertTrue(status.isOK());
    assertEquals(syncItems.size(), status.getItemCount());
    assertEquals(syncItems.size(), status.getTotalItemCount());

    /* Simulate incoming sync (merge starred state and labels) */
    Controller.getDefault().reload(bm, null, null);

    assertNotNull(feed.getTitle());
    assertNotNull(feed.getPublishDate());
    assertFalse(feed.getNews().isEmpty());

    /* Assert Starred State and Labels */
    for (INews news : feed.getNews()) {
      if (!guids.contains(news.getGuid().getValue()))
        continue;

      assertTrue(news.isFlagged());
      Set<ILabel> labels = news.getLabels();
      assertTrue(labels.size() >= 2);
      int count = 0;
      for (ILabel label : labels) {
        if ("Testing".equals(label.getName()) && label.getId() > 0)
          count++;
        else if ("Hello World".equals(label.getName()) && label.getId() > 0)
          count++;
      }

      assertEquals(2, count);
    }

    /* Test removing starred state and labels */
    syncItems = new ArrayList<SyncItem>();
    for (INews news : newsToSync) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setUnStarred();
      item.removeLabel("Testing");
      item.removeLabel("Hello World");
      syncItems.add(item);
    }

    service.testSync(syncItems);

    /* Assert Status */
    assertNotNull(service.getStatus());
    status = service.getStatus();
    assertTrue(status.isOK());
    assertEquals(syncItems.size(), status.getItemCount());
    assertEquals(syncItems.size() * 2, status.getTotalItemCount());

    /* Simulate incoming sync (merge starred state and labels) */
 
View Full Code Here

    assertNotNull(feed.getTitle());
    assertNotNull(feed.getPublishDate());
    assertFalse(feed.getNews().isEmpty());

    /* Test Outgoing Sync */
    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    IGuid marker = feed.getNews().get(0).getGuid();
    SyncItem item = SyncItem.toSyncItem(feed.getNews().get(0));
    item.addLabel(label.getName());

    service.testSync(Collections.singleton(item));

    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertEquals(1, status.getItemCount());
    assertEquals(1, status.getTotalItemCount());

    Controller.getDefault().reload(bm, null, null);

View Full Code Here

    Controller.getDefault().reload(sternBm, null, null);
    Controller.getDefault().reload(heiseBm, null, null);
    Controller.getDefault().reload(golemBm, null, null);

    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    List<SyncItem> items = new ArrayList<SyncItem>();

    INews sternNews1 = sternFeed.getNews().get(0);
    INews sternNews2 = sternFeed.getNews().get(1);
    INews heiseNews1 = heiseFeed.getNews().get(0);
    INews heiseNews2 = heiseFeed.getNews().get(1);
    INews golemNews1 = golemFeed.getNews().get(0);
    INews golemNews2 = golemFeed.getNews().get(1);

    SyncItem item = SyncItem.toSyncItem(sternNews1);
    item.setStarred();
    items.add(item);

    item = SyncItem.toSyncItem(heiseNews1);
    item.setStarred();
    items.add(item);

    item = SyncItem.toSyncItem(golemNews1);
    item.setStarred();
    items.add(item);

    item = SyncItem.toSyncItem(sternNews2);
    item.addLabel("Foo Bar");
    items.add(item);

    item = SyncItem.toSyncItem(heiseNews2);
    item.addLabel("Foo Bar");
    items.add(item);

    item = SyncItem.toSyncItem(golemNews2);
    item.addLabel("Foo Bar");
    item.addLabel("Hello World");
    items.add(item);

    service.testSync(items);

    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertEquals(6, status.getItemCount());
    assertEquals(6, status.getTotalItemCount());

    Controller.getDefault().reload(sternBm, null, null);
    Controller.getDefault().reload(heiseBm, null, null);
    Controller.getDefault().reload(golemBm, null, null);

    int counter = 0;
    for (INews news : sternFeed.getNews()) {
      if (news.getGuid().getValue().equals(sternNews1.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;
      } else if (news.getGuid().getValue().equals(sternNews2.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;

        Set<ILabel> labels = news.getLabels();
        for (ILabel label : labels) {
          if (label.getName().equals("Foo Bar"))
            counter++;
        }
      }
    }

    for (INews news : heiseFeed.getNews()) {
      if (news.getGuid().getValue().equals(heiseNews1.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;
      } else if (news.getGuid().getValue().equals(heiseNews2.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;

        Set<ILabel> labels = news.getLabels();
        for (ILabel label : labels) {
          if (label.getName().equals("Foo Bar"))
            counter++;
        }
      }
    }

    for (INews news : golemFeed.getNews()) {
      if (news.getGuid().getValue().equals(golemNews1.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;
      } else if (news.getGuid().getValue().equals(golemNews2.getGuid().getValue())) {
        if (news.isFlagged())
          counter++;

        Set<ILabel> labels = news.getLabels();
        for (ILabel label : labels) {
          if (label.getName().equals("Foo Bar"))
            counter++;
          if (label.getName().equals("Hello World"))
            counter++;
        }
      }
    }

    assertEquals(7, counter);

    /* Now remove again and check */
    item = SyncItem.toSyncItem(sternNews1);
    item.setUnStarred();
    items.add(item);

    item = SyncItem.toSyncItem(heiseNews1);
    item.setUnStarred();
    items.add(item);

    item = SyncItem.toSyncItem(golemNews1);
    item.setUnStarred();
    items.add(item);

    item = SyncItem.toSyncItem(sternNews2);
    item.removeLabel("Foo Bar");
    items.add(item);

    item = SyncItem.toSyncItem(heiseNews2);
    item.removeLabel("Foo Bar");
    items.add(item);

    item = SyncItem.toSyncItem(golemNews2);
    item.removeLabel("Foo Bar");
    item.removeLabel("Hello World");
    items.add(item);

    service.testSync(items);

    assertNotNull(service.getStatus());
    status = service.getStatus();
    assertEquals(6, status.getItemCount());
    assertEquals(12, status.getTotalItemCount());

    Controller.getDefault().reload(sternBm, null, null);
    Controller.getDefault().reload(heiseBm, null, null);
View Full Code Here

    DynamicDAO.save(root);

    Controller.getDefault().reload(bildBm, null, null);

    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    INews bildNews = bildFeed.getNews().get(0);
    SyncItem item = SyncItem.toSyncItem(bildNews);
    item.setStarred();
    item.addLabel("Foo");
    item.addLabel("Bar");
    item.addLabel("Hello World");
    item.addLabel("World Hello");

    service.testSync(Collections.singleton(item));

    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertEquals(1, status.getItemCount());
    assertEquals(1, status.getTotalItemCount());

    Controller.getDefault().reload(bildBm, null, null);

    final AtomicBoolean listenerCalled = new AtomicBoolean();
    NewsListener listener = new NewsAdapter() {
      @Override
      public void entitiesUpdated(Set<NewsEvent> events) {
        listenerCalled.set(true);
      }
    };
    DynamicDAO.addEntityListener(INews.class, listener);

    try {
      Controller.getDefault().reload(bildBm, null, null);
      assertFalse(listenerCalled.get());
    } finally {
      DynamicDAO.removeEntityListener(INews.class, listener);
    }

    /* Clean Up */
    item = SyncItem.toSyncItem(bildNews);
    item.setUnStarred();
    item.removeLabel("Foo");
    item.removeLabel("Bar");
    item.removeLabel("Hello World");
    item.removeLabel("World Hello");

    service.testSync(Collections.singleton(item));

    assertNotNull(service.getStatus());
    status = service.getStatus();
    assertEquals(1, status.getItemCount());
    assertEquals(2, status.getTotalItemCount());
  }
View Full Code Here

    DynamicDAO.save(root);

    Controller.getDefault().reload(testBm, null, null);

    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    INews testNews = testFeed.getNews().get(0);

    assertEquals(1, testNews.getLabels().size());
    assertEquals("TestFeed", testNews.getLabels().iterator().next().getName());

    SyncItem item = SyncItem.toSyncItem(testNews);
    item.addLabel("Foo");
    item.addLabel("Bar");
    item.addLabel("Hello World");
    item.addLabel("World Hello");

    service.testSync(Collections.singleton(item));

    assertNotNull(service.getStatus());
    SyncStatus status = service.getStatus();
    assertEquals(1, status.getItemCount());
    assertEquals(1, status.getTotalItemCount());

    Controller.getDefault().reload(testBm, null, null);

    assertEquals(5, testNews.getLabels().size());

    testNews.removeLabel(testNews.getLabels().iterator().next());
    DynamicDAO.save(testFeed);

    assertEquals(4, testNews.getLabels().size());

    Controller.getDefault().reload(testBm, null, null);

    assertEquals(5, testNews.getLabels().size());

    item = SyncItem.toSyncItem(testNews);
    item.removeLabel("Foo");
    item.removeLabel("Bar");
    item.addLabel("Bababu");

    service.testSync(Collections.singleton(item));

    Controller.getDefault().reload(testBm, null, null);
    assertEquals(4, testNews.getLabels().size());

    item = SyncItem.toSyncItem(testNews);
    item.removeLabel("Hello World");
    item.removeLabel("World Hello");
    item.removeLabel("Bababu");

    service.testSync(Collections.singleton(item));

    Controller.getDefault().reload(testBm, null, null);
    assertEquals(1, testNews.getLabels().size());
  }
View Full Code Here

    DynamicDAO.save(root);

    Controller.getDefault().reload(slashdotBm, null, null);

    SyncService service = new SyncService();
    assertTrue(service.getStatus() == null);

    int itemCount = slashdotFeed.getNews().size();
    assertTrue(itemCount > 790); //Sometimes seems to hit 799

    List<SyncItem> items = new ArrayList<SyncItem>();
    for (INews news : slashdotFeed.getNews()) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setStarred();
      item.setMarkedRead();
      items.add(item);

      item = SyncItem.toSyncItem(news);
      item.addLabel("Foo");
      items.add(item);

      item = SyncItem.toSyncItem(news);
      item.addLabel("Hello World");
      items.add(item);
    }

    service.testSync(items);
    assertEquals(itemCount, service.getStatus().getItemCount());
    assertEquals(itemCount, service.getStatus().getTotalItemCount());

    items = new ArrayList<SyncItem>();
    for (INews news : slashdotFeed.getNews()) {
      SyncItem item = SyncItem.toSyncItem(news);
      item.setUnStarred();
      items.add(item);

      item = SyncItem.toSyncItem(news);
      item.removeLabel("Foo");
      items.add(item);

      item = SyncItem.toSyncItem(news);
      item.removeLabel("Hello World");
      items.add(item);
    }

    service.testSync(items);
    assertEquals(itemCount, service.getStatus().getItemCount());
    assertEquals(itemCount * 2, service.getStatus().getTotalItemCount());
  }
View Full Code Here

TOP

Related Classes of org.rssowl.ui.internal.services.SyncService

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.