Пример #1
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());
  }
 private void assertCheckins(List<Checkin> checkins) {
   assertEquals(2, checkins.size());
   assertSingleCheckin(checkins.get(0));
   Checkin checkin2 = checkins.get(1);
   assertEquals("10150140239512040", checkin2.getId());
   assertEquals("533477039", checkin2.getFrom().getId());
   assertEquals("Raymie Walls", checkin2.getFrom().getName());
   assertEquals(1, checkin2.getTags().size());
   assertEquals("738140579", checkin2.getTags().get(0).getId());
   assertEquals("Craig Walls", checkin2.getTags().get(0).getName());
   assertEquals("With my favorite people! ;-)", checkin2.getMessage());
   Page place2 = checkin2.getPlace();
   assertEquals("150366431753543", place2.getId());
   assertEquals("Somewhere", place2.getName());
   assertEquals(35.0231428, place2.getLocation().getLatitude(), 0.0001);
   assertEquals(-98.740305416667, place2.getLocation().getLongitude(), 0.0001);
   assertEquals("6628568379", checkin2.getApplication().getId());
   assertEquals("Facebook for iPhone", checkin2.getApplication().getName());
   assertEquals(toDate("2011-02-11T20:59:41+0000"), checkin2.getCreatedTime());
   assertEquals(2, checkin2.getLikes().size());
   assertEquals("1524405653", checkin2.getLikes().get(0).getId());
   assertEquals("Samuel Hugh Parsons", checkin2.getLikes().get(0).getName());
   assertEquals("1580082219", checkin2.getLikes().get(1).getId());
   assertEquals("Kris Len Nicholson", checkin2.getLikes().get(1).getName());
   assertEquals(1, checkin2.getComments().size());
   assertEquals("10150140239512040_15204657", checkin2.getComments().get(0).getId());
   assertEquals("100000094813002", checkin2.getComments().get(0).getFrom().getId());
   assertEquals("Otis Nelson", checkin2.getComments().get(0).getFrom().getName());
   assertEquals("You are not with me!!!!", checkin2.getComments().get(0).getMessage());
   assertEquals(
       toDate("2011-02-11T21:31:31+0000"), checkin2.getComments().get(0).getCreatedTime());
 }
Пример #3
0
 @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());
 }
Пример #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 deleteAttachment() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);
    saveRandomPage(BRANCH_1, PAGE);
    Page attachment =
        Page.fromData(new byte[] {1, 2, 3}, "application/octet-stream"); // $NON-NLS-1$
    pageStore.saveAttachment(PROJECT, BRANCH_1, PAGE, "test.dat", attachment, USER); // $NON-NLS-1$
    assertFalse(pageStore.listPageAttachments(PROJECT, BRANCH_1, PAGE).isEmpty());
    File pageFile =
        new File(
            new File(new File(RepositoryUtil.getWorkingDir(repo.r()), "attachments"), PAGE),
            "test.dat.page"); //$NON-NLS-1$ //$NON-NLS-2$
    File metaFile =
        new File(
            new File(new File(RepositoryUtil.getWorkingDir(repo.r()), "attachments"), PAGE),
            "test.dat.meta"); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue(pageFile.exists());
    assertTrue(metaFile.exists());

    pageStore.deleteAttachment(PROJECT, BRANCH_1, PAGE, "test.dat", USER); // $NON-NLS-1$
    assertTrue(pageStore.listPageAttachments(PROJECT, BRANCH_1, PAGE).isEmpty());
    assertFalse(pageFile.exists());
    assertFalse(metaFile.exists());

    assertClean(repo.r());
  }
Пример #6
0
  @Test
  public void listPageAttachments() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null));
    saveRandomPage(BRANCH_1, "foo/bar/baz"); // $NON-NLS-1$
    saveRandomPage(BRANCH_1, "foo/bar/baz/qux"); // $NON-NLS-1$
    Page attachment =
        Page.fromData(new byte[] {1, 2, 3}, "application/octet-stream"); // $NON-NLS-1$
    pageStore.saveAttachment(
        PROJECT,
        BRANCH_1,
        "foo/bar/baz",
        "test.dat",
        attachment,
        USER); //$NON-NLS-1$ //$NON-NLS-2$
    pageStore.saveAttachment(
        PROJECT,
        BRANCH_1,
        "foo/bar/baz/qux",
        "test2.dat",
        attachment,
        USER); //$NON-NLS-1$ //$NON-NLS-2$

    List<String> attachments =
        pageStore.listPageAttachments(PROJECT, BRANCH_1, "foo/bar/baz"); // $NON-NLS-1$
    assertEquals(1, attachments.size());
    assertTrue(attachments.contains("test.dat")); // $NON-NLS-1$
    attachments =
        pageStore.listPageAttachments(PROJECT, BRANCH_1, "foo/bar/baz/qux"); // $NON-NLS-1$
    assertEquals(1, attachments.size());
    assertTrue(attachments.contains("test2.dat")); // $NON-NLS-1$
  }
