⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basictests.java

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * @copyright * ==================================================================== * Copyright (c) 2003-2004 CollabNet.  All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution.  The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals.  For exact contribution history, see the revision * history and logs, available at http://subversion.tigris.org/. * ==================================================================== * @endcopyright */package org.tigris.subversion.javahl.tests;import junit.framework.TestSuite;import junit.framework.TestResult;import org.tigris.subversion.javahl.*;import java.io.File;import java.io.FileOutputStream;import java.io.PrintWriter;import java.io.ByteArrayOutputStream;import java.util.Arrays;/** * Tests the basic functionality of javahl binding (inspired by the * tests in subversion/tests/cmdline/basic_tests.py). */public class BasicTests extends SVNTests{    /**     * base name of all our tests     */    public final static String testName = "basic_test";    /**     * Initialize the testBaseName and the testCounter, if this is the first     * test of this class     */    public BasicTests()    {        if(!testName.equals(testBaseName))        {            testCounter = 0;            testBaseName = testName;        }    }    /**     * Build a test suite of all tests of this class     * @return the new test suite     */    public static TestSuite suite() {        return new TestSuite(BasicTests.class);    }    /**     * Main method to run tests standalone     * @param args command line arguments to specify root directory and root     * url     */    public static void main(String[] args) {        processArgs(args);        TestResult tr = junit.textui.TestRunner.run(suite());        if (tr.errorCount() != 0 || tr.failureCount() != 0) {            System.exit(1);        }        System.exit(0);    }    /**     * Test SVNClient.getVersion().     * @throws Throwable     */    public void testVersion() throws Throwable    {        try        {            Version version = client.getVersion();            String versionString = version.toString();            if (versionString == null || versionString.trim().length() == 0)            {                throw new Exception("Version string empty");            }        }        catch (Exception e)        {            fail("Version should always be available unless the " +                 "native libraries failed to initialize: " + e);        }    }    /**     * Tests Subversion path validation.     */    public void testPathValidation() throws Throwable    {        // Rather than segfaulting, JavaHL considers null an invalid path.        assertFalse("Path validation produced false-positive for null path",                    Path.isValid(null));        String path = "valid-path";        assertTrue("Validation check of valid path '" + path +                   "' should succeed", Path.isValid(path));        // File names cannot contain control characters.        path = "invalid-\u0001-path";        assertFalse("Validation check of invalid path '" + path +                    "' (which contains control characters) should fail",                    Path.isValid(path));    }    /**     * test the basic SVNClient.checkout functionality     * @throws Throwable     */    public void testBasicCheckout() throws Throwable    {        // build the test setup        OneTest thisTest = new OneTest();        try        {            // obstructed checkout must fail            client.checkout(thisTest.getUrl() + "/A", thisTest.getWCPath(),                    null, true);            fail("missing exception");        }        catch (ClientException expected)        {        }        // modify file A/mu        File mu = new File(thisTest.getWorkingCopy(), "A/mu");        PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));        muPW.print("appended mu text");        muPW.close();        thisTest.getWc().setItemTextStatus("A/mu", Status.Kind.modified);        // delete A/B/lambda without svn        File lambda = new File(thisTest.getWorkingCopy(), "A/B/lambda");        lambda.delete();        thisTest.getWc().setItemTextStatus("A/B/lambda", Status.Kind.missing);        // remove A/D/G        client.remove(new String[]{thisTest.getWCPath() + "/A/D/G"}, null,                false);        thisTest.getWc().setItemTextStatus("A/D/G", Status.Kind.deleted);        thisTest.getWc().setItemTextStatus("A/D/G/pi", Status.Kind.deleted);        thisTest.getWc().setItemTextStatus("A/D/G/rho", Status.Kind.deleted);        thisTest.getWc().setItemTextStatus("A/D/G/tau", Status.Kind.deleted);        // check the status of the working copy        thisTest.checkStatus();        // recheckout the working copy        client.checkout(thisTest.getUrl(), thisTest.getWCPath(), null, true);        // deleted file should reapear        thisTest.getWc().setItemTextStatus("A/B/lambda", Status.Kind.normal);        // check the status of the working copy        thisTest.checkStatus();    }    /**     * test the basic SVNClient.status functionality     * @throws Throwable     */    public void testBasicStatus() throws Throwable    {        // build the test setup        OneTest thisTest = new OneTest();        // check the status of the working copy        thisTest.checkStatus();    }    /**     * test the basic SVNClient.commit functionality     * @throws Throwable     */    public void testBasicCommit() throws Throwable    {        // build the test setup        OneTest thisTest = new OneTest();        // modify file A/mu        File mu = new File(thisTest.getWorkingCopy(), "A/mu");        PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));        muPW.print("appended mu text");        muPW.close();        thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);        thisTest.getWc().setItemContent("A/mu",                thisTest.getWc().getItemContent("A/mu") + "appended mu text");        addExpectedCommitItem(thisTest.getWCPath(),                thisTest.getUrl(), "A/mu",NodeKind.file,                CommitItemStateFlags.TextMods);        // modify file A/D/G/rho        File rho = new File(thisTest.getWorkingCopy(), "A/D/G/rho");        PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho, true));        rhoPW.print("new appended text for rho");        rhoPW.close();        thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);        thisTest.getWc().setItemContent("A/D/G/rho",                thisTest.getWc().getItemContent("A/D/G/rho")                + "new appended text for rho");        addExpectedCommitItem(thisTest.getWCPath(),                thisTest.getUrl(), "A/D/G/rho",NodeKind.file,                CommitItemStateFlags.TextMods);        // commit the changes        assertEquals("wrong revision number from commit",                client.commit(new String[]{thisTest.getWCPath()}, "log msg",                        true), 2);        // check the status of the working copy        thisTest.checkStatus();    }    /**     * test the basic SVNClient.update functionality     * @throws Throwable     */    public void testBasicUpdate() throws Throwable    {        // build the test setup. Used for the changes        OneTest thisTest = new OneTest();        // build the backup test setup. That is the one that will be updated        OneTest backupTest = thisTest.copy(".backup");        // modify A/mu        File mu = new File(thisTest.getWorkingCopy(), "A/mu");        PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));        muPW.print("appended mu text");        muPW.close();        thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);        thisTest.getWc().setItemContent("A/mu",                thisTest.getWc().getItemContent("A/mu") + "appended mu text");        addExpectedCommitItem(thisTest.getWCPath(),                thisTest.getUrl(), "A/mu",NodeKind.file,                CommitItemStateFlags.TextMods);        // modify A/D/G/rho        File rho = new File(thisTest.getWorkingCopy(), "A/D/G/rho");        PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho, true));        rhoPW.print("new appended text for rho");        rhoPW.close();        thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);        thisTest.getWc().setItemContent("A/D/G/rho",                thisTest.getWc().getItemContent("A/D/G/rho")                + "new appended text for rho");        addExpectedCommitItem(thisTest.getWCPath(),                thisTest.getUrl(), "A/D/G/rho",NodeKind.file,                CommitItemStateFlags.TextMods);        // commit the changes        assertEquals("wrong revision number from commit",                client.commit(new String[]{thisTest.getWCPath()}, "log msg",                        true), 2);        // check the status of the working copy        thisTest.checkStatus();        // update the backup test        assertEquals("wrong revision number from update",                client.update(backupTest.getWCPath(), null, true), 2);        // set the expected working copy layout for the backup test        backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);        backupTest.getWc().setItemContent("A/mu",                backupTest.getWc().getItemContent("A/mu") + "appended mu text");        backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);        backupTest.getWc().setItemContent("A/D/G/rho",                backupTest.getWc().getItemContent("A/D/G/rho")                + "new appended text for rho");        // check the status of the working copy of the backup test        backupTest.checkStatus();    }    /**     * test basic SVNClient.mkdir with url parameter functionality     * @throws Throwable     */    public void testBasicMkdirUrl() throws Throwable    {        // build the test setup.        OneTest thisTest = new OneTest();        // create Y and Y/Z directories in the repository        addExpectedCommitItem(null, thisTest.getUrl(), "Y", NodeKind.none,                CommitItemStateFlags.Add);        addExpectedCommitItem(null, thisTest.getUrl(), "Y/Z", NodeKind.none,                CommitItemStateFlags.Add);        client.mkdir(new String[]{thisTest.getUrl() + "/Y",                                  thisTest.getUrl() + "/Y/Z"}, "log_msg");        // add the new directories the expected working copy layout        thisTest.getWc().addItem("Y", null);        thisTest.getWc().setItemWorkingCopyRevision("Y", 2);        thisTest.getWc().addItem("Y/Z", null);        thisTest.getWc().setItemWorkingCopyRevision("Y/Z", 2);        // update the working copy        assertEquals("wrong revision from update",                client.update(thisTest.getWCPath(), null, true), 2);        // check the status of the working copy        thisTest.checkStatus();    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -