1 7 package com.sun.syndication.unittest; 8 9 import com.sun.syndication.feed.module.DCModule; 10 import com.sun.syndication.feed.module.SyModule; 11 import com.sun.syndication.feed.module.DCSubject; 12 import com.sun.syndication.feed.synd.SyndEntry; 13 import com.sun.syndication.io.impl.DateParser; 14 15 import java.util.Date ; 16 import java.util.List ; 17 18 19 25 public class TestSyndFeedAtom03DCSyModules extends TestSyndFeedAtom03 { 26 27 public TestSyndFeedAtom03DCSyModules() { 28 super("atom_0.3", "atom_0.3_DC_Sy.xml"); 29 } 30 31 protected TestSyndFeedAtom03DCSyModules(String type) { 32 super(type); 33 } 34 35 protected TestSyndFeedAtom03DCSyModules(String feedType,String feedFileName) { 36 super(feedType,feedFileName); 37 } 38 39 public void testModules() throws Exception { 40 DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); 41 assertNotNull(dc); 42 SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI); 43 assertNotNull(sy); 44 } 45 46 public void testFeedDCModule() throws Exception { 47 DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); 48 _testDCModule(dc,"feed.",false,0); 49 } 50 51 protected void _testDCModule(DCModule dc,String prefix,boolean isEntry,int index) throws Exception { 52 assertNotNull(dc); 53 assertProperty(dc.getTitle(),prefix+"dc:title"); 54 55 assertProperty(dc.getCreator(),prefix+"author.name"); 57 assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(),prefix+"dc:subject[0]"); 58 String taxo0 = ((DCSubject)dc.getSubjects().get(0)).getTaxonomyUri(); 59 if (taxo0!=null) { 60 assertProperty(taxo0,prefix+"dc:subject[0].taxo:topic^resource"); 61 } 62 assertProperty(((DCSubject)dc.getSubjects().get(1)).getValue(),prefix+"dc:subject[1]"); 63 String taxo1 = ((DCSubject)dc.getSubjects().get(1)).getTaxonomyUri(); 64 if (taxo1!=null) { 65 assertProperty(taxo1,prefix+"dc:subject[1].taxo:topic^resource"); 66 } 67 assertProperty(dc.getDescription(),prefix+"dc:description"); 68 assertProperty(dc.getPublisher(),prefix+"dc:publisher"); 69 assertProperty((String )dc.getContributors().get(0),prefix+"dc:contributor[0]"); 70 assertProperty((String )dc.getContributors().get(1),prefix+"dc:contributor[1]"); 71 Date date = DateParser.parseW3CDateTime("2000-0"+(index+1)+"-01T00:00:00Z"); 72 assertEquals(dc.getDate(),date); 73 assertProperty(dc.getType(),prefix+"dc:type"); 74 assertProperty(dc.getFormat(),prefix+"dc:format"); 75 assertProperty(dc.getIdentifier(),prefix+"dc:identifier"); 76 assertProperty(dc.getSource(),prefix+"dc:source"); 77 assertProperty(dc.getLanguage(),prefix+"dc:language"); 78 assertProperty(dc.getRelation(),prefix+"dc:relation"); 79 assertProperty(dc.getCoverage(),prefix+"dc:coverage"); 80 81 if (isEntry) { 82 assertProperty(dc.getRights(),prefix+"dc:rights"); 83 } 84 else { 85 assertProperty(dc.getRights(),prefix+"copyright"); } 87 } 88 89 public void testFeedSyModule() throws Exception { 90 SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI); 91 assertNotNull(sy); 92 assertEquals(sy.getUpdatePeriod(),SyModule.HOURLY); 93 assertEquals(sy.getUpdateFrequency(),100); 94 Date date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00"); 95 assertEquals(sy.getUpdateBase(),date); 96 } 97 98 public void testEntriesDCModule() throws Exception { 99 _testEntryDCModule(0); 100 _testEntryDCModule(1); 101 } 102 103 protected void _testEntryDCModule(int i) throws Exception { 104 List entries = getCachedSyndFeed().getEntries(); 105 SyndEntry entry = (SyndEntry) entries.get(i); 106 DCModule dc = (DCModule) entry.getModule(DCModule.URI); 107 _testDCModule(dc,"feed.entry["+i+"].",true,i); 108 109 } 110 111 112 } 113 | Popular Tags |