Пример #7
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()));
  }
Пример #8
0
  @Test
  public void saveAndGetAttachment() throws IOException, GitAPIException {
    register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
    ILockedRepository repo =
        globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null);
    register(repo);
    saveRandomPage(BRANCH_1, "foo/bar/baz"); // $NON-NLS-1$
    Page attachment =
        Page.fromData(new byte[] {1, 2, 3}, "application/octet-stream"); // $NON-NLS-1$
    pageStore.saveAttachment(
        PROJECT,
        BRANCH_1,
        "foo/bar/baz",
        "test.dat",
        attachment,
        USER); //$NON-NLS-1$ //$NON-NLS-2$

    Page result =
        pageStore.getAttachment(
            PROJECT, BRANCH_1, "foo/bar/baz", "test.dat"); // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(ArrayUtils.isEquals(attachment.getData(), result.getData()));
    assertEquals(attachment.getContentType(), result.getContentType());

    assertClean(repo.r());
  }
 private void assertSingleCheckin(Checkin checkin) {
   assertEquals("10150431253050580", checkin.getId());
   assertEquals("738140579", checkin.getFrom().getId());
   assertEquals("Craig Walls", checkin.getFrom().getName());
   Page place1 = checkin.getPlace();
   assertEquals("117372064948189", place1.getId());
   assertEquals("Freebirds World Burrito", place1.getName());
   assertEquals("238 W Campbell Rd", place1.getLocation().getStreet());
   assertEquals("Richardson", place1.getLocation().getCity());
   assertEquals("TX", place1.getLocation().getState());
   assertEquals("United States", place1.getLocation().getCountry());
   assertEquals("75080-3512", place1.getLocation().getZip());
   assertEquals(32.975537, place1.getLocation().getLatitude(), 0.0001);
   assertEquals(-96.722944, place1.getLocation().getLongitude(), 0.0001);
   assertEquals("6628568379", checkin.getApplication().getId());
   assertEquals("Facebook for iPhone", checkin.getApplication().getName());
   assertEquals(toDate("2011-03-13T01:00:49+0000"), checkin.getCreatedTime());
 }
Пример #10
0
  @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());
  }
Пример #11
0
  @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());
  }
Пример #12
0
 private Page saveRandomAttachment(String branchName, String pagePath, String fileName)
     throws IOException {
   try {
     byte[] data = UUID.randomUUID().toString().getBytes("UTF-8"); // $NON-NLS-1$
     Page attachment = Page.fromData(data, "application/octet-stream"); // $NON-NLS-1$
     pageStore.saveAttachment(PROJECT, branchName, pagePath, fileName, attachment, USER);
     return attachment;
   } catch (UnsupportedEncodingException e) {
     throw new RuntimeException(e);
   }
 }
Пример #13
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());
  }
Пример #14
0
 @Test
 public void getAttachmentMetadata() throws IOException, GitAPIException {
   register(globalRepoManager.createProjectCentralRepository(PROJECT, USER));
   register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null));
   saveRandomPage(BRANCH_1, PAGE);
   Page attachment = Page.fromData(new byte[] {1, 2, 3}, "image/png"); // $NON-NLS-1$
   pageStore.saveAttachment(PROJECT, BRANCH_1, PAGE, "test.png", attachment, USER); // $NON-NLS-1$
   PageMetadata metadata =
       pageStore.getAttachmentMetadata(PROJECT, BRANCH_1, PAGE, "test.png"); // $NON-NLS-1$
   assertEquals(USER.getLoginName(), metadata.getLastEditedBy());
   assertSecondsAgo(metadata.getLastEdited(), 5);
 }
Пример #15
0
  @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());
  }
Пример #16
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());
  }