001: package fitnesse.responders;
002:
003: import fitnesse.wiki.*;
004: import fitnesse.testutil.*;
005: import fitnesse.http.*;
006: import fitnesse.*;
007: import fitnesse.html.*;
008: import java.util.Date;
009: import java.text.SimpleDateFormat;
010:
011: public class WikiImportPropertyTest extends RegexTest {
012: private WikiImportProperty property;
013: private WikiPage page;
014:
015: public void setUp() {
016: property = new WikiImportProperty("");
017: }
018:
019: public void testSource() throws Exception {
020: property = new WikiImportProperty("import source");
021: assertEquals("import source", property.getSourceUrl());
022: assertEquals("import source", property.get("Source"));
023: }
024:
025: public void testIsRoot() throws Exception {
026: assertFalse(property.isRoot());
027: assertFalse(property.has("IsRoot"));
028:
029: property.setRoot(true);
030:
031: assertTrue(property.isRoot());
032: assertTrue(property.has("IsRoot"));
033: }
034:
035: public void testAutoUpdate() throws Exception {
036: assertFalse(property.isAutoUpdate());
037: assertFalse(property.has("AutoUpdate"));
038:
039: property.setAutoUpdate(true);
040:
041: assertTrue(property.isAutoUpdate());
042: assertTrue(property.has("AutoUpdate"));
043: }
044:
045: public void testLastUpdated() throws Exception {
046: SimpleDateFormat format = WikiPageProperty.getTimeFormat();
047: Date date = new Date();
048: property.setLastRemoteModificationTime(date);
049:
050: assertEquals(format.format(date), format.format(property
051: .getLastRemoteModificationTime()));
052:
053: assertEquals(format.format(date), property
054: .get("LastRemoteModification"));
055: }
056:
057: public void testFailedCreateFromProperty() throws Exception {
058: assertNull(WikiImportProperty
059: .createFrom(new WikiPageProperty()));
060: }
061:
062: public void testCreateFromProperty() throws Exception {
063: WikiPageProperty rawImportProperty = property
064: .set(WikiImportProperty.PROPERTY_NAME);
065: rawImportProperty.set("IsRoot");
066: rawImportProperty.set("AutoUpdate");
067: rawImportProperty.set("Source", "some source");
068: Date date = new Date();
069: rawImportProperty.set("LastRemoteModification",
070: WikiPageProperty.getTimeFormat().format(date));
071:
072: WikiImportProperty importProperty = WikiImportProperty
073: .createFrom(property);
074: assertEquals("some source", importProperty.getSourceUrl());
075: assertTrue(importProperty.isRoot());
076: assertTrue(importProperty.isAutoUpdate());
077: SimpleDateFormat format = WikiPageProperty.getTimeFormat();
078: assertEquals(format.format(date), format.format(importProperty
079: .getLastRemoteModificationTime()));
080: }
081:
082: public void testAddtoProperty() throws Exception {
083: WikiImportProperty importProperty = new WikiImportProperty(
084: "some source");
085: importProperty.setRoot(true);
086: importProperty.setAutoUpdate(true);
087: importProperty.addTo(property);
088:
089: WikiImportProperty importProperty2 = WikiImportProperty
090: .createFrom(property);
091: assertEquals("some source", importProperty2.getSourceUrl());
092: assertTrue(importProperty2.isRoot());
093: assertTrue(importProperty2.isAutoUpdate());
094: }
095:
096: // Tests for the rendering of import specific page details
097: private WikiPage root;
098: private PageCrawler crawler;
099:
100: public void pageRenderingSetUp() throws Exception {
101: root = InMemoryPage.makeRoot("root");
102: crawler = root.getPageCrawler();
103: }
104:
105: private SimpleResponse requestPage(String name) throws Exception {
106: MockRequest request = new MockRequest();
107: request.setResource(name);
108: Responder responder = new WikiPageResponder();
109: return (SimpleResponse) responder.makeResponse(
110: new FitNesseContext(root), request);
111: }
112:
113: public void testVirtualPageIndication() throws Exception {
114: pageRenderingSetUp();
115:
116: WikiPage targetPage = crawler.addPage(root, PathParser
117: .parse("TargetPage"));
118: crawler.addPage(targetPage, PathParser.parse("ChildPage"));
119: WikiPage linkPage = (BaseWikiPage) crawler.addPage(root,
120: PathParser.parse("LinkPage"));
121: VirtualCouplingExtensionTest
122: .setVirtualWiki(linkPage, "http://localhost:"
123: + FitNesseUtil.port + "/TargetPage");
124:
125: FitNesseUtil.startFitnesse(root);
126: SimpleResponse response = null;
127: try {
128: response = requestPage("LinkPage.ChildPage");
129: } finally {
130: FitNesseUtil.stopFitnesse();
131: }
132:
133: assertSubString("<body class=\"virtual\">", response
134: .getContent());
135: }
136:
137: public void testImportedPageIndication() throws Exception {
138: pageRenderingSetUp();
139:
140: page = crawler.addPage(root, PathParser.parse("SamplePage"));
141: PageData data = page.getData();
142: WikiImportProperty importProperty = new WikiImportProperty(
143: "blah");
144: importProperty.addTo(data.getProperties());
145: page.commit(data);
146:
147: String content = getContentAfterSpecialImportHandling();
148:
149: assertSubString("<body class=\"imported\">", content);
150: }
151:
152: public void testEditActions() throws Exception {
153: pageRenderingSetUp();
154:
155: page = crawler.addPage(root, PathParser.parse("SamplePage"));
156: PageData data = page.getData();
157: page.commit(data);
158: String content = getContentAfterSpecialImportHandling();
159:
160: assertNotSubString("Edit Locally", content);
161: assertNotSubString("Edit Remotely", content);
162:
163: WikiImportProperty importProperty = new WikiImportProperty(
164: "blah");
165: importProperty.addTo(data.getProperties());
166: page.commit(data);
167: content = getContentAfterSpecialImportHandling();
168:
169: assertSubString(
170: "<a href=\"SamplePage?edit\" accesskey=\"e\">Edit Locally</a>",
171: content);
172: assertSubString(
173: "<a href=\"blah?responder=edit&redirectToReferer=true&redirectAction=importAndView\" accesskey=\"e\">Edit Remotely</a>",
174: content);
175: }
176:
177: private String getContentAfterSpecialImportHandling()
178: throws Exception {
179: HtmlPage html = new HtmlPageFactory().newPage();
180: WikiImportProperty.handleImportProperties(html, page, page
181: .getData());
182: return html.html();
183: }
184:
185: }
|