basictests.java

来自「linux subdivision ying gai ke yi le ba」· Java 代码 · 共 869 行 · 第 1/3 页

JAVA
869
字号
package org.tigris.subversion.test;

/**
 * @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
 */

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.tigris.subversion.util.NativeResources;

public class BasicTests extends SVNTests
{
    static
    {
        testCounter = 0;
    }

    /**
     * @param name Method name to invoke.
     */
    public BasicTests(String name)
    {
        super(name);
    }

    public static Test suite()
    {
        return new TestSuite(BasicTests.class);
    }

    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    public void testInitialization()
    {
        System.out.println("Initializing SVN native resources...");
        NativeResources.getInstance().initialize();
        System.out.println("Success!");
    }

    /*
    public void testBasicCheckout() throws Throwable
    {
        OneTest thisTest = new OneTest();
        try
        {
            client.checkout(thisTest.getURL() + "/A",
                            thisTest.getWorkingCopy().getAbsolutePath(),
                            null, true);
            fail("missing exception");
        }
        catch (ClientException e)
        {
        }
        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);
        File lambda = new File(thisTest.getWorkingCopy(), "A/B/lambda");
        lambda.delete();
        thisTest.getWc().setItemTextStatus("A/B/lambda", Status.Kind.missing);
        client.remove(new String[] {thisTest.getWorkingCopy().getAbsolutePath()
                                    + "/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);
        thisTest.checkStatus();
        client.checkout(thisTest.getURL(),
                        thisTest.getWorkingCopy().getAbsolutePath(),
                        null, true);
        thisTest.getWc().setItemTextStatus("A/B/lambda", Status.Kind.normal);
        thisTest.checkStatus();
    }

    public void testBasicStatus() throws Throwable
    {
        OneTest thisTest = new OneTest();
        thisTest.checkStatus();
    }

    public void testBasicCommit() throws Throwable
    {
        OneTest thisTest = new OneTest();
        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");
        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");
        assertEquals("wrong revision number from commit", client.commit(new String[]{thisTest.getWorkingCopy().getAbsolutePath()}, "log msg", true), 2);
        thisTest.checkStatus();
    }

    public void testBasicUpdate() throws Throwable
    {
        OneTest thisTest = new OneTest();
        OneTest backupTest = thisTest.copy(".backup");
        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");
        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");
        assertEquals("wrong revision number from commit",
                     client.commit(new String[] {thisTest.getWorkingCopy().getAbsolutePath()},
                     "log msg", true), 2);
        thisTest.checkStatus();
        assertEquals("wrong revision number from update",
                     client.update(backupTest.getWorkingCopy().getAbsolutePath(),
                                   null, true), 2);
        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");
        backupTest.checkStatus();
    }

    public void testBasicMkdirUrl() throws Throwable
    {
        OneTest thisTest = new OneTest();
        String url = thisTest.getURL();
        client.mkdir(new String[] { url + "/Y", url + "/Y/Z" }, "log_msg");
        thisTest.getWc().addItem("Y", null);
        thisTest.getWc().setItemWorkingCopyRevision("Y", 2);
        thisTest.getWc().addItem("Y/Z", null);
        thisTest.getWc().setItemWorkingCopyRevision("Y/Z", 2);
        assertEquals("wrong revision from update",
                     client.update(thisTest.getWorkingCopy().getAbsolutePath(),
                                   null, true), 2);
        thisTest.checkStatus();
    }

    public void testBasicMergingUpdate() throws Throwable
    {
        OneTest thisTest = new OneTest();
        File mu = new File(thisTest.getWorkingCopy(), "A/mu");
        PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));
        String muContent = thisTest.getWc().getItemContent("A/mu");
        File rho = new File(thisTest.getWorkingCopy(), "A/D/G/rho");
        PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho, true));
        String rhoContent = thisTest.getWc().getItemContent("A/D/G/rho");
        for (int i = 2; i < 11; i++)
        {
            muPW.print("\nThis is line " + i + " in mu");
            muContent = muContent + "\nThis is line " + i + " in mu";
            rhoPW.print("\nThis is line " + i + " in rho");
            rhoContent = rhoContent + "\nThis is line " + i + " in rho";
        }
        muPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
        thisTest.getWc().setItemContent("A/mu", muContent);
        rhoPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
        thisTest.getWc().setItemContent("A/D/G/rho", rhoContent);
        assertEquals("wrong revision number from commit",
                     client.commit(new String[] { thisTest.getWorkingCopy().getAbsolutePath() },
                                   "log msg", true), 2);
        thisTest.checkStatus();
        OneTest backupTest = thisTest.copy(".backup");
        muPW = new PrintWriter(new FileOutputStream(mu, true));
        muContent = thisTest.getWc().getItemContent("A/mu");
        rhoPW = new PrintWriter(new FileOutputStream(rho, true));
        rhoContent = thisTest.getWc().getItemContent("A/D/G/rho");
        muPW.print(" Appended to line 10 of mu");
        muContent = muContent + " Appended to line 10 of mu";
        rhoPW.print(" Appended to line 10 of rho");
        rhoContent = rhoContent + " Appended to line 10 of rho";
        muPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/mu", 3);
        thisTest.getWc().setItemContent("A/mu", muContent);
        rhoPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 3);
        thisTest.getWc().setItemContent("A/D/G/rho", rhoContent);
        assertEquals("wrong revision number from commit",
                     client.commit(new String[] { thisTest.getWorkingCopy().getAbsolutePath() },
                                   "log msg", true), 3);
        thisTest.checkStatus();
        mu = new File(backupTest.getWorkingCopy(), "A/mu");
        muPW = new PrintWriter(new FileOutputStream(mu));
        muPW.print("This is the new line 1 in the backup copy of mu");
        muContent = "This is the new line 1 in the backup copy of mu";
        rho = new File(backupTest.getWorkingCopy(), "A/D/G/rho");
        rhoPW = new PrintWriter(new FileOutputStream(rho));
        rhoPW.print("This is the new line 1 in the backup copy of rho");
        rhoContent = "This is the new line 1 in the backup copy of rho";
        for (int i = 2; i < 11; i++)
        {
            muPW.print("\nThis is line " + i + " in mu");
            muContent = muContent + "\nThis is line " + i + " in mu";
            rhoPW.print("\nThis is line " + i + " in rho");
            rhoContent = rhoContent + "\nThis is line " + i + " in rho";
        }
        muPW.close();
        backupTest.getWc().setItemWorkingCopyRevision("A/mu", 3);
        muContent = muContent + " Appended to line 10 of mu";
        backupTest.getWc().setItemContent("A/mu", muContent);
        backupTest.getWc().setItemTextStatus("A/mu", Status.Kind.modified);
        rhoPW.close();
        backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 3);
        rhoContent = rhoContent + " Appended to line 10 of rho";
        backupTest.getWc().setItemContent("A/D/G/rho", rhoContent);
        backupTest.getWc().setItemTextStatus("A/D/G/rho",
                                             Status.Kind.modified);
        assertEquals("wrong revision number from update",
                     client.update(backupTest.getWorkingCopy().getAbsolutePath(),
                                   null, true), 3);
        backupTest.checkStatus();
    }

    public void testBasicConflict() throws Throwable
    {
        OneTest thisTest = new OneTest();
        OneTest backupTest = thisTest.copy(".backup");
        File mu = new File(thisTest.getWorkingCopy(), "A/mu");
        PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));
        String muContent = thisTest.getWc().getItemContent("A/mu");
        File rho = new File(thisTest.getWorkingCopy(), "A/D/G/rho");
        PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho, true));
        String rhoContent = thisTest.getWc().getItemContent("A/D/G/rho");
        muPW.print("\nOriginal appended text for mu");
        muContent = muContent + "\nOriginal appended text for mu";
        rhoPW.print("\nOriginal appended text for rho");
        rhoContent = rhoContent + "\nOriginal appended text for rho";
        muPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
        thisTest.getWc().setItemContent("A/mu", muContent);
        rhoPW.close();
        thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
        thisTest.getWc().setItemContent("A/D/G/rho", rhoContent);
        assertEquals("wrong revision number from commit", client.commit(new String[]{thisTest.getWorkingCopy().getAbsolutePath()}, "log msg", true), 2);
        thisTest.checkStatus();
        mu = new File(backupTest.getWorkingCopy(), "A/mu");
        muPW = new PrintWriter(new FileOutputStream(mu, true));
        rho = new File(backupTest.getWorkingCopy(), "A/D/G/rho");
        rhoPW = new PrintWriter(new FileOutputStream(rho, true));
        muPW.print("\nConflicting appended text for mu");
        muContent = "<<<<<<< .mine\nThis is the file 'mu'.\nConflicting appended text for mu=======\nThis is the file 'mu'.\nOriginal appended text for mu>>>>>>> .r2";
        rhoPW.print("\nConflicting appended text for rho");
        rhoContent = "<<<<<<< .mine\nThis is the file 'rho'.\nConflicting appended text for rho=======\nhis is the file 'rho'.\nOriginal appended text for rho>>>>>>> .r2";
        muPW.close();
        backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
        backupTest.getWc().setItemContent("A/mu", muContent);
        backupTest.getWc().setItemTextStatus("A/mu", Status.Kind.conflicted);
        rhoPW.close();
        backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
        backupTest.getWc().setItemContent("A/D/G/rho", rhoContent);
        backupTest.getWc().setItemTextStatus("A/D/G/rho", Status.Kind.conflicted);
        backupTest.getWc().addItem("A/mu.r1", "");

⌨️ 快捷键说明

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