コード例 #1
0
  @Test
  public void getMarkdown() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);

    Page page1 = Page.fromText("title", UUID.randomUUID().toString()); // $NON-NLS-1$
    pageStore.savePage(PROJECT, BRANCH_1, "home", page1, null, USER); // $NON-NLS-1$
    RevCommit commit1 = CommitUtils.getLastCommit(repo.r(), "pages/home.page"); // $NON-NLS-1$
    Page page2 = Page.fromText("title", UUID.randomUUID().toString()); // $NON-NLS-1$
    pageStore.savePage(PROJECT, BRANCH_1, "home", page2, null, USER); // $NON-NLS-1$
    RevCommit commit2 = CommitUtils.getLastCommit(repo.r(), "pages/home.page"); // $NON-NLS-1$
    Page page3 = Page.fromText("title", UUID.randomUUID().toString()); // $NON-NLS-1$
    pageStore.savePage(PROJECT, BRANCH_1, "home", page3, null, USER); // $NON-NLS-1$
    RevCommit commit3 = CommitUtils.getLastCommit(repo.r(), "pages/home.page"); // $NON-NLS-1$

    Map<String, String> result =
        pageStore.getMarkdown(
            PROJECT,
            BRANCH_1,
            "home", //$NON-NLS-1$
            Sets.newHashSet(
                "latest",
                "previous",
                commit2.getName(),
                commit1.getName())); // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals(commit3.getName(), result.get("latest")); // $NON-NLS-1$
    assertEquals(commit2.getName(), result.get("previous")); // $NON-NLS-1$
    assertEquals(((PageTextData) page2.getData()).getText(), result.get(commit2.getName()));
    assertEquals(((PageTextData) page1.getData()).getText(), result.get(commit1.getName()));
  }
コード例 #2
0
  @Test
  public void savePageWithSameBaseCommitAndConflictingChanges()
      throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);
    Page page =
        Page.fromText("title", "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\n"); // $NON-NLS-1$ //$NON-NLS-2$
    pageStore.savePage(PROJECT, BRANCH_1, PAGE, page, null, USER);
    String baseCommit = pageStore.getPageMetadata(PROJECT, BRANCH_1, PAGE).getCommit();

    page = Page.fromText("title", "a\nbbb\nc\nd\ne\nf\ng\nh\ni\nj\n"); // $NON-NLS-1$ //$NON-NLS-2$
    pageStore.savePage(PROJECT, BRANCH_1, PAGE, page, baseCommit, USER);
    page = Page.fromText("title", "a\nxxx\nc\nd\ne\nf\ng\nh\ni\nj\n"); // $NON-NLS-1$ //$NON-NLS-2$
    MergeConflict conflict = pageStore.savePage(PROJECT, BRANCH_1, PAGE, page, baseCommit, USER);

    Page result = pageStore.getPage(PROJECT, BRANCH_1, PAGE, true);
    assertNotNull(conflict);
    assertEquals(
        "a\nbbb\nc\nd\ne\nf\ng\nh\ni\nj\n",
        ((PageTextData) result.getData()).getText()); // $NON-NLS-1$
    assertEquals(
        "a\n<<<<<<< OURS\nbbb\n=======\nxxx\n>>>>>>> THEIRS\nc\nd\ne\nf\ng\nh\ni\nj\n",
        conflict.getText()); // $NON-NLS-1$

    assertClean(repo.r());
  }
コード例 #3
0
  @Test
  public void restorePageVersion() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);
    Page page = Page.fromText("old", "old"); // $NON-NLS-1$ //$NON-NLS-2$
    pageStore.savePage(PROJECT, BRANCH_1, PAGE, page, null, USER);
    page = Page.fromText("new", "new"); // $NON-NLS-1$ //$NON-NLS-2$
    pageStore.savePage(PROJECT, BRANCH_1, PAGE, page, null, USER);
    List<PageVersion> versions = pageStore.listPageVersions(PROJECT, BRANCH_1, PAGE);

    pageStore.restorePageVersion(PROJECT, BRANCH_1, PAGE, versions.get(1).getCommitName(), USER);
    Page result = pageStore.getPage(PROJECT, BRANCH_1, PAGE, true);
    assertEquals("old", ((PageTextData) result.getData()).getText()); // $NON-NLS-1$
    versions = pageStore.listPageVersions(PROJECT, BRANCH_1, PAGE);
    assertEquals(3, versions.size());

    assertClean(repo.r());
  }
コード例 #4
0
  @Test
  public void getPageViewRestrictionRole() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null));
    Page page = Page.fromText("title", "text"); // $NON-NLS-1$ //$NON-NLS-2$
    page.setViewRestrictionRole("viewRole"); // $NON-NLS-1$
    pageStore.savePage(PROJECT, BRANCH_1, "home/page", page, null, USER); // $NON-NLS-1$

    String role = pageStore.getViewRestrictionRole(PROJECT, BRANCH_1, "home/page"); // $NON-NLS-1$
    assertEquals(page.getViewRestrictionRole(), role);
  }
コード例 #5
0
  @Test
  public void savePageWithViewRestrictionRole() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);
    Page page = Page.fromText("title", "text"); // $NON-NLS-1$ //$NON-NLS-2$
    page.setViewRestrictionRole("viewRole"); // $NON-NLS-1$
    pageStore.savePage(PROJECT, BRANCH_1, "home/foo", page, null, USER); // $NON-NLS-1$
    Page result = pageStore.getPage(PROJECT, BRANCH_1, "home/foo", true); // $NON-NLS-1$
    assertEquals(page.getTitle(), result.getTitle());
    assertEquals(
        ((PageTextData) page.getData()).getText(), ((PageTextData) result.getData()).getText());
    assertEquals(page.getContentType(), result.getContentType());
    assertEquals(page.getViewRestrictionRole(), result.getViewRestrictionRole());
    assertEquals("home", result.getParentPagePath()); // $NON-NLS-1$

    assertClean(repo.r());
  }
コード例 #6
0
 private Page saveRandomPage(String branchName, String path) throws IOException {
   Page page = createRandomPage();
   pageStore.savePage(PROJECT, branchName, path, page, null, USER);
   return page;
 }