@Test public void testDefaultAttributesForSuitePageNames() throws Exception { WikiPage suitePage3 = WikiPageUtil.addPage(root, PathParser.parse("TestPageSuite")); PageData data = suitePage3.getData(); assertFalse(data.hasAttribute(TEST.toString())); assertTrue(data.hasAttribute(SUITE.toString())); }
@Test public void testTwoLevel() throws Exception { WikiPage levelA = crawler.addPage(root, PathParser.parse("PageA")); WikiPage page = crawler.addPage(levelA, PathParser.parse("PageB")); page.commit(page.getData()); assertTrue(new File(defaultPath + "/RooT/PageA/PageB").exists()); }
@Test public void testPagesForTestSystemAreSurroundedBySuiteSetupAndTeardown() throws Exception { WikiPage slimPage = addTestPage(suite, "AaSlimTest", simpleSlimDecisionTable); WikiPage setUp = crawler.addPage(root, PathParser.parse("SuiteSetUp"), "suite set up"); WikiPage tearDown = crawler.addPage(root, PathParser.parse("SuiteTearDown"), "suite tear down"); testPages = new LinkedList<WikiPage>(); testPages.add(setUp); testPages.add(slimPage); testPages.add(testPage); testPages.add(tearDown); MultipleTestsRunner runner = new MultipleTestsRunner(testPages, context, suite, null); Map<TestSystem.Descriptor, LinkedList<TestPage>> map = runner.makeMapOfPagesByTestSystem(); TestSystem.Descriptor fitDescriptor = TestSystem.getDescriptor(testPage.getData(), context.pageFactory, false); TestSystem.Descriptor slimDescriptor = TestSystem.getDescriptor(slimPage.getData(), context.pageFactory, false); List<TestPage> fitList = map.get(fitDescriptor); List<TestPage> slimList = map.get(slimDescriptor); assertEquals(3, fitList.size()); assertEquals(3, slimList.size()); assertEquals(setUp, fitList.get(0).getSourcePage()); assertEquals(testPage, fitList.get(1).getSourcePage()); assertEquals(tearDown, fitList.get(2).getSourcePage()); assertEquals(setUp, slimList.get(0).getSourcePage()); assertEquals(slimPage, slimList.get(1).getSourcePage()); assertEquals(tearDown, slimList.get(2).getSourcePage()); }
/** * Compare two pages (WikiPage version). Compares them by name first. If the same name, compares * their versions. * * @param page1 the first page * @param page2 the second page * @return see java.util.Comparator * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(WikiPage page1, WikiPage page2) { if (page1 == page2) return 0; // the same object int res = m_comparator.compare(page1.getName(), page2.getName()); if (res == 0) res = page1.getVersion() - page2.getVersion(); return res; }
@Test public void DirectoryWithContentIsFileSystemPage() throws Exception { fileSystem.makeFile("./somepath/WikiPage/content.txt", "stuff"); fileSystem.makeFile("./somepath/WikiPage/subsuite/myfile.html", "stuff"); WikiPage page = pageRepository.makeChildPage("WikiPage", rootPage); assertEquals(FileSystemPage.class, page.getClass()); }
/** * Updates the lucene index for a single page. * * @param page The WikiPage to check * @param text The page text to index. */ protected synchronized void updateLuceneIndex(WikiPage page, String text) { IndexWriter writer = null; log.debug("Updating Lucene index for page '" + page.getName() + "'..."); Directory luceneDir = null; try { pageRemoved(page); // Now add back the new version. luceneDir = new SimpleFSDirectory(new File(m_luceneDirectory), null); writer = getIndexWriter(luceneDir); luceneIndexPage(page, text, writer); } catch (IOException e) { log.error("Unable to update page '" + page.getName() + "' from Lucene index", e); // reindexPage( page ); } catch (Exception e) { log.error("Unexpected Lucene exception - please check configuration!", e); // reindexPage( page ); } finally { close(writer); } log.debug("Done updating Lucene index for page '" + page.getName() + "'."); }
@Test public void testThatTestAtEndOfNameSetsTestProperty() throws Exception { WikiPage testPage2 = WikiPageUtil.addPage(root, PathParser.parse("PageTest")); PageData data = testPage2.getData(); assertTrue(data.hasAttribute(TEST.toString())); assertFalse(data.hasAttribute(SUITE.toString())); }
@Test public void testUnicodeCharacters() throws Exception { WikiPage page = WikiPageUtil.addPage(root, PathParser.parse("SomePage"), "\uba80\uba81\uba82\uba83"); PageData data = page.getData(); assertEquals("\uba80\uba81\uba82\uba83", data.getContent()); }
@Test public void testThatSuiteAtBeginningOfNameSetsSuiteProperty() throws Exception { WikiPage suitePage1 = WikiPageUtil.addPage(root, PathParser.parse("SuitePage")); PageData data = suitePage1.getData(); assertFalse(data.hasAttribute(TEST.toString())); assertTrue(data.hasAttribute(SUITE.toString())); }
@Test public void testSuiteSetUpAndTearDownIsCalledIfSingleTestIsRun() throws Exception { responder.setFastTest(false); WikiPage suitePage = crawler.addPage(root, PathParser.parse("TestSuite"), classpathWidgets()); WikiPage testPage = crawler.addPage( suitePage, PathParser.parse("TestPage"), outputWritingTable("Output of TestPage")); crawler.addPage( suitePage, PathParser.parse(SuiteContentsFinder.SUITE_SETUP_NAME), outputWritingTable("Output of SuiteSetUp")); crawler.addPage( suitePage, PathParser.parse(SuiteContentsFinder.SUITE_TEARDOWN_NAME), outputWritingTable("Output of SuiteTearDown")); WikiPagePath testPagePath = crawler.getFullPath(testPage); String resource = PathParser.render(testPagePath); request.setResource(resource); Response response = responder.makeResponse(context, request); MockResponseSender sender = new MockResponseSender(); sender.doSending(response); results = sender.sentData(); assertEquals("Output Captured", getExecutionStatusMessage()); assertHasRegexp("ErrorLog", results); WikiPage errorLog = crawler.getPage(errorLogsParentPage, testPagePath); String errorLogContent = errorLog.getData().getContent(); assertHasRegexp("Output of SuiteSetUp", errorLogContent); assertHasRegexp("Output of TestPage", errorLogContent); assertHasRegexp("Output of SuiteTearDown", errorLogContent); }
@Test public void testLastModifiedTime() throws Exception { WikiPage page = crawler.addPage(root, PathParser.parse("SomePage"), "some text"); page.commit(page.getData()); long now = Clock.currentTimeInMillis(); Date lastModified = page.getData().getProperties().getLastModificationTime(); assertTrue(now - lastModified.getTime() <= 5000); }
@Test public void testDefaultAttributes() throws Exception { WikiPage page = crawler.addPage(root, PathParser.parse("PageOne"), "something"); assertTrue(page.getData().hasAttribute("Edit")); assertTrue(page.getData().hasAttribute("Search")); assertFalse(page.getData().hasAttribute("Test")); assertFalse(page.getData().hasAttribute("TestSuite")); }
@Test public void testCanFindExistingPages() throws Exception { WikiPageUtil.addPage(root, PathParser.parse("FrontPage"), "front page"); WikiPage newRoot = new FileSystemPageFactory() .makePage(new File(base, "RooT"), "RooT", null, new SystemVariableSource()); assertNotNull(newRoot.getChildPage("FrontPage")); }
@Test public void testCanSaveOutOfOrderIfFromSameEditSession() throws Exception { PageData data = somePage.getData(); long ticket = 99; long time = SaveRecorder.pageSaved(data, ticket, clock); somePage.commit(data); assertFalse(SaveRecorder.changesShouldBeMerged(time - 1, ticket, data)); }
@Test public void testUsernameColumnWithoutUser() throws Exception { recentChangesWikiPage.updateRecentChanges(page1); WikiPage recentChanges = rootPage.getChildPage("RecentChanges"); List<String> lines = recentChangesWikiPage.getRecentChangesLines(recentChanges.getData()); String line = lines.get(0).toString(); assertSubString("|PageOne||", line); }
@Before public void setUp() throws Exception { rootPage = InMemoryPage.makeRoot("RooT"); newPage = rootPage.addChildPage("SomeNewPage"); page1 = rootPage.addChildPage("PageOne"); page2 = rootPage.addChildPage("PageTwo"); recentChangesWikiPage = new RecentChangesWikiPage(); }
@Test public void testNoDuplicates() throws Exception { recentChangesWikiPage.updateRecentChanges(page1); recentChangesWikiPage.updateRecentChanges(page1); WikiPage recentChanges = rootPage.getChildPage("RecentChanges"); List<String> lines = recentChangesWikiPage.getRecentChangesLines(recentChanges.getData()); assertEquals(1, lines.size()); assertHasRegexp("PageOne", lines.get(0)); }
public void testGetVirtualWikiValue() throws Exception { WikiPage page = crawler.addPage(root, PathParser.parse("PageOne")); PageData data = page.getData(); assertEquals("", PropertiesResponder.getVirtualWikiValue(data)); data.setAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, "http://www.objectmentor.com"); assertEquals("http://www.objectmentor.com", PropertiesResponder.getVirtualWikiValue(data)); }
private WikiPage addTestPage(WikiPage page, String name, String content) throws Exception { WikiPage testPage = crawler.addPage(page, PathParser.parse(name), content); PageData data = testPage.getData(); data.setAttribute("Test"); testPage.commit(data); testPages.add(testPage); return testPage; }
public void testMakeSecurityPropertiesHtml() throws Exception { WikiPage page = root.addChildPage("SomePage"); PageData data = page.getData(); String html = new PropertiesResponder().makeSecurityCheckboxesHtml(data).html(); assertSubString("<div style=\"float: left; width: 150px;\">Security:", html); assertSubString("<input type=\"checkbox\" name=\"secure-read\"/> - secure-read", html); assertSubString("<input type=\"checkbox\" name=\"secure-write\"/> - secure-write", html); assertSubString("<input type=\"checkbox\" name=\"secure-test\"/> - secure-test", html); }
@Test public void DirectoryOfHtmlFilesIsExternalSuitePageChild() throws Exception { fileSystem.makeFile("./somepath/ExternalSuite/subsuite/myfile.html", "stuff"); ExternalSuitePage page = (ExternalSuitePage) pageRepository.makeChildPage("ExternalSuite", rootPage); WikiPage child = pageRepository.findChildren(page).get(0); assertEquals(ExternalSuitePage.class, child.getClass()); assertEquals("SubsuitE", child.getName()); }
private void prepareSymlinkOnPageOne() { PageData data = pageOne.getData(); WikiPageProperty symLinks = data.getProperties().set(SymbolicPage.PROPERTY_NAME); symLinks.set("SymLink", "PageTwo"); pageOne.commit(data); assertNotNull(pageOne.getChildPage("SymLink")); request.addInput("rename", "SymLink"); }
private boolean isInternalPageThatDoesntExist(String linkPath) { String expandedPath = WikiWordReference.expandPrefix(page, linkPath); WikiPagePath path = PathParser.parse(expandedPath); if (path == null) { return true; } WikiPage start = path.isRelativePath() ? page.getParent() : page; // TODO -AcD- a better way? return !start.getPageCrawler().pageExists(path); }
@Test public void testFirstRecentChange() throws Exception { assertEquals(false, rootPage.hasChildPage("RecentChanges")); recentChangesWikiPage.updateRecentChanges(newPage); assertEquals(true, rootPage.hasChildPage("RecentChanges")); WikiPage recentChanges = rootPage.getChildPage("RecentChanges"); List<String> lines = recentChangesWikiPage.getRecentChangesLines(recentChanges.getData()); assertEquals(1, lines.size()); assertHasRegexp("SomeNewPage", lines.get(0)); }
public List getNormalChildren() throws Exception { List children = realPage.getChildren(); List symChildren = new LinkedList(); for (Iterator iterator = children.iterator(); iterator.hasNext(); ) { WikiPage child = (WikiPage) iterator.next(); if (!(child instanceof SymbolicPage)) symChildren.add(new SymbolicPage(child.getName(), child, this)); } return symChildren; }
public void testdoesntTraverseSymbolicPages() throws Exception { PageData data = page1.getData(); data.getProperties().set(SymbolicPage.PROPERTY_NAME).set("SymLink", "PageTwo"); page1.commit(data); crawler.traverse(root, this); assertEquals(6, traversedPages.size()); assertFalse(traversedPages.contains("SymLink")); }
@Test public void testTiming() throws Exception { PageData data = somePage.getData(); long savedTicket = 0; long editTicket = 1; long time = SaveRecorder.pageSaved(data, savedTicket, clock); somePage.commit(data); assertTrue(SaveRecorder.changesShouldBeMerged(time - 1, editTicket, somePage.getData())); assertFalse(SaveRecorder.changesShouldBeMerged(time + 1, editTicket, somePage.getData())); }
public void testSuitesDisplayed() throws Exception { WikiPage page = getContentFromSimplePropertiesPage(); PageData data = page.getData(); data.setAttribute(PageData.PropertySUITES, "smoke"); page.commit(data); getPropertiesContentFromPage(page); assertSubString("Suites", content); assertSubString("<input type=\"text\" name=\"Suites\" value=\"smoke\" size=\"40\"/>", content); }
public void testMakeNavigationPropertiesHtml() throws Exception { WikiPage page = root.addChildPage("SomePage"); PageData data = page.getData(); String html = new PropertiesResponder().makeNavigationCheckboxesHtml(data).html(); assertSubString("<div style=\"float: left; width: 150px;\">Navigation:", html); assertSubString("<input type=\"checkbox\" name=\"Files\" checked=\"true\"/> - Files", html); assertSubString( "<input type=\"checkbox\" name=\"RecentChanges\" checked=\"true\"/> - RecentChanges", html); assertSubString("<input type=\"checkbox\" name=\"Search\" checked=\"true\"/> - Search", html); assertSubString("<input type=\"checkbox\" name=\"Prune\"/> - Prune", html); }
private void executeSymbolicLinkTestWith(String linkName, String linkPath) throws Exception { request.addInput("linkName", linkName); request.addInput("linkPath", linkPath); Response response = invokeResponder(); checkPageOneRedirectToProperties(response); WikiPage symLink = pageOne.getChildPage("SymLink"); assertNotNull(symLink); assertEquals(SymbolicPage.class, symLink.getClass()); }