1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.feedparser.test; |
18 | |
|
19 | |
import java.io.FileOutputStream; |
20 | |
import java.io.PrintStream; |
21 | |
import java.net.URL; |
22 | |
|
23 | |
import junit.framework.TestCase; |
24 | |
|
25 | |
import org.apache.commons.feedparser.FeedParser; |
26 | |
import org.apache.commons.feedparser.FeedParserFactory; |
27 | |
import org.apache.commons.feedparser.impl.DebugFeedParserListener; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class TestFeedFilter extends TestCase { |
35 | |
protected String feedparserHome; |
36 | |
|
37 | 0 | public static int current = 0; |
38 | |
|
39 | |
public TestFeedFilter( String name ) throws Exception { |
40 | 0 | super( name ); |
41 | |
|
42 | 0 | feedparserHome = System.getProperty("feedparser.home", "."); |
43 | |
|
44 | |
|
45 | |
|
46 | 0 | if (feedparserHome.endsWith("/") == false) |
47 | 0 | feedparserHome = feedparserHome + "/"; |
48 | 0 | } |
49 | |
|
50 | |
private void doTest( String resource ) throws Exception { |
51 | |
|
52 | 0 | System.out.println( "resource: (" + current + ") " + resource ); |
53 | |
|
54 | 0 | URL url = new URL( resource ); |
55 | |
|
56 | 0 | FileOutputStream fos = new FileOutputStream( "/tmp/test-feed-filter-" + current + ".html" ); |
57 | |
|
58 | 0 | PrintStream out = new PrintStream( fos, true, "UTF-8" ); |
59 | |
|
60 | 0 | out.println( "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"> " ); |
61 | 0 | out.println( "<pre>" ); |
62 | |
|
63 | 0 | DebugFeedParserListener listener = new DebugFeedParserListener( out ); |
64 | |
|
65 | 0 | FeedParser parser=FeedParserFactory.newFeedParser(); |
66 | 0 | parser.parse( listener, url.openStream(), resource ); |
67 | |
|
68 | 0 | out.println( "</pre>" ); |
69 | |
|
70 | 0 | ++current; |
71 | |
|
72 | 0 | } |
73 | |
|
74 | |
public void test1() throws Exception { |
75 | 0 | String path = "file:" + feedparserHome; |
76 | |
|
77 | 0 | doTest( path + "tests/feeds/rss-1.0-EUC-JP.rdf" ); |
78 | |
|
79 | 0 | doTest( path + "tests/filter/nbsp-1.xml" ); |
80 | |
|
81 | 0 | doTest( path + "tests/filter/entity-atom-1.xml" ); |
82 | |
|
83 | 0 | doTest( path + "tests/filter/prolog-atom-1.xml" ); |
84 | 0 | doTest( path + "tests/filter/prolog-atom-2.xml" ); |
85 | 0 | doTest( path + "tests/filter/prolog-opml-1.xml" ); |
86 | |
|
87 | 0 | doTest( path + "tests/filter/lisa.opml" ); |
88 | |
|
89 | 0 | doTest( path + "tests/feeds/utf16.rss1" ); |
90 | 0 | doTest( path + "tests/feeds/utf16.rss2" ); |
91 | 0 | doTest( path + "tests/feeds/i18n.atom" ); |
92 | 0 | doTest( path + "tests/feeds/utf16.atom" ); |
93 | |
|
94 | 0 | doTest( path + "tests/feeds/atom-1.xml" ); |
95 | 0 | doTest( path + "tests/feeds/rss-1.0-EUC-JP.rdf" ); |
96 | 0 | doTest( path + "tests/feeds/rss-1.0-international-1.rdf" ); |
97 | |
|
98 | 0 | } |
99 | |
|
100 | |
public static void main( String[] args ) throws Exception { |
101 | |
|
102 | 0 | TestFeedFilter test = new TestFeedFilter( null ); |
103 | |
|
104 | |
|
105 | 0 | test.test1(); |
106 | |
|
107 | 0 | } |
108 | |
|
109 | |
} |
110 | |
|