@Test
 public void testDelTree() throws Exception {
   WikiPage levelOne = crawler.addPage(root, PathParser.parse("LevelOne"));
   WikiPage levelTwo = crawler.addPage(levelOne, PathParser.parse("LevelTwo"));
   levelOne.commit(levelOne.getData());
   levelTwo.commit(levelTwo.getData());
   File childOne = new File(defaultPath + "/RooT/LevelOne");
   File childTwo = new File(defaultPath + "/RooT/LevelOne/LevelTwo");
   assertTrue(childOne.exists());
   root.removeChildPage("LevelOne");
   assertFalse(childTwo.exists());
   assertFalse(childOne.exists());
 }
 @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 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);
  }
 private WikiPage addTestPage(WikiPage page, String name, String content) {
   WikiPage testPage = WikiPageUtil.addPage(page, PathParser.parse(name), content);
   PageData data = testPage.getData();
   data.setAttribute("Test");
   testPage.commit(data);
   return testPage;
 }
  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=\".*\">&nbsp;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\">&gt;SomeChild</a>", content);

    assertSubString("<td>file://some/page</td>", content);
  }
Example #6
0
 @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 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);
 }
  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 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;
  }
Example #10
0
  protected void movePage(WikiPage movedPage, WikiPage targetPage) throws Exception {
    PageData pageData = movedPage.getData();

    targetPage.commit(pageData);

    moveChildren(movedPage, targetPage);

    WikiPage parentOfMovedPage = movedPage.getParent();
    parentOfMovedPage.removeChildPage(movedPage.getName());
  }
Example #11
0
 @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()));
 }
 private void addImportPropertyToPage(WikiPage page, boolean isRoot, boolean autoUpdate)
     throws Exception {
   PageData data = page.getData();
   String sourceUrl = FitNesseUtil.URL + "PageOne";
   WikiImportProperty importProps = new WikiImportProperty(sourceUrl);
   importProps.setRoot(isRoot);
   importProps.setAutoUpdate(autoUpdate);
   importProps.addTo(data.getProperties());
   pageOne.commit(data);
 }
 @Test
 public void testRemovePage() throws Exception {
   WikiPage levelOne = WikiPageUtil.addPage(root, PathParser.parse("LevelOne"));
   levelOne.commit(levelOne.getData());
   WikiPageUtil.addPage(levelOne, PathParser.parse("LevelTwo"));
   levelOne.removeChildPage("LevelTwo");
   File fileOne = new File(defaultPath + "/RooT/LevelOne");
   File fileTwo = new File(defaultPath + "/RooT/LevelOne/LevelTwo");
   assertTrue(fileOne.exists());
   assertFalse(fileTwo.exists());
 }
  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);
  }
  private void removeSymbolicLink(Request request, WikiPage page) {
    String linkToRemove = request.getInput("removal");

    PageData data = page.getData();
    WikiPageProperty properties = data.getProperties();
    WikiPageProperty symLinks = getSymLinkProperty(properties);
    symLinks.remove(linkToRemove);
    if (symLinks.keySet().isEmpty()) properties.remove(SymbolicPage.PROPERTY_NAME);
    page.commit(data);
    setRedirect(resource);
  }
  public void testHelpTextDisplayed() throws Exception {
    WikiPage page = getContentFromSimplePropertiesPage();
    PageData data = page.getData();
    data.setAttribute(PageData.PropertyHELP, "help text");
    page.commit(data);

    getPropertiesContentFromPage(page);

    assertSubString("Help Text", content);
    assertSubString(
        "<input type=\"text\" name=\"HelpText\" value=\"help text\" size=\"90\"/>", content);
  }
