1
2
3
4
5
6
7 package com.sun.syndication.unittest;
8
9
10 import com.sun.syndication.feed.synd.SyndCategoryI;
11 import com.sun.syndication.feed.synd.SyndEntryI;
12 import com.sun.syndication.feed.synd.SyndImageI;
13 import com.sun.syndication.io.impl.DateParser;
14
15 import java.util.Date;
16 import java.util.List;
17
18 /***
19 * @author pat
20 *
21 */
22 public abstract class SyndFeedTest extends FeedTest {
23 private String _prefix = null;
24
25 protected SyndFeedTest(String feedType) {
26 this(feedType,feedType+".xml");
27 }
28
29 protected SyndFeedTest(String feedType,String feedFileName) {
30 super(feedFileName);
31 _prefix = feedType;
32 }
33
34 protected String getPrefix() {
35 return _prefix;
36 }
37
38 public void assertEqualsStr(String a, String b) {
39 assertEquals(getPrefix() + "." + a, b);
40 }
41
42 public void testType() throws Exception {
43 assertEquals(getPrefix(), getCachedSyndFeed().getFeedType());
44 }
45
46 public void testTitle() throws Exception {
47 assertEqualsStr("channel.title", getCachedSyndFeed().getTitle());
48 }
49
50 public void testLink() throws Exception {
51 assertEqualsStr("channel.link", getCachedSyndFeed().getLink());
52 }
53
54 public void testDescription() throws Exception {
55 assertEqualsStr("channel.description", getCachedSyndFeed().getDescription());
56 }
57
58 public void testLanguage() throws Exception {
59 assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage());
60 }
61
62 public void testCategories() throws Exception {
63 List catlist = getCachedSyndFeed().getCategories();
64
65 assertEquals(2, catlist.size());
66 SyndCategoryI cat = (SyndCategoryI)catlist.get(0);
67 assertEqualsStr("channel.category[0]", cat.getName());
68 assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri());
69 cat = (SyndCategoryI)catlist.get(1);
70 assertEqualsStr("channel.category[1]", cat.getName());
71 assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri());
72 }
73
74 public void testPublishedDate() throws Exception {
75 assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate());
76 }
77
78
79 public void testImage() throws Exception {
80 SyndImageI img = getCachedSyndFeed().getImage();
81 assertEqualsStr("channel.image.description", img.getDescription());
82 assertEqualsStr("channel.image.link", img.getLink());
83 assertEqualsStr("channel.image.title", img.getTitle());
84 assertEqualsStr("channel.image.url", img.getUrl());
85 }
86
87 public void testEntries() throws Exception {
88 List entrylist = getCachedSyndFeed().getEntries();
89 assertEquals(2, entrylist.size());
90 }
91
92 public void testEntryTitle() throws Exception {
93 assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0)));
94 assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1)));
95 }
96
97 public String getEntryTitle(Object o) throws Exception {
98 SyndEntryI e = (SyndEntryI) o;
99 return e.getTitle();
100 }
101
102 public void testEntryDescription() throws Exception {
103 assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0)));
104 assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1)));
105 }
106
107 public String getEntryDescription(Object o) throws Exception {
108 SyndEntryI e = (SyndEntryI) o;
109 return e.getDescription().getValue();
110 }
111
112 public void testEntryLink() throws Exception {
113 assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0)));
114 assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1)));
115 }
116
117 public String getEntryLink(Object o) {
118 SyndEntryI e = (SyndEntryI) o;
119 return e.getLink();
120 }
121
122 public void testEntryPublishedDate() throws Exception {
123 assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0)));
124 assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1)));
125 }
126
127 public Date getEntryPublishedDate(Object o) {
128 SyndEntryI e = (SyndEntryI) o;
129 return e.getPublishedDate();
130 }
131
132 public void testEntryCategories() throws Exception {
133 SyndEntryI e = (SyndEntryI)getCachedSyndFeed().getEntries().get(0);
134 List catlist = e.getCategories();
135
136 assertEquals(2, catlist.size());
137 SyndCategoryI cat = (SyndCategoryI)catlist.get(0);
138 assertEqualsStr("channel.item[0].category[0]", cat.getName());
139 assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri());
140 cat = (SyndCategoryI)catlist.get(1);
141 assertEqualsStr("channel.item[0].category[1]", cat.getName());
142 assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri());
143
144 }
145
146 public void testEntryAuthor() throws Exception {
147 assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0)));
148 assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1)));
149 }
150
151 public String getEntryAuthor(Object o) {
152 SyndEntryI e = (SyndEntryI) o;
153 return e.getAuthor();
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 protected void tearDown() throws Exception {
262 super.tearDown();
263 }
264
265
266
267 }