MediaModuleTest fixed (added google-video-rss file to resources)

This commit is contained in:
Martin Kurz 2013-10-09 19:41:00 +02:00
parent 584bc72493
commit a54575d76a
2 changed files with 65 additions and 65 deletions

View file

@ -9,9 +9,9 @@ package org.rometools.feed.module.mediarss;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;
import java.io.IOException;
import java.util.List;
import junit.framework.Test;
@ -21,6 +21,7 @@ import org.rometools.feed.module.AbstractTestCase;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.SyndFeedOutput;
@ -41,32 +42,26 @@ public class MediaModuleTest extends AbstractTestCase {
}
public void testGoogleVideo() throws Exception {
final SyndFeedInput input = new SyndFeedInput();
final SyndFeed feed = input.build(new InputStreamReader(new URL("http://video.google.com/videofeed?type=top100new&num=20&output=rss").openStream()));
final SyndFeed feed = getSyndFeed(new File(getTestFile("data/YouTube-MostPopular.rss")));
for (final Object element : feed.getEntries()) {
final SyndEntry entry = (SyndEntry) element;
final MediaEntryModule m = (MediaEntryModule) entry.getModule(MediaModule.URI);
System.out.print(m);
assertNotNull(m);
}
}
public void testParse() throws Exception {
final SyndFeedInput input = new SyndFeedInput();
final File test = new File(super.getTestFile("xml"));
final File[] files = test.listFiles();
for (int j = 0; j < files.length; j++) {
if (!files[j].getName().endsWith(".xml")) {
continue;
}
final SyndFeed feed = input.build(files[j]);
// System.out.println( feed );
final List entries = feed.getEntries();
for (int i = 0; i < entries.size(); i++) {
// System.out.println( ((SyndEntry) entries.get(i)).getModule( MediaModule.URI ) );
}
final SyndFeed feed = getSyndFeed(files[j]);
final List<SyndEntry> entries = feed.getEntries();
final SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, new File("target/" + j + ".xml"));
final SyndFeed feed2 = input.build(new File("target/" + j + ".xml"));
final SyndFeed feed2 = getSyndFeed(new File("target/" + j + ".xml"));
for (int i = 0; i < entries.size(); i++) {
BufferedWriter b = new BufferedWriter(new FileWriter("target/" + j + "a.txt"));
b.write("" + ((SyndEntry) entries.get(i)).getModule(MediaModule.URI));
@ -79,57 +74,8 @@ public class MediaModuleTest extends AbstractTestCase {
}
}
/**
* This code represents the original MediaModuleTest main class from openvision.tv
*/
public void xtestOriginal() throws Exception {
//
/*
* //You can test with blip tv or broadcast machine
*
* String rss = "http://blip.tv/?1=1&&skin=rss";// // String rss = "http://openvision.tv/bm/rss.php?i=4"; // String rss =
* "http://api.search.yahoo.com/VideoSearchService/rss/videoSearch.xml?appid=yahoosearchvideorss&query=surfing&adult_ok=0";
*
*
* URLConnection uc = new URL(rss).openConnection(); String contentType = uc.getContentEncoding();
*
* WireFeedInput input = new WireFeedInput();
*
* XmlReader xmlReader = new XmlReader(uc.getInputStream(), contentType, true);
*
* Channel chnl = (Channel)input.build(xmlReader);
*
* String feedTitle = chnl.getTitle(); String feedDesc = chnl.getDescription();
*
*
* List items = chnl.getItems();
*
* ListIterator li = items.listIterator(); Item item = null; Enclosure enc = null; MediaModule mModule = null;
*
* while (li.hasNext()) {
*
* item = (Item)li.next(); enc = (Enclosure)item.getEnclosures().get(0);
*
* mModule = (MediaModule)item.getModule(MediaModule.URI);
*
* List modules = item.getModules(); System.out.println("title: " + item.getTitle()); System.out.println("module count: " + modules.size());
*
* if (mModule != null) { Thumbnail[] mThumbs = mModule.getMediaThumbnails();
*
* if (mThumbs != null) { for (int i = 0; i < mThumbs.length; i++) { String imgUrl = mThumbs[i].getUrl(); System.out.println("got MediaModule img " + i
* + ": " + imgUrl); } }
*
* System.out.println("MediaModule title: " + mModule.getTitle()); System.out.println("MediaModule isAdult: " + mModule.isAdult()); /* if
* (mModule.getMediaContent() != null) { for (int i = 0; i < mModule.getMediaContent().length; i++) { MediaContent mc = mModule.getMediaContent()[i];
* mThumbs = mc.getMediaThumbnails(); if (mThumbs != null) { for (int n = 0; n < mThumbs.length; n++) { String imgUrl = mThumbs[n].getUrl();
* System.out.println("got MediaContentImage " + n + " img: " + imgUrl); } } System.out.println("MediaContent title:" + mc.getTitle());
* System.out.println("MediaContent text:" + mc.getText());
*
* }
*
* }
*
* } else { System.out.println("no MediaModule!"); } }
*/
private SyndFeed getSyndFeed(final File file) throws FileNotFoundException, IllegalArgumentException, IOException, FeedException {
final SyndFeedInput input = new SyndFeedInput();
return input.build(file);
}
}

File diff suppressed because one or more lines are too long