Example #17
0
  public void testEnterChildPageWhenRemotePageNotModified() throws Exception {
    importer.enterChildPage(pageOne, Clock.currentDate());
    importer.exitPage();

    PageData data = pageOne.getData();
    data.setContent("new content");
    pageOne.commit(data);

    importer.enterChildPage(pageOne, new Date(0));

    assertEquals("new content", pageOne.getData().getContent());
  }
  @Test
  public void testImportedPageIndication() throws Exception {
    final WikiPage page = WikiPageUtil.addPage(root, PathParser.parse("SamplePage"));
    final PageData data = page.getData();
    final WikiImportProperty importProperty = new WikiImportProperty("blah");
    importProperty.addTo(data.getProperties());
    page.commit(data);

    final String content = requestPage("SamplePage").getContent();

    assertSubString("<body class=\"imported\">", content);
  }
  private void addSymbolicLink(Request request, WikiPage page) throws Exception {
    String linkName = StringUtils.trim(request.getInput("linkName"));
    String linkPath = StringUtils.trim(request.getInput("linkPath"));

    PageData data = page.getData();
    WikiPageProperty properties = data.getProperties();
    WikiPageProperty symLinks = getSymLinkProperty(properties);
    if (isValidLinkPathName(linkPath) && isValidWikiPageName(linkName, symLinks)) {
      symLinks.set(linkName, linkPath);
      page.commit(data);
      setRedirect(resource);
    }
  }
 @Before
 public void setUp() throws Exception {
   suitePageName = "SuitePage";
   root = InMemoryPage.makeRoot("RooT");
   context = FitNesseUtil.makeTestContext(root);
   crawler = root.getPageCrawler();
   PageData data = root.getData();
   data.setContent(classpathWidgets());
   root.commit(data);
   suite = crawler.addPage(root, PathParser.parse(suitePageName), "This is the test suite\n");
   testPages = new LinkedList<WikiPage>();
   testPage = addTestPage(suite, "TestOne", "My test");
 }
 @Test
 public void testPersistentAttributes() throws Exception {
   WikiPage createdPage = crawler.addPage(root, PathParser.parse("FrontPage"));
   PageData data = createdPage.getData();
   data.setAttribute("Test", "true");
   data.setAttribute("Search", "true");
   createdPage.commit(data);
   assertTrue(data.hasAttribute("Test"));
   assertTrue(data.hasAttribute("Search"));
   WikiPage page = root.getChildPage("FrontPage");
   assertTrue(page.getData().hasAttribute("Test"));
   assertTrue(page.getData().hasAttribute("Search"));
 }
  @Test
  public void testRemoval() throws Exception {
    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("removal", "SymLink");
    Response response = invokeResponder();
    checkPageOneRedirectToProperties(response);

    assertNull(pageOne.getChildPage("SymLink"));
  }
  private void testWikiImportUpdateWith(WikiImportProperty property) throws Exception {
    WikiPage page = root.addChildPage("SomePage");
    PageData data = page.getData();
    property.addTo(data.getProperties());
    page.commit(data);

    getPropertiesContentFromPage(page);
    checkUpdateForm();
    assertSubString("Wiki Import Update", content);
    assertSubString(
        "<a href=\"http://my.host.com/PageRoot\">http://my.host.com/PageRoot</a>", content);

    assertNotSubString("value=\"Import\"", content);
  }
Example #24
0
  private WikiPage addLocalPageWithImportProperty(
      WikiPage parentPage, String pageName, boolean isRoot) throws Exception {
    WikiPage page = parentPage.addChildPage(pageName);
    PageData data = page.getData();

    WikiPagePath pagePath = localRoot.getPageCrawler().getFullPath(page);
    WikiImportProperty importProps =
        new WikiImportProperty(
            "http://localhost:" + FitNesseUtil.port + "/" + PathParser.render(pagePath));
    if (isRoot) importProps.setRoot(true);
    importProps.addTo(data.getProperties());
    page.commit(data);

    return page;
  }
  public Response makeResponse(FitNesseContext context, Request request) {
    SimpleResponse response = new SimpleResponse();
    String resource = request.getResource();
    WikiPagePath path = PathParser.parse(resource);
    WikiPage page = context.root.getPageCrawler().getPage(path);
    if (page == null) return new NotFoundResponder().makeResponse(context, request);
    PageData data = page.getData();
    saveAttributes(request, data);
    VersionInfo commitRecord = page.commit(data);
    response.addHeader("Current-Version", commitRecord.getName());
    context.recentChanges.updateRecentChanges(data);
    response.redirect(resource);

    return response;
  }
Example #26
0
  public void testAutoUpdateWhenRemotePageNotModified() throws Exception {
    importer.enterChildPage(pageOne, Clock.currentDate());
    importer.exitPage();

    PageData data = pageOne.getData();
    data.setContent("new content");
    pageOne.commit(data);

    importer.setAutoUpdateSetting(true);
    importer.enterChildPage(pageOne, new Date(0));

    WikiImportProperty importProps =
        WikiImportProperty.createFrom(pageOne.getData().getProperties());
    assertTrue(importProps.isAutoUpdate());
  }
  public void testUsernameDisplayed() throws Exception {
    WikiPage page = getContentFromSimplePropertiesPage();

    assertSubString("Last modified anonymously", content);

    PageData data = page.getData();
    data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Bill");
    page.commit(data);

    request.setResource("SomePage");
    SimpleResponse response =
        (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request);
    content = response.getContent();

    assertSubString("Last modified by Bill", content);
  }
  private void renameSymbolicLink(Request request, WikiPage page) throws Exception {
    String linkToRename = (String) request.getInput("rename"),
        newName = (String) request.getInput("newname");

    PageData data = page.getData();
    WikiPageProperty properties = data.getProperties();
    WikiPageProperty symLinks = getSymLinkProperty(properties);

    if (isValidWikiPageName(newName, symLinks)) {
      String currentPath = symLinks.get(linkToRename);
      symLinks.remove(linkToRename);
      symLinks.set(newName, currentPath);
      page.commit(data);
      setRedirect(resource);
    }
  }
  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\">&lt;SomePage.OtherChild</a>", content);
  }
Example #30
0
  @Test
  public void testEmptyTestPage() throws Exception {
    PageData data = root.getData();
    data.setContent(classpathWidgets());
    root.commit(data);
    testPage = crawler.addPage(root, PathParser.parse("EmptyTestPage"));
    request.setResource(testPage.getName());

    response = responder.makeResponse(context, request);
    sender = new MockResponseSender();
    sender.doSending(response);
    sender.sentData();

    WikiPagePath errorLogPath = PathParser.parse("ErrorLogs.EmptyTestPage");
    WikiPage errorLogPage = crawler.getPage(root, errorLogPath);
    String errorLogContent = errorLogPage.getData().getContent();
    assertNotSubString("Exception", errorLogContent);
  }