1 package com.sun.syndication.unittest;
2
3 import junit.framework.TestCase;
4
5 import com.sun.syndication.feed.synd.SyndFeed;
6 import com.sun.syndication.feed.WireFeed;
7 import com.sun.syndication.io.SyndFeedInput;
8 import com.sun.syndication.io.WireFeedInput;
9
10 import java.io.InputStreamReader;
11 import java.io.Reader;
12 import java.io.InputStream;
13
14 import org.jdom.Document;
15 import org.jdom.input.SAXBuilder;
16
17 /***
18 * @author pat, tucu
19 *
20 */
21 public abstract class FeedTest extends TestCase {
22 private String _feedFileName;
23 private Document _jDomDoc = null;
24 private WireFeed _wireFeed = null;
25 private SyndFeed _syndFeed = null;
26
27 protected FeedTest(String feedFileName) {
28 _feedFileName = feedFileName;
29 }
30
31 protected String getFeedFileName() {
32 return _feedFileName;
33 }
34
35 protected Reader getFeedReader() throws Exception {
36 InputStream resource = Thread.currentThread().
37 getContextClassLoader().getResourceAsStream(getFeedFileName());
38 assertNotNull("Could not find resource " + getFeedFileName(), resource);
39 return new InputStreamReader(resource);
40 }
41
42 protected Document getJDomDoc() throws Exception {
43 SAXBuilder saxBuilder = new SAXBuilder(false);
44 return saxBuilder.build(getFeedReader());
45 }
46
47 protected WireFeed getWireFeed() throws Exception {
48 WireFeedInput in = new WireFeedInput();
49 return in.build(getFeedReader());
50 }
51
52 protected SyndFeed getSyndFeed() throws Exception {
53 SyndFeedInput in = new SyndFeedInput();
54 return in.build(getFeedReader());
55 }
56
57 protected Document getCachedJDomDoc() throws Exception {
58 if (_jDomDoc==null) {
59 _jDomDoc = getJDomDoc();
60 }
61 return _jDomDoc;
62 }
63
64 protected WireFeed getCachedWireFeed() throws Exception {
65 if (_wireFeed==null) {
66 _wireFeed = getWireFeed();
67 }
68 return _wireFeed;
69 }
70
71 protected SyndFeed getCachedSyndFeed() throws Exception {
72 if (_syndFeed==null) {
73 _syndFeed = getSyndFeed();
74 }
75 return _syndFeed;
76 }
77
78 }