KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on Jun 25, 2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */

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 JavaDoc;
16 import java.util.List JavaDoc;
17
18
19 /**
20  * @author pat
21  *
22  * TODO To change the template for this generated type comment go to
23  * Window - Preferences - Java - Code Generation - Code and Comments
24  */

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 JavaDoc type) {
32         super(type);
33     }
34
35     protected TestSyndFeedAtom03DCSyModules(String JavaDoc feedType,String JavaDoc feedFileName) {
36         super(feedType,feedFileName);
37     }
38
39     public void testModules() throws Exception JavaDoc {
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 JavaDoc {
47         DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI);
48         _testDCModule(dc,"feed.",false,0);
49     }
50
51     protected void _testDCModule(DCModule dc,String JavaDoc prefix,boolean isEntry,int index) throws Exception JavaDoc {
52         assertNotNull(dc);
53         assertProperty(dc.getTitle(),prefix+"dc:title");
54
55         assertProperty(dc.getCreator(),prefix+"author.name"); // Convenience method
56

57         assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(),prefix+"dc:subject[0]");
58         String JavaDoc 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 JavaDoc 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 JavaDoc)dc.getContributors().get(0),prefix+"dc:contributor[0]");
70         assertProperty((String JavaDoc)dc.getContributors().get(1),prefix+"dc:contributor[1]");
71         Date JavaDoc 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"); // in header is convenience method
86
}
87     }
88
89     public void testFeedSyModule() throws Exception JavaDoc {
90         SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI);
91         assertNotNull(sy);
92         assertEquals(sy.getUpdatePeriod(),SyModule.HOURLY);
93         assertEquals(sy.getUpdateFrequency(),100);
94         Date JavaDoc date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00");
95         assertEquals(sy.getUpdateBase(),date);
96     }
97
98     public void testEntriesDCModule() throws Exception JavaDoc {
99         _testEntryDCModule(0);
100         _testEntryDCModule(1);
101     }
102
103     protected void _testEntryDCModule(int i) throws Exception JavaDoc {
104         List JavaDoc 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