KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > unittest > FeedTest


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 JavaDoc;
11 import java.io.Reader JavaDoc;
12 import java.io.InputStream JavaDoc;
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 JavaDoc _feedFileName;
23     private Document _jDomDoc = null;
24     private WireFeed _wireFeed = null;
25     private SyndFeed _syndFeed = null;
26
27     protected FeedTest(String JavaDoc feedFileName) {
28         _feedFileName = feedFileName;
29     }
30
31     protected String JavaDoc getFeedFileName() {
32         return _feedFileName;
33     }
34
35     protected Reader JavaDoc getFeedReader() throws Exception JavaDoc {
36       InputStream JavaDoc resource = Thread.currentThread().
37                                           getContextClassLoader().getResourceAsStream(getFeedFileName());
38       assertNotNull("Could not find resource " + getFeedFileName(), resource);
39       return new InputStreamReader JavaDoc(resource);
40     }
41
42     protected Document getJDomDoc() throws Exception JavaDoc {
43         SAXBuilder saxBuilder = new SAXBuilder(false);
44         return saxBuilder.build(getFeedReader());
45     }
46
47     protected WireFeed getWireFeed() throws Exception JavaDoc {
48         WireFeedInput in = new WireFeedInput();
49         return in.build(getFeedReader());
50     }
51
52     protected SyndFeed getSyndFeed() throws Exception JavaDoc {
53         SyndFeedInput in = new SyndFeedInput();
54         return in.build(getFeedReader());
55     }
56
57     protected Document getCachedJDomDoc() throws Exception JavaDoc {
58         if (_jDomDoc==null) {
59             _jDomDoc = getJDomDoc();
60         }
61         return _jDomDoc;
62     }
63
64     protected WireFeed getCachedWireFeed() throws Exception JavaDoc {
65         if (_wireFeed==null) {
66             _wireFeed = getWireFeed();
67         }
68         return _wireFeed;
69     }
70
71     protected SyndFeed getCachedSyndFeed() throws Exception JavaDoc {
72         if (_syndFeed==null) {
73             _syndFeed = getSyndFeed();
74         }
75         return _syndFeed;
76     }
77
78 }
79
Popular Tags