Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于JUnit测试的Java SVNKit模拟_Java_Unit Testing_Junit_Mocking_Svnkit - Fatal编程技术网

用于JUnit测试的Java SVNKit模拟

用于JUnit测试的Java SVNKit模拟,java,unit-testing,junit,mocking,svnkit,Java,Unit Testing,Junit,Mocking,Svnkit,我正在开发一个SVN监视器,我需要模拟一个SVNRepository实例进行测试 我在另一个问题中看到了这段代码 这就像魅力一样,但现在我需要在回购协议中加入斯文洛绅士。。。 我一直在看API,但还没有发现任何有用的东西。有什么想法吗?我终于找到了解决办法。您必须对测试repo提交一些更改,这是我为此开发和使用的方法 private static void fill_repo(SVNRepository repo) throws SVNException { final

我正在开发一个SVN监视器,我需要模拟一个SVNRepository实例进行测试

我在另一个问题中看到了这段代码

这就像魅力一样,但现在我需要在回购协议中加入斯文洛绅士。。。
我一直在看API,但还没有发现任何有用的东西。有什么想法吗?

我终于找到了解决办法。您必须对测试repo提交一些更改,这是我为此开发和使用的方法

    private static void fill_repo(SVNRepository repo) throws SVNException {
        final SVNURL location = repo.getLocation();
        final SVNURL trunkUrl = SVNURL.parseURIEncoded(location + "/trunk");
        final SVNURL branchesUrl = SVNURL.parseURIEncoded(location + "/branches");
        SVNCommitInfo svnCommitInfo = makeDirectory(new SVNURL[]{trunkUrl, branchesUrl}, "commiting the directory");
        createNewFile("trunk", "new_file.txt", repo, "user_1", "");
        createNewFile("trunk", "test_file.txt", repo, "user_1", "");
        createNewFile("trunk", "another_file.txt", repo, "user_1", "");

        createBranchFromTrunk("Test_Branch", repo);
        createBranchFromTrunk("Second_Branch", repo);

        addContentToFile(repo, "branches/Test_Branch/test_file.txt", "Test Text");

    }


    private static void createNewFile(String dir, String filename, SVNRepository repo, String username, String password) throws SVNException {

        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
        repo.setAuthenticationManager(authManager);

        ISVNEditor editor = repo.getCommitEditor("creating a new file", null /*locks*/, true /*keepLocks*/, null /*mediator*/);
        editor.openRoot(-1);
        editor.openDir(dir, -1);
        editor.addFile(dir + "/" + filename, null, -1);
        editor.closeFile(dir + "/" + filename, "checksum");
        editor.closeEdit();
    }


    private static void createBranchFromTrunk(String branchName, SVNRepository repo) throws SVNException {

        final SVNClientManager svnClientManager = SVNClientManager.newInstance();
        final SVNCopyClient copyClient = svnClientManager.getCopyClient();
        final SVNURL location = repo.getLocation();
        final SVNURL srcURL = SVNURL.parseURIEncoded(location + "/trunk");
        final SVNURL dstURL = SVNURL.parseURIEncoded(location + "/branches/" + branchName);

        final SVNCopySource source = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcURL);
        copyClient.doCopy(new SVNCopySource[]{source}, dstURL, false, false, true, "Create new Branch", null);
    }


    private static SVNCommitInfo addContentToFile(SVNRepository repos, String pathToFile, String content) throws SVNException {
        InputStream newContents = new ByteArrayInputStream(content.getBytes());
        ISVNEditor editor = repos.getCommitEditor("", null);
        editor.openRoot(-1);
        editor.openFile(pathToFile, -1);
        editor.applyTextDelta(pathToFile, null);
        String checksum = new SVNDeltaGenerator().sendDelta(pathToFile, newContents, editor, true);
        editor.closeDir();
        SVNCommitInfo info = editor.closeEdit();
        return info;
    }
    private static void fill_repo(SVNRepository repo) throws SVNException {
        final SVNURL location = repo.getLocation();
        final SVNURL trunkUrl = SVNURL.parseURIEncoded(location + "/trunk");
        final SVNURL branchesUrl = SVNURL.parseURIEncoded(location + "/branches");
        SVNCommitInfo svnCommitInfo = makeDirectory(new SVNURL[]{trunkUrl, branchesUrl}, "commiting the directory");
        createNewFile("trunk", "new_file.txt", repo, "user_1", "");
        createNewFile("trunk", "test_file.txt", repo, "user_1", "");
        createNewFile("trunk", "another_file.txt", repo, "user_1", "");

        createBranchFromTrunk("Test_Branch", repo);
        createBranchFromTrunk("Second_Branch", repo);

        addContentToFile(repo, "branches/Test_Branch/test_file.txt", "Test Text");

    }


    private static void createNewFile(String dir, String filename, SVNRepository repo, String username, String password) throws SVNException {

        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
        repo.setAuthenticationManager(authManager);

        ISVNEditor editor = repo.getCommitEditor("creating a new file", null /*locks*/, true /*keepLocks*/, null /*mediator*/);
        editor.openRoot(-1);
        editor.openDir(dir, -1);
        editor.addFile(dir + "/" + filename, null, -1);
        editor.closeFile(dir + "/" + filename, "checksum");
        editor.closeEdit();
    }


    private static void createBranchFromTrunk(String branchName, SVNRepository repo) throws SVNException {

        final SVNClientManager svnClientManager = SVNClientManager.newInstance();
        final SVNCopyClient copyClient = svnClientManager.getCopyClient();
        final SVNURL location = repo.getLocation();
        final SVNURL srcURL = SVNURL.parseURIEncoded(location + "/trunk");
        final SVNURL dstURL = SVNURL.parseURIEncoded(location + "/branches/" + branchName);

        final SVNCopySource source = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcURL);
        copyClient.doCopy(new SVNCopySource[]{source}, dstURL, false, false, true, "Create new Branch", null);
    }


    private static SVNCommitInfo addContentToFile(SVNRepository repos, String pathToFile, String content) throws SVNException {
        InputStream newContents = new ByteArrayInputStream(content.getBytes());
        ISVNEditor editor = repos.getCommitEditor("", null);
        editor.openRoot(-1);
        editor.openFile(pathToFile, -1);
        editor.applyTextDelta(pathToFile, null);
        String checksum = new SVNDeltaGenerator().sendDelta(pathToFile, newContents, editor, true);
        editor.closeDir();
        SVNCommitInfo info = editor.closeEdit();
        return info;
    }