/** Test method remove */
 @Test
 @DirtiesContext
 public void testRemove() {
   final Item item = feed.getItems().get(0);
   // Count episodes before
   final int initialCount = feed.getItems().size();
   feedManager.remove(item, feed);
   // re-read feed and count episodes after adding a new one
   feed = feedManager.getFeed(feed);
   final int newCount = feed.getItems().size();
   // Compare
   assertEquals(initialCount - 1, newCount);
 }
 /** Test method add */
 @Test
 public void testAdd() {
   final Item newEpisode = new Item();
   newEpisode.setGuid(CodeHelper.getGlobalForeverUniqueID());
   newEpisode.setTitle("This is my new Item");
   // Count episodes before
   final int initialCount = feed.getItems().size();
   feedManager.addItem(newEpisode, null, feed, PublishEventTO.getNoPublishInstance());
   // re-read feed and count episodes
   feed = feedManager.getFeed(feed);
   final int newCount = feed.getItems().size();
   // Compare
   assertEquals(initialCount + 1, newCount);
 }
 /**
  * Checks if the FeedItems of this feed have images that point to the same URL. If two FeedItems
  * have an image that points to the same URL, the reference of the second item is removed, so
  * that every image reference is unique.
  */
 private void removeDuplicateImages(Feed feed) {
   for (int x = 0; x < feed.getItems().size(); x++) {
     for (int y = x + 1; y < feed.getItems().size(); y++) {
       FeedItem item1 = feed.getItems().get(x);
       FeedItem item2 = feed.getItems().get(y);
       if (item1.hasItemImage() && item2.hasItemImage()) {
         if (StringUtils.equals(
             item1.getImage().getDownload_url(), item2.getImage().getDownload_url())) {
           item2.setImage(null);
         }
       }
     }
   }
 }
示例#4
0
  public void testWrite() throws Exception {
    FileWriter fw = null;
    File outFile = null;

    try {
      outFile = File.createTempFile("FeedTest", "tmp");
      filesToDelete.add(outFile);
      fw = new FileWriter(outFile);
      Feed feed = new Feed(tempFile);
      feed.write(fw);
      fw.close();

      // Feed feed2 = new Feed(outFile);
      assertEquals("CruiseControl Build Results", feed.getTitle());
      assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
      assertEquals(
          "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

      // validate the number of items and the contents of the first item.
      assertEquals(11, feed.getItems().size());
      Item item = (Item) feed.getItems().get(0);
      assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
      assertEquals(
          "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
              + "VERSION_10?log=log20050817084109Lbuild.7",
          item.getLink());
      assertEquals(
          "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
              + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
              + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
              + "ApplicationServer/PlayTime/default.build"
              + "  by jefferson (deploy the mock object dll)</li></ul>",
          item.getDescription());
    } finally {
      IO.close(fw);
    }
  }
示例#5
0
  public void testConstructors() {
    Feed feed = new Feed(tempFile);

    assertEquals("CruiseControl Build Results", feed.getTitle());
    assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
    assertEquals(
        "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

    // validate the number of items and the contents of the first item.
    assertEquals(11, feed.getItems().size());
    Item item = (Item) feed.getItems().get(0);
    assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
    assertEquals(
        "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
            + "VERSION_10?log=log20050817084109Lbuild.7",
        item.getLink());
    assertEquals(
        "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
            + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
            + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
            + "ApplicationServer/PlayTime/default.build"
            + "  by jefferson (deploy the mock object dll)</li></ul>",
        item.getDescription());
  }
 private boolean hasValidFeedItems(Feed feed) {
   for (FeedItem item : feed.getItems()) {
     if (item.getTitle() == null) {
       Log.e(TAG, "Item has no title");
       return false;
     }
     if (item.getPubDate() == null) {
       Log.e(TAG, "Item has no pubDate. Using current time as pubDate");
       if (item.getTitle() != null) {
         Log.e(TAG, "Title of invalid item: " + item.getTitle());
       }
       item.setPubDate(new Date());
     }
   }
   return true;
 }