001: /*
002: * Created on Jun 25, 2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package com.sun.syndication.unittest;
008:
009: import com.sun.syndication.feed.module.DCModule;
010: import com.sun.syndication.feed.module.SyModule;
011: import com.sun.syndication.feed.module.DCSubject;
012: import com.sun.syndication.feed.synd.SyndEntry;
013: import com.sun.syndication.io.impl.DateParser;
014:
015: import java.util.Date;
016: import java.util.List;
017:
018: /**
019: * @author pat
020: *
021: * TODO To change the template for this generated type comment go to
022: * Window - Preferences - Java - Code Generation - Code and Comments
023: */
024: public class TestSyndFeedAtom03DCSyModules extends TestSyndFeedAtom03 {
025:
026: public TestSyndFeedAtom03DCSyModules() {
027: super ("atom_0.3", "atom_0.3_DC_Sy.xml");
028: }
029:
030: protected TestSyndFeedAtom03DCSyModules(String type) {
031: super (type);
032: }
033:
034: protected TestSyndFeedAtom03DCSyModules(String feedType,
035: String feedFileName) {
036: super (feedType, feedFileName);
037: }
038:
039: public void testModules() throws Exception {
040: DCModule dc = (DCModule) getCachedSyndFeed().getModule(
041: DCModule.URI);
042: assertNotNull(dc);
043: SyModule sy = (SyModule) getCachedSyndFeed().getModule(
044: SyModule.URI);
045: assertNotNull(sy);
046: }
047:
048: public void testFeedDCModule() throws Exception {
049: DCModule dc = (DCModule) getCachedSyndFeed().getModule(
050: DCModule.URI);
051: _testDCModule(dc, "feed.", false, 0);
052: }
053:
054: protected void _testDCModule(DCModule dc, String prefix,
055: boolean isEntry, int index) throws Exception {
056: assertNotNull(dc);
057: assertProperty(dc.getTitle(), prefix + "dc:title");
058:
059: assertProperty(dc.getCreator(), prefix + "dc:creator"); // Convenience method
060:
061: assertProperty(
062: ((DCSubject) dc.getSubjects().get(0)).getValue(),
063: prefix + "dc:subject[0]");
064: String taxo0 = ((DCSubject) dc.getSubjects().get(0))
065: .getTaxonomyUri();
066: if (taxo0 != null) {
067: assertProperty(taxo0, prefix
068: + "dc:subject[0].taxo:topic^resource");
069: }
070: assertProperty(
071: ((DCSubject) dc.getSubjects().get(1)).getValue(),
072: prefix + "dc:subject[1]");
073: String taxo1 = ((DCSubject) dc.getSubjects().get(1))
074: .getTaxonomyUri();
075: if (taxo1 != null) {
076: assertProperty(taxo1, prefix
077: + "dc:subject[1].taxo:topic^resource");
078: }
079: assertProperty(dc.getDescription(), prefix + "dc:description");
080: assertProperty(dc.getPublisher(), prefix + "dc:publisher");
081: assertProperty((String) dc.getContributors().get(0), prefix
082: + "dc:contributor[0]");
083: assertProperty((String) dc.getContributors().get(1), prefix
084: + "dc:contributor[1]");
085: Date date = DateParser.parseW3CDateTime("2000-0" + (index + 1)
086: + "-01T00:00:00Z");
087: assertEquals(dc.getDate(), date);
088: assertProperty(dc.getType(), prefix + "dc:type");
089: assertProperty(dc.getFormat(), prefix + "dc:format");
090: assertProperty(dc.getIdentifier(), prefix + "dc:identifier");
091: assertProperty(dc.getSource(), prefix + "dc:source");
092: assertProperty(dc.getLanguage(), prefix + "dc:language");
093: assertProperty(dc.getRelation(), prefix + "dc:relation");
094: assertProperty(dc.getCoverage(), prefix + "dc:coverage");
095:
096: if (isEntry) {
097: assertProperty(dc.getRights(), prefix + "dc:rights");
098: } else {
099: assertProperty(dc.getRights(), prefix + "copyright"); // in header is convenience method
100: }
101: }
102:
103: public void testFeedSyModule() throws Exception {
104: SyModule sy = (SyModule) getCachedSyndFeed().getModule(
105: SyModule.URI);
106: assertNotNull(sy);
107: assertEquals(sy.getUpdatePeriod(), SyModule.HOURLY);
108: assertEquals(sy.getUpdateFrequency(), 100);
109: Date date = DateParser
110: .parseW3CDateTime("2001-01-01T01:00+00:00");
111: assertEquals(sy.getUpdateBase(), date);
112: }
113:
114: public void testEntriesDCModule() throws Exception {
115: _testEntryDCModule(0);
116: _testEntryDCModule(1);
117: }
118:
119: protected void _testEntryDCModule(int i) throws Exception {
120: List entries = getCachedSyndFeed().getEntries();
121: SyndEntry entry = (SyndEntry) entries.get(i);
122: DCModule dc = (DCModule) entry.getModule(DCModule.URI);
123: _testDCModule(dc, "feed.entry[" + i + "].", true, i);
124:
125: }
126:
127: }
|