001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.responders;
004:
005: import fitnesse.Responder;
006: import fitnesse.wiki.*;
007: import fitnesse.util.XmlUtil;
008: import fitnesse.http.*;
009: import org.w3c.dom.*;
010:
011: public class RssResponderTest extends AbstractResponderRegex {
012: protected Element channelElement;
013:
014: protected Element rssElement;
015:
016: protected Document rssDoc;
017:
018: // Return an instance of the Responder being tested.
019: protected Responder responderInstance() {
020: return new RssResponder();
021: }
022:
023: public void testEmptyRssReport() throws Exception {
024: buildRssChannel();
025: assertEquals("rss", rssElement.getTagName());
026: assertEquals("2.0", rssElement.getAttribute("version"));
027: assertNotNull(channelElement);
028: assertEquals("FitNesse:", XmlUtil.getTextValue(channelElement,
029: "title"));
030: }
031:
032: public void testOneNewPage() throws Exception {
033: NodeList items = getReportedItems("|MyNewPage|me|now|");
034: assertEquals(1, items.getLength());
035: String title = "MyNewPage";
036: String author = "me";
037: String pubDate = "now";
038: String description = "me:now";
039: checkItem(items.item(0), title, author, pubDate, description,
040: "http://localhost/MyNewPage");
041: }
042:
043: public void testTwoNewPages() throws Exception {
044: String recentChangeOne = "|MyNewPage|me|now|";
045: String recentChangeTwo = "|SomeOtherPage||later|";
046: String recentChangesContent = recentChangeOne + "\n"
047: + recentChangeTwo + "\n";
048: NodeList items = getReportedItems(recentChangesContent);
049: assertEquals(2, items.getLength());
050: checkItem(items.item(0), "MyNewPage", "me", "now", "me:now",
051: "http://localhost/MyNewPage");
052: checkItem(items.item(1), "SomeOtherPage", null, "later",
053: "later", "http://localhost/SomeOtherPage");
054: }
055:
056: public void testReportedPagesSelectedByResource() throws Exception {
057: request.setResource("FrontPage");
058: String page1 = "|SomePage|me|now|";
059: String page2 = "|FrontPage|me|now|";
060: String page3 = "|FrontPage.MyPage|me|now|";
061: String page4 = "|SomePage.FrontPage|me|now";
062:
063: String recentChangesContent = page1 + "\n" + page2 + "\n"
064: + page3 + "\n" + page4 + "\n";
065: NodeList items = getReportedItems(recentChangesContent);
066: assertEquals(2, items.getLength());
067: checkItem(items.item(0), "FrontPage", "me", "now", "me:now",
068: "http://localhost/FrontPage");
069: checkItem(items.item(1), "FrontPage.MyPage", "me", "now",
070: "me:now", "http://localhost/FrontPage.MyPage");
071: }
072:
073: public void testLinkWithSetPrefix() throws Exception {
074: PageData data = root.getData();
075: data.setContent("!define RSS_PREFIX {http://host/}\n");
076: root.commit(data);
077:
078: NodeList items = getReportedItems("|PageName|author|date|");
079: assertEquals(1, items.getLength());
080: checkItem(items.item(0), "PageName", "author", "date",
081: "author:date", "http://host/PageName");
082: }
083:
084: public void testLinkWitDefaultPrefix() throws Exception {
085: NodeList items = getReportedItems("|PageName|author|date|");
086: assertEquals(1, items.getLength());
087: checkItem(items.item(0), "PageName", "author", "date",
088: "author:date", "http://localhost/PageName");
089: }
090:
091: private void buildRssChannel() throws Exception {
092: SimpleResponse response = (SimpleResponse) responder
093: .makeResponse(context, request);
094: rssDoc = XmlUtil.newDocument(response.getContent());
095: rssElement = rssDoc.getDocumentElement();
096: channelElement = XmlUtil.getElementByTagName(rssElement,
097: "channel");
098: }
099:
100: private void checkItem(Node node, String title, String author,
101: String pubDate, String description, String link)
102: throws Exception {
103: Element itemElement = (Element) node;
104: assertEquals(title, XmlUtil.getTextValue(itemElement, "title"));
105: assertEquals(author, XmlUtil
106: .getTextValue(itemElement, "author"));
107: assertEquals(pubDate, XmlUtil.getTextValue(itemElement,
108: "pubDate"));
109: assertEquals(description, XmlUtil.getTextValue(itemElement,
110: "description"));
111: assertEquals(link, XmlUtil.getTextValue(itemElement, "link"));
112: }
113:
114: private NodeList getReportedItems(String recentChangesContent)
115: throws Exception {
116: crawler.addPage(root, PathParser.parse("RecentChanges"),
117: recentChangesContent);
118: buildRssChannel();
119: NodeList items = channelElement.getElementsByTagName("item");
120: return items;
121: }
122: }
|