1 package com.sun.syndication.unittest; 2 3 import com.sun.syndication.feed.atom.Feed; 4 import com.sun.syndication.feed.atom.Content; 5 import com.sun.syndication.io.WireFeedOutput; 6 import com.sun.syndication.io.WireFeedInput; 7 import junit.framework.TestCase; 8 9 import java.io.StringWriter; 10 import java.io.StringReader; 11 12 public class TestAtomContent extends TestCase { 13 14 private Feed createFeed() { 15 Feed feed = new Feed(); 16 Content content = new Content(); 17 content.setType("application/xml"); 18 content.setValue("<test>Hello Hello</test>"); 19 feed.setTitleEx(content); 20 feed.setFeedType("atom_1.0"); 21 return feed; 22 } 23 24 public void testReadWrite() throws Exception { 25 Feed feed = createFeed(); 26 StringWriter sw = new StringWriter(); 27 WireFeedOutput output = new WireFeedOutput(); 28 output.output(feed, sw); 29 sw.close(); 30 StringReader reader = new StringReader(sw.toString()); 31 WireFeedInput input = new WireFeedInput(); 32 feed = (Feed) input.build(reader); 33 reader.close(); 34 assertEquals("<test>Hello Hello</test>", feed.getTitleEx().getValue().trim()); 35 } 36 37 public void testXML() throws Exception { 38 Feed feed = createFeed(); 39 StringWriter sw = new StringWriter(); 40 WireFeedOutput output = new WireFeedOutput(); 41 output.output(feed, sw); 42 sw.close(); 43 assertTrue(sw.toString().contains("<test xmlns=\"\">Hello Hello</test>")); 44 } 45 46 }