001: package com.sun.syndication.unittest;
002:
003: import com.sun.syndication.feed.module.DCModule;
004: import com.sun.syndication.feed.module.DCSubject;
005: import com.sun.syndication.feed.synd.SyndEntry;
006: import com.sun.syndication.io.impl.DateParser;
007:
008: import java.util.List;
009: import java.util.Date;
010:
011: /**
012: * Test case for the multi-valued DublinCore module elements.
013: * <p>
014: * @author Paul Dlug
015: */
016: public class TestSyndFeedRSS10DCMulti extends TestSyndFeedRSS10 {
017:
018: public TestSyndFeedRSS10DCMulti() {
019: super ("rss_1.0", "rss_1.0_DC_multi.xml");
020: }
021:
022: protected TestSyndFeedRSS10DCMulti(String type) {
023: super (type);
024: }
025:
026: protected TestSyndFeedRSS10DCMulti(String feedType,
027: String feedFileName) {
028: super (feedType, feedFileName);
029: }
030:
031: public void testChannelDCModule() throws Exception {
032: DCModule dc = (DCModule) getCachedSyndFeed().getModule(
033: DCModule.URI);
034: _testDCModule(dc, "channel.");
035: }
036:
037: protected void _testDCModule(DCModule dc, String prefix)
038: throws Exception {
039: assertNotNull(dc);
040:
041: assertProperty((String) dc.getTitles().get(0), prefix
042: + "dc:title[0]");
043: assertProperty((String) dc.getTitles().get(1), prefix
044: + "dc:title[1]");
045:
046: assertProperty((String) dc.getCreators().get(0), prefix
047: + "dc:creator[0]");
048: assertProperty((String) dc.getCreators().get(1), prefix
049: + "dc:creator[1]");
050:
051: assertProperty(
052: ((DCSubject) dc.getSubjects().get(0)).getValue(),
053: prefix + "dc:subject[0]");
054: String taxo0 = ((DCSubject) dc.getSubjects().get(0))
055: .getTaxonomyUri();
056: if (taxo0 != null) {
057: assertProperty(taxo0, prefix
058: + "dc:subject[0].taxo:topic^resource");
059: }
060: assertProperty(
061: ((DCSubject) dc.getSubjects().get(1)).getValue(),
062: prefix + "dc:subject[1]");
063: String taxo1 = ((DCSubject) dc.getSubjects().get(1))
064: .getTaxonomyUri();
065: if (taxo1 != null) {
066: assertProperty(taxo1, prefix
067: + "dc:subject[1].taxo:topic^resource");
068: }
069:
070: assertProperty((String) dc.getDescriptions().get(0), prefix
071: + "dc:description[0]");
072: assertProperty((String) dc.getDescriptions().get(1), prefix
073: + "dc:description[1]");
074:
075: assertProperty((String) dc.getPublishers().get(0), prefix
076: + "dc:publisher[0]");
077: assertProperty((String) dc.getPublishers().get(1), prefix
078: + "dc:publisher[1]");
079:
080: assertProperty((String) dc.getContributors().get(0), prefix
081: + "dc:contributor[0]");
082: assertProperty((String) dc.getContributors().get(1), prefix
083: + "dc:contributor[1]");
084: Date date = DateParser
085: .parseW3CDateTime("2001-01-01T00:00+00:00");
086: assertEquals((Date) dc.getDates().get(0), date);
087: assertEquals((Date) dc.getDates().get(1), date);
088:
089: assertProperty((String) dc.getTypes().get(0), prefix
090: + "dc:type[0]");
091: assertProperty((String) dc.getTypes().get(1), prefix
092: + "dc:type[1]");
093:
094: assertProperty((String) dc.getFormats().get(0), prefix
095: + "dc:format[0]");
096: assertProperty((String) dc.getFormats().get(1), prefix
097: + "dc:format[1]");
098:
099: assertProperty((String) dc.getIdentifiers().get(0), prefix
100: + "dc:identifier[0]");
101: assertProperty((String) dc.getIdentifiers().get(1), prefix
102: + "dc:identifier[1]");
103:
104: assertProperty((String) dc.getSources().get(0), prefix
105: + "dc:source[0]");
106: assertProperty((String) dc.getSources().get(1), prefix
107: + "dc:source[1]");
108:
109: assertProperty((String) dc.getLanguages().get(0), prefix
110: + "dc:language[0]");
111: assertProperty((String) dc.getLanguages().get(1), prefix
112: + "dc:language[1]");
113:
114: assertProperty((String) dc.getRelations().get(0), prefix
115: + "dc:relation[0]");
116: assertProperty((String) dc.getRelations().get(1), prefix
117: + "dc:relation[1]");
118:
119: assertProperty((String) dc.getCoverages().get(0), prefix
120: + "dc:coverage[0]");
121: assertProperty((String) dc.getCoverages().get(1), prefix
122: + "dc:coverage[1]");
123:
124: assertProperty((String) dc.getRightsList().get(0), prefix
125: + "dc:rights[0]");
126: assertProperty((String) dc.getRightsList().get(1), prefix
127: + "dc:rights[1]");
128: }
129:
130: public void testItemsDCModule() throws Exception {
131: _testItemDCModule(0);
132: _testItemDCModule(1);
133: }
134:
135: protected void _testItemDCModule(int i) throws Exception {
136: List entries = getCachedSyndFeed().getEntries();
137: SyndEntry entry = (SyndEntry) entries.get(i);
138: DCModule dc = (DCModule) entry.getModule(DCModule.URI);
139: _testDCModule(dc, "item[" + i + "].");
140: }
141: }
|