|
19 | 19 | */ |
20 | 20 | package com.rometools.modules.itunes; |
21 | 21 |
|
22 | | -import java.io.File; |
23 | | -import java.io.StringWriter; |
24 | | -import java.util.List; |
25 | | - |
26 | | -import junit.framework.Test; |
27 | | -import junit.framework.TestSuite; |
28 | | - |
29 | | -import org.slf4j.Logger; |
30 | | -import org.slf4j.LoggerFactory; |
31 | | - |
32 | 22 | import com.rometools.modules.AbstractTestCase; |
33 | | -import com.rometools.modules.itunes.AbstractITunesObject; |
34 | | -import com.rometools.modules.itunes.FeedInformation; |
35 | | -import com.rometools.modules.itunes.FeedInformationImpl; |
36 | 23 | import com.rometools.modules.itunes.types.Category; |
37 | 24 | import com.rometools.rome.feed.synd.SyndEntry; |
38 | 25 | import com.rometools.rome.feed.synd.SyndFeed; |
39 | 26 | import com.rometools.rome.feed.synd.SyndFeedImpl; |
40 | 27 | import com.rometools.rome.io.SyndFeedInput; |
41 | 28 | import com.rometools.rome.io.SyndFeedOutput; |
42 | 29 | import com.rometools.rome.io.XmlReader; |
| 30 | +import java.io.ByteArrayInputStream; |
| 31 | +import java.io.File; |
| 32 | +import java.io.StringWriter; |
| 33 | +import java.net.URL; |
| 34 | +import java.util.List; |
| 35 | +import junit.framework.Test; |
| 36 | +import junit.framework.TestSuite; |
| 37 | +import org.slf4j.Logger; |
| 38 | +import org.slf4j.LoggerFactory; |
43 | 39 |
|
44 | 40 | public class ITunesGeneratorTest extends AbstractTestCase { |
45 | 41 |
|
@@ -114,6 +110,73 @@ public void testCreate() throws Exception { |
114 | 110 | final StringWriter writer = new StringWriter(); |
115 | 111 | output.output(feed, writer); |
116 | 112 | LOG.debug("{}", writer); |
| 113 | + } |
| 114 | + |
| 115 | + public void testImage() throws Exception { |
| 116 | + SyndFeed feed = new SyndFeedImpl(); |
| 117 | + feed.setFeedType("rss_2.0"); |
| 118 | + feed.setTitle("title"); |
| 119 | + feed.setDescription("description"); |
| 120 | + feed.setLink("https://example.org"); |
| 121 | + |
| 122 | + FeedInformation itunesFeed = new FeedInformationImpl(); |
| 123 | + itunesFeed.setImage(new URL("https://example.org/test.png")); |
| 124 | + feed.getModules().add(itunesFeed); |
| 125 | + |
| 126 | + String xml = new SyndFeedOutput().outputString(feed); |
| 127 | + |
| 128 | + AbstractITunesObject parsedItunesFeed = |
| 129 | + (AbstractITunesObject) new SyndFeedInput() |
| 130 | + .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8")))) |
| 131 | + .getModule(AbstractITunesObject.URI); |
| 132 | + assertEquals(new URL("https://example.org/test.png"), parsedItunesFeed.getImage()); |
| 133 | + assertEquals(new java.net.URI("https://example.org/test.png"), |
| 134 | + parsedItunesFeed.getImageUri()); |
| 135 | + } |
| 136 | + |
| 137 | + public void testImageUri() throws Exception { |
| 138 | + SyndFeed feed = new SyndFeedImpl(); |
| 139 | + feed.setFeedType("rss_2.0"); |
| 140 | + feed.setTitle("title"); |
| 141 | + feed.setDescription("description"); |
| 142 | + feed.setLink("https://example.org"); |
| 143 | + |
| 144 | + FeedInformation itunesFeed = new FeedInformationImpl(); |
| 145 | + itunesFeed.setImageUri(new java.net.URI("https://example.org/test.png")); |
| 146 | + feed.getModules().add(itunesFeed); |
| 147 | + |
| 148 | + String xml = new SyndFeedOutput().outputString(feed); |
| 149 | + |
| 150 | + AbstractITunesObject parsedItunesFeed = |
| 151 | + (AbstractITunesObject) new SyndFeedInput() |
| 152 | + .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8")))) |
| 153 | + .getModule(AbstractITunesObject.URI); |
| 154 | + assertEquals(new java.net.URI("https://example.org/test.png"), |
| 155 | + parsedItunesFeed.getImageUri()); |
| 156 | + assertEquals(new URL("https://example.org/test.png"), |
| 157 | + parsedItunesFeed.getImage()); |
| 158 | + } |
117 | 159 |
|
| 160 | + public void testImageTakesPrecedenceOverImageUri() throws Exception { |
| 161 | + SyndFeed feed = new SyndFeedImpl(); |
| 162 | + feed.setFeedType("rss_2.0"); |
| 163 | + feed.setTitle("title"); |
| 164 | + feed.setDescription("description"); |
| 165 | + feed.setLink("https://example.org"); |
| 166 | + |
| 167 | + FeedInformation itunesFeed = new FeedInformationImpl(); |
| 168 | + itunesFeed.setImage(new URL("https://example.org/test1.png")); |
| 169 | + itunesFeed.setImageUri(new java.net.URI("https://example.org/test2.png")); |
| 170 | + feed.getModules().add(itunesFeed); |
| 171 | + |
| 172 | + String xml = new SyndFeedOutput().outputString(feed); |
| 173 | + |
| 174 | + AbstractITunesObject parsedItunesFeed = |
| 175 | + (AbstractITunesObject) new SyndFeedInput() |
| 176 | + .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8")))) |
| 177 | + .getModule(AbstractITunesObject.URI); |
| 178 | + assertEquals(new URL("https://example.org/test1.png"), parsedItunesFeed.getImage()); |
| 179 | + assertEquals(new java.net.URI("https://example.org/test1.png"), |
| 180 | + parsedItunesFeed.getImageUri()); |
118 | 181 | } |
119 | 182 | } |
0 commit comments