@Test
  public void simple_replace() throws ParseException, NoSuchAlgorithmException {
    final String newFileContent = "No content.\n";

    Predicate<Node> predicate =
        n ->
            n.getRevision().get().getNumber() == 1
                && n.getHeaders().get(NodeHeader.PATH).equals("README.txt");
    FileContentReplace fileContentReplace =
        new FileContentReplace(predicate, n -> new ContentChunkImpl(newFileContent.getBytes()));

    RepositoryInMemory inMemory = new RepositoryInMemory();
    fileContentReplace.continueTo(inMemory);

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

    assertThat(inMemory.getRepo().getRevisions().size(), is(2));
    Revision r1 = inMemory.getRepo().getRevisions().get(1);
    assertThat(r1.getNodes().size(), is(1));
    Node node = r1.getNodes().get(0);
    assertThat(new String(node.getContent().get(0).getContent()), is(equalTo(newFileContent)));
    assertThat(node.get(NodeHeader.TEXT_CONTENT_LENGTH), is(equalTo("12")));
    assertThat(node.get(NodeHeader.CONTENT_LENGTH), is(equalTo("22")));
    assertThat(node.get(NodeHeader.MD5), is(equalTo(new Md5().hash(newFileContent.getBytes()))));
    assertThat(node.get(NodeHeader.SHA1), is(equalTo(new Sha1().hash(newFileContent.getBytes()))));
  }
示例#2
0
  @Test
  public void node_property_should_be_changed_and_dump_should_be_unchanged() throws ParseException {
    RepositoryConsumer propChange =
        new PropertyChange(
            "svn:mergeinfo"::equals, new MergeInfoReplaceRevision("/branches/mybranch", 2, 1));

    RepositoryInMemory inMemoryDump = new RepositoryInMemory();
    propChange.continueTo(inMemoryDump);

    final InputStream s =
        Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream("dumps/simple_branch_and_merge.dump");

    SvnDumpParser.consume(s, propChange);

    Repository dump = inMemoryDump.getRepo();

    assertThat(dump.getRevisions().size(), is(6));
    Revision r4 = dump.getRevisions().get(4);
    assertThat(r4.getNodes().size(), is(2));
    assertThat(
        r4.getNodes().get(0).getProperties().get(Property.MERGEINFO), is("/branches/mybranch:1-3"));
  }