Example #1
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());
  }
Example #2
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$
  }