KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.syndication.unittest;
2
3 import com.sun.syndication.feed.module.DCModule;
4 import com.sun.syndication.feed.module.DCSubject;
5 import com.sun.syndication.feed.synd.SyndEntry;
6 import com.sun.syndication.io.impl.DateParser;
7
8 import java.util.List JavaDoc;
9 import java.util.Date JavaDoc;
10
11
12 /**
13  * Test case for the multi-valued DublinCore module elements.
14  * <p>
15  * @author Paul Dlug
16  */

17 public class TestSyndFeedRSS10DCMulti extends TestSyndFeedRSS10 {
18
19     public TestSyndFeedRSS10DCMulti() {
20         super("rss_1.0", "rss_1.0_DC_multi.xml");
21     }
22
23     protected TestSyndFeedRSS10DCMulti(String JavaDoc type) {
24         super(type);
25     }
26
27     protected TestSyndFeedRSS10DCMulti(String JavaDoc feedType, String JavaDoc feedFileName) {
28         super(feedType, feedFileName);
29     }
30
31     public void testChannelDCModule() throws Exception JavaDoc {
32         DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI);
33         _testDCModule(dc, "channel.");
34     }
35
36     protected void _testDCModule(DCModule dc,String JavaDoc prefix) throws Exception JavaDoc {
37         assertNotNull(dc);
38         
39         assertProperty((String JavaDoc)dc.getTitles().get(0), prefix + "dc:title[0]");
40         assertProperty((String JavaDoc)dc.getTitles().get(1), prefix + "dc:title[1]");
41         
42         assertProperty((String JavaDoc)dc.getCreators().get(0), prefix + "dc:creator[0]");
43         assertProperty((String JavaDoc)dc.getCreators().get(1), prefix + "dc:creator[1]");
44         
45         assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(), prefix + "dc:subject[0]");
46         String JavaDoc taxo0 = ((DCSubject)dc.getSubjects().get(0)).getTaxonomyUri();
47         if (taxo0 != null) {
48             assertProperty(taxo0, prefix + "dc:subject[0].taxo:topic^resource");
49         }
50         assertProperty(((DCSubject)dc.getSubjects().get(1)).getValue(), prefix + "dc:subject[1]");
51         String JavaDoc taxo1 = ((DCSubject)dc.getSubjects().get(1)).getTaxonomyUri();
52         if (taxo1 != null) {
53             assertProperty(taxo1, prefix + "dc:subject[1].taxo:topic^resource");
54         }
55         
56         assertProperty((String JavaDoc)dc.getDescriptions().get(0), prefix + "dc:description[0]");
57         assertProperty((String JavaDoc)dc.getDescriptions().get(1), prefix + "dc:description[1]");
58         
59         assertProperty((String JavaDoc)dc.getPublishers().get(0), prefix + "dc:publisher[0]");
60         assertProperty((String JavaDoc)dc.getPublishers().get(1), prefix + "dc:publisher[1]");
61         
62         assertProperty((String JavaDoc)dc.getContributors().get(0),prefix + "dc:contributor[0]");
63         assertProperty((String JavaDoc)dc.getContributors().get(1),prefix + "dc:contributor[1]");
64         Date JavaDoc date = DateParser.parseW3CDateTime("2001-01-01T00:00+00:00");
65         assertEquals((Date JavaDoc)dc.getDates().get(0), date);
66         assertEquals((Date JavaDoc)dc.getDates().get(1), date);
67         
68         assertProperty((String JavaDoc)dc.getTypes().get(0), prefix + "dc:type[0]");
69         assertProperty((String JavaDoc)dc.getTypes().get(1), prefix +"dc:type[1]");
70         
71         assertProperty((String JavaDoc)dc.getFormats().get(0), prefix + "dc:format[0]");
72         assertProperty((String JavaDoc)dc.getFormats().get(1), prefix + "dc:format[1]");
73         
74         assertProperty((String JavaDoc)dc.getIdentifiers().get(0), prefix + "dc:identifier[0]");
75         assertProperty((String JavaDoc)dc.getIdentifiers().get(1), prefix + "dc:identifier[1]");
76         
77         assertProperty((String JavaDoc)dc.getSources().get(0), prefix + "dc:source[0]");
78         assertProperty((String JavaDoc)dc.getSources().get(1), prefix + "dc:source[1]");
79         
80         assertProperty((String JavaDoc)dc.getLanguages().get(0), prefix + "dc:language[0]");
81         assertProperty((String JavaDoc)dc.getLanguages().get(1), prefix + "dc:language[1]");
82         
83         assertProperty((String JavaDoc)dc.getRelations().get(0), prefix + "dc:relation[0]");
84         assertProperty((String JavaDoc)dc.getRelations().get(1), prefix + "dc:relation[1]");
85         
86         assertProperty((String JavaDoc)dc.getCoverages().get(0), prefix + "dc:coverage[0]");
87         assertProperty((String JavaDoc)dc.getCoverages().get(1), prefix + "dc:coverage[1]");
88         
89         assertProperty((String JavaDoc)dc.getRightsList().get(0), prefix + "dc:rights[0]");
90         assertProperty((String JavaDoc)dc.getRightsList().get(1), prefix + "dc:rights[1]");
91     }
92
93     public void testItemsDCModule() throws Exception JavaDoc {
94         _testItemDCModule(0);
95         _testItemDCModule(1);
96     }
97
98     protected void _testItemDCModule(int i) throws Exception JavaDoc {
99         List JavaDoc entries = getCachedSyndFeed().getEntries();
100         SyndEntry entry = (SyndEntry) entries.get(i);
101         DCModule dc = (DCModule) entry.getModule(DCModule.URI);
102         _testDCModule(dc, "item[" + i + "].");
103     }
104 }
105
Popular Tags