@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()); }
@Test public void getPageWithoutData() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null)); saveRandomPage(BRANCH_1, "foo"); // $NON-NLS-1$ Page result = pageStore.getPage(PROJECT, BRANCH_1, "foo", false); // $NON-NLS-1$ assertNull(result.getData()); }
@Test public void getPageForCommit() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null)); Page oldPage = saveRandomPage(BRANCH_1, "home"); // $NON-NLS-1$ String oldCommit = pageStore.getPageMetadata(PROJECT, BRANCH_1, "home").getCommit(); // $NON-NLS-1$ Page newPage = saveRandomPage(BRANCH_1, "home"); // $NON-NLS-1$ String newCommit = pageStore.getPageMetadata(PROJECT, BRANCH_1, "home").getCommit(); // $NON-NLS-1$ assertFalse(oldPage.getData().equals(newPage.getData())); assertFalse(newCommit.equals(oldCommit)); Page result = pageStore.getPage(PROJECT, BRANCH_1, "home", oldCommit, true); // $NON-NLS-1$ assertEquals(oldPage.getData(), result.getData()); result = pageStore.getPage(PROJECT, BRANCH_1, "home", newCommit, true); // $NON-NLS-1$ assertEquals(newPage.getData(), result.getData()); }
@Test public void saveAndGetPage() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); ILockedRepository repo = globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null); register(repo); Page page = saveRandomPage(BRANCH_1, "home/foo"); // $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("home", result.getParentPagePath()); // $NON-NLS-1$ assertNull(result.getViewRestrictionRole()); verify(eventBus).post(new PageChangedEvent(PROJECT, BRANCH_1, "home/foo")); // $NON-NLS-1$ assertClean(repo.r()); }
@Test public void relocatePage() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); ILockedRepository repo = globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null); register(repo); saveRandomPage(BRANCH_1, "home"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/foo"); // $NON-NLS-1$ Page page = saveRandomPage(BRANCH_1, "home/foo/bar"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/foo/bar/quuux"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/foo/quux"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/baz"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/baz/bar"); // $NON-NLS-1$ saveRandomPage(BRANCH_1, "home/baz/qux"); // $NON-NLS-1$ Page attachment = saveRandomAttachment(BRANCH_1, "home/foo/bar", "test.txt"); // $NON-NLS-1$ //$NON-NLS-2$ saveRandomAttachment(BRANCH_1, "home/baz/bar", "test.txt"); // $NON-NLS-1$ //$NON-NLS-2$ pageStore.relocatePage( PROJECT, BRANCH_1, "home/foo/bar", "home/baz", USER); // $NON-NLS-1$ //$NON-NLS-2$ assertEquals( Sets.newHashSet("home/foo/quux"), // $NON-NLS-1$ Sets.newHashSet( pageStore.listChildPagePaths(PROJECT, BRANCH_1, "home/foo"))); // $NON-NLS-1$ assertEquals( Sets.newHashSet("home/baz/bar", "home/baz/qux"), // $NON-NLS-1$ //$NON-NLS-2$ Sets.newHashSet( pageStore.listChildPagePaths(PROJECT, BRANCH_1, "home/baz"))); // $NON-NLS-1$ assertEquals( Sets.newHashSet("home/baz/bar/quuux"), // $NON-NLS-1$ Sets.newHashSet( pageStore.listChildPagePaths(PROJECT, BRANCH_1, "home/baz/bar"))); // $NON-NLS-1$ assertEquals( page.getData(), pageStore.getPage(PROJECT, BRANCH_1, "home/baz/bar", true).getData()); // $NON-NLS-1$ assertEquals( attachment.getData(), pageStore .getAttachment(PROJECT, BRANCH_1, "home/baz/bar", "test.txt") .getData()); //$NON-NLS-1$ //$NON-NLS-2$ assertClean(repo.r()); }
@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()); }
@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()); }