@Test public void testResponse() throws Exception { WikiPage page = WikiPageUtil.addPage(root, PathParser.parse("ChildPage"), "child content"); PageData data = page.getData(); WikiPageProperties properties = data.getProperties(); properties.set(PageData.PropertySUITES, "Wiki Page tags"); page.commit(data); final MockRequest request = new MockRequest(); request.setResource("ChildPage"); final Responder responder = new WikiPageResponder(); final SimpleResponse response = (SimpleResponse) responder.makeResponse(context, request); assertEquals(200, response.getStatus()); final String body = response.getContent(); assertSubString("<html>", body); assertSubString("<body", body); assertSubString("child content", body); assertSubString("href=\"ChildPage?whereUsed\"", body); assertSubString("Cache-Control: max-age=0", response.makeHttpHeaders()); assertSubString("<h5> Wiki Page tags</h5>", body); }
public void testSymbolicLinkListing() throws Exception { WikiPage page = root.addChildPage("SomePage"); page.addChildPage("SomeChild"); WikiPage pageOne = root.addChildPage("PageOne"); // ...page must exist! pageOne.addChildPage("ChildOne"); // ...page must exist! PageData data = page.getData(); WikiPageProperties props = data.getProperties(); WikiPageProperty symProp = props.set(SymbolicPage.PROPERTY_NAME); symProp.set("InternalAbsPage", ".PageOne.ChildOne"); symProp.set("InternalRelPage", "PageOne.ChildOne"); symProp.set("InternalSubPage", ">SomeChild"); symProp.set("ExternalPage", "file://some/page"); page.commit(data); getPropertiesContentFromPage(page); assertSubString("<td>InternalAbsPage</td>", content); assertSubString("<input type=\"text\" name=\"InternalAbsPage\"", content); assertSubString("<a href=\".PageOne.ChildOne\">.PageOne.ChildOne</a>", content); assertMatches("<a href=\".*\"> Rename:</a>", content); assertSubString("<td>InternalRelPage</td>", content); assertSubString("<input type=\"text\" name=\"InternalRelPage\"", content); assertSubString("<a href=\".PageOne.ChildOne\">PageOne.ChildOne</a>", content); assertSubString("<td>InternalSubPage</td>", content); assertSubString("<input type=\"text\" name=\"InternalSubPage\"", content); assertSubString("<a href=\".SomePage.SomeChild\">>SomeChild</a>", content); assertSubString("<td>file://some/page</td>", content); }
@Test public void testLastModificationTime() throws Exception { DateFormat format = WikiPageProperty.getTimeFormat(); WikiPageProperties props = new WikiPageProperties(); assertEquals( format.format(Clock.currentDate()), format.format(props.getLastModificationTime())); Date date = format.parse("20040101000001"); props.setLastModificationTime(date); assertEquals("20040101000001", props.get(PageData.PropertyLAST_MODIFIED)); assertEquals(date, props.getLastModificationTime()); }
protected List<WikiPage> getSymlinkChildren(WikiPage page) { List<WikiPage> children = new LinkedList<>(); WikiPageProperties props = page.getData().getProperties(); WikiPageProperty symLinksProperty = props.getProperty(SymbolicPage.PROPERTY_NAME); if (symLinksProperty != null) { for (String linkName : symLinksProperty.keySet()) { WikiPage linkedPage = createSymbolicPage(page, linkName); if (linkedPage != null && !children.contains(linkedPage)) children.add(linkedPage); } } return children; }
private void attemptToReadPropertiesFile(File file, PageData data, long lastModifiedTime) throws Exception { InputStream input = null; try { final WikiPageProperties props = new WikiPageProperties(); input = new FileInputStream(file); props.loadFromXmlStream(input); props.setLastModificationTime(new Date(lastModifiedTime)); data.setProperties(props); } finally { if (input != null) input.close(); } }
@Test public void testKeySet() throws Exception { properties = new WikiPageProperties(); properties.set("one"); properties.set("two"); properties.set("three"); Set<?> keys = properties.keySet(); assertTrue(keys.contains("one")); assertTrue(keys.contains("two")); assertTrue(keys.contains("three")); assertFalse(keys.contains("four")); }
private void saveNewProperties(String path, Properties oldProps) throws Exception { File newPropsFile = new File(path + FileSystemPage.propertiesFilename); WikiPageProperties newProps = new WikiPageProperties(); for (Iterator iterator = oldProps.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); String value = (String) oldProps.get(key); if (!"false".equals(value)) newProps.set(key, value); } FileOutputStream os = new FileOutputStream(newPropsFile); newProps.save(os); os.close(); }
public void testSymbolicLinkListingForBackwardPath() throws Exception { WikiPage page = root.addChildPage("SomePage"); WikiPage child = page.addChildPage("SomeChild"); page.addChildPage("OtherChild"); PageData data = child.getData(); WikiPageProperties props = data.getProperties(); WikiPageProperty symProp = props.set(SymbolicPage.PROPERTY_NAME); symProp.set("InternalBackPage", "<SomePage.OtherChild"); page.commit(data); getPropertiesContentFromPage(page); assertSubString("InternalBackPage", content); assertSubString("<a href=\".SomePage.OtherChild\"><SomePage.OtherChild</a>", content); }
@Test public void testToXml() throws Exception { String xml = properties.toXml(); for (String fragment : sampleXmlFragments) { assertTrue(fragment, xml.contains(fragment)); } }
public void testResponse() throws Exception { WikiPage page = crawler.addPage(root, PathParser.parse("PageOne")); PageData data = page.getData(); data.setContent("some content"); WikiPageProperties properties = data.getProperties(); properties.set("Test", "true"); properties.set(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, "http://www.fitnesse.org"); page.commit(data); MockRequest request = new MockRequest(); request.setResource("PageOne"); Responder responder = new PropertiesResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request); assertEquals("max-age=0", response.getHeader("Cache-Control")); String content = response.getContent(); assertSubString("PageOne", content); assertSubString("value=\"http://www.fitnesse.org\"", content); assertDoesntHaveRegexp("textarea name=\"extensionXml\"", content); assertHasRegexp("<input.*value=\"Save Properties\".*>", content); assertHasRegexp("<input.*value=\"saveProperties\"", content); assertSubString("<input type=\"checkbox\" name=\"Test\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Search\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Edit\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Properties\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Suite\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Prune\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Versions\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Refactor\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"WhereUsed\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"RecentChanges\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_READ + "\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_WRITE + "\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_TEST + "\"/>", content); }
protected synchronized void saveAttributes(final WikiPageProperties attributes) throws Exception { OutputStream output = null; String propertiesFilePath = "<unknown>"; try { propertiesFilePath = getFileSystemPath() + propertiesFilename; File propertiesFile = new File(propertiesFilePath); if (propertiesFile.exists()) cmSystem.edit(propertiesFilePath); output = new FileOutputStream(propertiesFile); WikiPageProperties propertiesToSave = new WikiPageProperties(attributes); removeAlwaysChangingProperties(propertiesToSave); propertiesToSave.save(output); } catch (final Exception e) { System.err.println( "Failed to save properties file: \"" + propertiesFilePath + "\" (exception: " + e + ")."); e.printStackTrace(); throw e; } finally { if (output != null) { output.close(); cmSystem.update(propertiesFilePath); } } }
private void validateLoading() throws Exception { assertTrue(properties.has("Edit")); assertTrue(properties.has("Test")); assertFalse(properties.has("Suite")); assertEquals("http://someurl", properties.get("VirtualWiki")); WikiPageProperty parentOne = properties.getProperty("ParentOne"); assertEquals(null, parentOne.getValue()); assertEquals("child one value", parentOne.get("ChildOne")); WikiPageProperty parentTwo = properties.getProperty("ParentTwo"); assertEquals("parent 2 value", parentTwo.getValue()); assertEquals("child two value", parentTwo.get("ChildTwo")); WikiPageProperty symbolics = properties.getProperty("SymbolicLinks"); assertEquals("<BackWard.SymLink", symbolics.get("BackLink")); assertEquals("RelaTive.SymLink", symbolics.get("RelLink")); assertEquals(".AbsoLute.SymLink", symbolics.get("AbsLink")); assertEquals(">SubChild.SymLink", symbolics.get("SubLink")); }
private void removeAlwaysChangingProperties(WikiPageProperties properties) { properties.remove(PageData.PropertyLAST_MODIFIED); }