01: package com.sun.syndication.unittest;
02:
03: import junit.framework.TestCase;
04:
05: import com.sun.syndication.feed.synd.SyndFeed;
06: import com.sun.syndication.feed.WireFeed;
07: import com.sun.syndication.io.SyndFeedInput;
08: import com.sun.syndication.io.WireFeedInput;
09:
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(
38: getFeedFileName());
39: assertNotNull("Could not find resource " + getFeedFileName(),
40: resource);
41: return new InputStreamReader(resource);
42: }
43:
44: protected Document getJDomDoc() throws Exception {
45: SAXBuilder saxBuilder = new SAXBuilder(false);
46: return saxBuilder.build(getFeedReader());
47: }
48:
49: protected WireFeed getWireFeed() throws Exception {
50: WireFeedInput in = new WireFeedInput();
51: return in.build(getFeedReader());
52: }
53:
54: protected SyndFeed getSyndFeed() throws Exception {
55: SyndFeedInput in = new SyndFeedInput();
56: return in.build(getFeedReader());
57: }
58:
59: protected Document getCachedJDomDoc() throws Exception {
60: if (_jDomDoc == null) {
61: _jDomDoc = getJDomDoc();
62: }
63: return _jDomDoc;
64: }
65:
66: protected WireFeed getCachedWireFeed() throws Exception {
67: if (_wireFeed == null) {
68: _wireFeed = getWireFeed();
69: }
70: return _wireFeed;
71: }
72:
73: protected SyndFeed getCachedSyndFeed() throws Exception {
74: if (_syndFeed == null) {
75: _syndFeed = getSyndFeed();
76: }
77: return _syndFeed;
78: }
79:
80: }
|