2014-01-23 1 views
0

SVN 모니터에서 작업 중이며 테스트를 위해 SVNRepository의 인스턴스를 모의해야합니다.JUnit 용 Java SVNKit 모의 테스트

나는 또 다른 질문 ( Mock svn instance for testing svnkit tests)

import static org.junit.Assert.*; 
import java.io.*; 
import org.apache.commons.io.FileUtils; 
import org.junit.*; 
import org.tmatesoft.svn.core.*; 

public class SVNTest { 

    private static final String path = "/tmp/testrepo"; 
    SVNURL tgtURL; 

    @Before 
    public void setUp() throws Exception { 
     SVNRepositoryFactoryImpl.setup(); 
     tgtURL = SVNRepositoryFactory.createLocalRepository(new File(path), true , false); 
    } 

    @After 
    public void tearDown() throws IOException { 
     FileUtils.deleteDirectory(new File(path)); 
    } 

    @Test 
    public void test() { 
     fail("Not yet implemented"); 
    } 

} 

여기에이 코드를 본 적이 그리고 그것은 마법처럼 작동하지만, 지금 ...을 REPO에 내가에서 찾고 있었어요 을 SVNLogEntries를 추가 할 필요가

API하지만 아직 유용한 것을 찾지 못했습니다. 어떤 아이디어?

답변

0

마지막으로 해결책을 찾았습니다. 테스트 레포 (test 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; 
    }