Exemplo n.º 1
0
  @Test(expected = NullPointerException.class)
  public void does_not_allow_null_chunk() throws ParseException {
    Predicate<Node> predicate = n -> true;
    FileContentReplace fileContentReplace = new FileContentReplace(predicate, n -> null);

    ByteArrayOutputStream newDump = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDump);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(TestUtil.openResource("dumps/add_file.dump"), fileContentReplace);
  }
Exemplo n.º 2
0
  @Test
  public void if_no_match_then_no_change() throws ParseException, IOException {
    Predicate<Node> predicate = n -> false;
    FileContentReplace fileContentReplace = new FileContentReplace(predicate, n -> null);

    ByteArrayOutputStream newDump = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDump);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(TestUtil.openResource("dumps/add_file.dump"), fileContentReplace);

    TestUtil.assertEqualStreams(
        TestUtil.openResource("dumps/add_file.dump"),
        new ByteArrayInputStream(newDump.toByteArray()));
  }
Exemplo n.º 3
0
  @Test
  public void tracks_copied_file_across_one_copy() throws ParseException, IOException {
    Predicate<Node> nodeMatcher =
        n -> n.getRevision().get().getNumber() == 1 && "README.txt".equals(n.get(NodeHeader.PATH));
    FileContentReplace fileContentReplace =
        new FileContentReplace(nodeMatcher, n -> new ContentChunkImpl("new content\n".getBytes()));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(TestUtil.openResource("dumps/svn_copy_file.dump"), fileContentReplace);

    TestUtil.assertEqualStreams(
        TestUtil.openResource("dumps/svn_copy_file_new_content.dump"),
        new ByteArrayInputStream(newDumpStream.toByteArray()));
  }
Exemplo n.º 4
0
  @Test
  public void handle_multiple_matches_across_simple_copies() throws ParseException, IOException {
    Predicate<Node> nodeMatcher = n -> n.get(NodeHeader.PATH).endsWith("README.txt");
    FileContentReplace fileContentReplace =
        new FileContentReplace(
            nodeMatcher, FileContentReplace.chunkFromString("this text is different\n"));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(TestUtil.openResource("dumps/simple_copy.dump"), fileContentReplace);

    TestUtil.assertEqualStreams(
        TestUtil.openResource("dumps/simple_copy2.dump"),
        new ByteArrayInputStream(newDumpStream.toByteArray()));
  }
Exemplo n.º 5
0
  @Test
  public void tracks_copied_file_across_many_copies() throws ParseException, IOException {
    FileContentReplace fileContentReplace =
        FileContentReplace.createFCR(
            1, "add", "README.txt", n -> new ContentChunkImpl("new content\n".getBytes()));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(
        TestUtil.openResource("dumps/svn_copy_file_many_times.dump"), fileContentReplace);

    TestUtil.assertEqualStreams(
        TestUtil.openResource("dumps/svn_copy_file_many_times_new_content.dump"),
        new ByteArrayInputStream(newDumpStream.toByteArray()));
  }
Exemplo n.º 6
0
  @Test
  public void does_not_change_a_change_and_copied_file() throws ParseException, IOException {
    Predicate<Node> nodeMatcher = n -> false;
    FileContentReplace fileContentReplace =
        new FileContentReplace(
            nodeMatcher, n -> new ContentChunkImpl("i replaced the content\n".getBytes()));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(
        TestUtil.openResource("dumps/add_and_change_copy_delete.dump"), fileContentReplace);

    TestUtil.assertEqualStreams(
        TestUtil.openResource("dumps/add_and_change_copy_delete.dump"),
        new ByteArrayInputStream(newDumpStream.toByteArray()));
  }
Exemplo n.º 7
0
  @Test
  public void tracks_node_in_directory_external_tok() throws ParseException, IOException {
    FileContentReplace fileContentReplace =
        FileContentReplace.createFCR(
            2,
            "add",
            "dir1/dir2/dir3/README.txt",
            n -> new ContentChunkImpl("new content\n".getBytes()));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(
        TestUtil.openResource("dumps/add_file_in_directory.before.dump"), fileContentReplace);

    InputStream dumpWithNewContent =
        TestUtil.openResource("dumps/add_file_in_directory.after.dump");
    InputStream dumpCreatedByFileContentReplace =
        new ByteArrayInputStream(newDumpStream.toByteArray());
    TestUtil.assertEqualStreams(dumpWithNewContent, dumpCreatedByFileContentReplace);
  }
Exemplo n.º 8
0
  @Test
  public void tracks_node_in_directory() throws ParseException, IOException {
    Predicate<Node> nodeMatcher =
        n ->
            n.getRevision().get().getNumber() == 2
                && "dir1/dir2/dir3/README.txt".equals(n.get(NodeHeader.PATH));
    FileContentReplace fileContentReplace =
        new FileContentReplace(nodeMatcher, n -> new ContentChunkImpl("new content\n".getBytes()));

    ByteArrayOutputStream newDumpStream = new ByteArrayOutputStream();
    RepositoryWriter svnDumpWriter = new SvnDumpWriter();
    svnDumpWriter.writeTo(newDumpStream);

    fileContentReplace.continueTo(svnDumpWriter);

    SvnDumpParser.consume(
        TestUtil.openResource("dumps/add_file_in_directory.before.dump"), fileContentReplace);

    InputStream dumpWithNewContent =
        TestUtil.openResource("dumps/add_file_in_directory.after.dump");
    InputStream dumpCreatedByFileContentReplace =
        new ByteArrayInputStream(newDumpStream.toByteArray());
    TestUtil.assertEqualStreams(dumpWithNewContent, dumpCreatedByFileContentReplace);
  }