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