0001: /**
0002: * @copyright
0003: * ====================================================================
0004: * Copyright (c) 2003-2004 CollabNet. All rights reserved.
0005: *
0006: * This software is licensed as described in the file COPYING, which
0007: * you should have received as part of this distribution. The terms
0008: * are also available at http://subversion.tigris.org/license-1.html.
0009: * If newer versions of this license are posted there, you may use a
0010: * newer version instead, at your option.
0011: *
0012: * This software consists of voluntary contributions made by many
0013: * individuals. For exact contribution history, see the revision
0014: * history and logs, available at http://subversion.tigris.org/.
0015: * ====================================================================
0016: * @endcopyright
0017: */package org.tigris.subversion.javahl.tests;
0018:
0019: import junit.framework.TestSuite;
0020: import junit.framework.TestResult;
0021: import org.tigris.subversion.javahl.*;
0022:
0023: import java.io.File;
0024: import java.io.FileOutputStream;
0025: import java.io.PrintWriter;
0026: import java.io.ByteArrayOutputStream;
0027: import java.util.Arrays;
0028:
0029: /**
0030: * Tests the basic functionality of javahl binding (inspired by the
0031: * tests in subversion/tests/cmdline/basic_tests.py).
0032: */
0033: public class BasicTests extends SVNTests {
0034: /**
0035: * base name of all our tests
0036: */
0037: public final static String testName = "basic_test";
0038:
0039: /**
0040: * Initialize the testBaseName and the testCounter, if this is the first
0041: * test of this class
0042: */
0043: public BasicTests() {
0044: if (!testName.equals(testBaseName)) {
0045: testCounter = 0;
0046: testBaseName = testName;
0047: }
0048: }
0049:
0050: /**
0051: * Build a test suite of all tests of this class
0052: * @return the new test suite
0053: */
0054: public static TestSuite suite() {
0055: return new TestSuite(BasicTests.class);
0056: }
0057:
0058: /**
0059: * Main method to run tests standalone
0060: * @param args command line arguments to specify root directory and root
0061: * url
0062: */
0063: public static void main(String[] args) {
0064: processArgs(args);
0065: TestResult tr = junit.textui.TestRunner.run(suite());
0066: if (tr.errorCount() != 0 || tr.failureCount() != 0) {
0067: System.exit(1);
0068: }
0069: System.exit(0);
0070: }
0071:
0072: /**
0073: * Test SVNClient.getVersion().
0074: * @throws Throwable
0075: */
0076: public void testVersion() throws Throwable {
0077: try {
0078: Version version = client.getVersion();
0079: String versionString = version.toString();
0080: if (versionString == null
0081: || versionString.trim().length() == 0) {
0082: throw new Exception("Version string empty");
0083: }
0084: } catch (Exception e) {
0085: fail("Version should always be available unless the "
0086: + "native libraries failed to initialize: " + e);
0087: }
0088: }
0089:
0090: /**
0091: * Tests Subversion path validation.
0092: */
0093: public void testPathValidation() throws Throwable {
0094: // Rather than segfaulting, JavaHL considers null an invalid path.
0095: assertFalse(
0096: "Path validation produced false-positive for null path",
0097: Path.isValid(null));
0098:
0099: String path = "valid-path";
0100: assertTrue("Validation check of valid path '" + path
0101: + "' should succeed", Path.isValid(path));
0102:
0103: // File names cannot contain control characters.
0104: path = "invalid-\u0001-path";
0105: assertFalse("Validation check of invalid path '" + path
0106: + "' (which contains control characters) should fail",
0107: Path.isValid(path));
0108: }
0109:
0110: /**
0111: * test the basic SVNClient.checkout functionality
0112: * @throws Throwable
0113: */
0114: public void testBasicCheckout() throws Throwable {
0115: // build the test setup
0116: OneTest this Test = new OneTest();
0117: try {
0118: // obstructed checkout must fail
0119: client.checkout(this Test.getUrl() + "/A", this Test
0120: .getWCPath(), null, true);
0121: fail("missing exception");
0122: } catch (ClientException expected) {
0123: }
0124: // modify file A/mu
0125: File mu = new File(this Test.getWorkingCopy(), "A/mu");
0126: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
0127: true));
0128: muPW.print("appended mu text");
0129: muPW.close();
0130: this Test.getWc()
0131: .setItemTextStatus("A/mu", Status.Kind.modified);
0132:
0133: // delete A/B/lambda without svn
0134: File lambda = new File(this Test.getWorkingCopy(), "A/B/lambda");
0135: lambda.delete();
0136: this Test.getWc().setItemTextStatus("A/B/lambda",
0137: Status.Kind.missing);
0138:
0139: // remove A/D/G
0140: client.remove(new String[] { this Test.getWCPath() + "/A/D/G" },
0141: null, false);
0142: this Test.getWc()
0143: .setItemTextStatus("A/D/G", Status.Kind.deleted);
0144: this Test.getWc().setItemTextStatus("A/D/G/pi",
0145: Status.Kind.deleted);
0146: this Test.getWc().setItemTextStatus("A/D/G/rho",
0147: Status.Kind.deleted);
0148: this Test.getWc().setItemTextStatus("A/D/G/tau",
0149: Status.Kind.deleted);
0150:
0151: // check the status of the working copy
0152: this Test.checkStatus();
0153:
0154: // recheckout the working copy
0155: client.checkout(this Test.getUrl(), this Test.getWCPath(), null,
0156: true);
0157:
0158: // deleted file should reapear
0159: this Test.getWc().setItemTextStatus("A/B/lambda",
0160: Status.Kind.normal);
0161:
0162: // check the status of the working copy
0163: this Test.checkStatus();
0164: }
0165:
0166: /**
0167: * test the basic SVNClient.status functionality
0168: * @throws Throwable
0169: */
0170: public void testBasicStatus() throws Throwable {
0171: // build the test setup
0172: OneTest this Test = new OneTest();
0173:
0174: // check the status of the working copy
0175: this Test.checkStatus();
0176: }
0177:
0178: /**
0179: * test the basic SVNClient.commit functionality
0180: * @throws Throwable
0181: */
0182: public void testBasicCommit() throws Throwable {
0183: // build the test setup
0184: OneTest this Test = new OneTest();
0185:
0186: // modify file A/mu
0187: File mu = new File(this Test.getWorkingCopy(), "A/mu");
0188: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
0189: true));
0190: muPW.print("appended mu text");
0191: muPW.close();
0192: this Test.getWc().setItemWorkingCopyRevision("A/mu", 2);
0193: this Test.getWc().setItemContent(
0194: "A/mu",
0195: this Test.getWc().getItemContent("A/mu")
0196: + "appended mu text");
0197: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0198: "A/mu", NodeKind.file, CommitItemStateFlags.TextMods);
0199:
0200: // modify file A/D/G/rho
0201: File rho = new File(this Test.getWorkingCopy(), "A/D/G/rho");
0202: PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho,
0203: true));
0204: rhoPW.print("new appended text for rho");
0205: rhoPW.close();
0206: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0207: this Test.getWc().setItemContent(
0208: "A/D/G/rho",
0209: this Test.getWc().getItemContent("A/D/G/rho")
0210: + "new appended text for rho");
0211: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0212: "A/D/G/rho", NodeKind.file,
0213: CommitItemStateFlags.TextMods);
0214:
0215: // commit the changes
0216: assertEquals("wrong revision number from commit", client
0217: .commit(new String[] { this Test.getWCPath() },
0218: "log msg", true), 2);
0219:
0220: // check the status of the working copy
0221: this Test.checkStatus();
0222: }
0223:
0224: /**
0225: * test the basic SVNClient.update functionality
0226: * @throws Throwable
0227: */
0228: public void testBasicUpdate() throws Throwable {
0229: // build the test setup. Used for the changes
0230: OneTest this Test = new OneTest();
0231:
0232: // build the backup test setup. That is the one that will be updated
0233: OneTest backupTest = this Test.copy(".backup");
0234:
0235: // modify A/mu
0236: File mu = new File(this Test.getWorkingCopy(), "A/mu");
0237: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
0238: true));
0239: muPW.print("appended mu text");
0240: muPW.close();
0241: this Test.getWc().setItemWorkingCopyRevision("A/mu", 2);
0242: this Test.getWc().setItemContent(
0243: "A/mu",
0244: this Test.getWc().getItemContent("A/mu")
0245: + "appended mu text");
0246: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0247: "A/mu", NodeKind.file, CommitItemStateFlags.TextMods);
0248:
0249: // modify A/D/G/rho
0250: File rho = new File(this Test.getWorkingCopy(), "A/D/G/rho");
0251: PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho,
0252: true));
0253: rhoPW.print("new appended text for rho");
0254: rhoPW.close();
0255: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0256: this Test.getWc().setItemContent(
0257: "A/D/G/rho",
0258: this Test.getWc().getItemContent("A/D/G/rho")
0259: + "new appended text for rho");
0260: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0261: "A/D/G/rho", NodeKind.file,
0262: CommitItemStateFlags.TextMods);
0263:
0264: // commit the changes
0265: assertEquals("wrong revision number from commit", client
0266: .commit(new String[] { this Test.getWCPath() },
0267: "log msg", true), 2);
0268:
0269: // check the status of the working copy
0270: this Test.checkStatus();
0271:
0272: // update the backup test
0273: assertEquals("wrong revision number from update", client
0274: .update(backupTest.getWCPath(), null, true), 2);
0275:
0276: // set the expected working copy layout for the backup test
0277: backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
0278: backupTest.getWc().setItemContent(
0279: "A/mu",
0280: backupTest.getWc().getItemContent("A/mu")
0281: + "appended mu text");
0282: backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0283: backupTest.getWc().setItemContent(
0284: "A/D/G/rho",
0285: backupTest.getWc().getItemContent("A/D/G/rho")
0286: + "new appended text for rho");
0287:
0288: // check the status of the working copy of the backup test
0289: backupTest.checkStatus();
0290: }
0291:
0292: /**
0293: * test basic SVNClient.mkdir with url parameter functionality
0294: * @throws Throwable
0295: */
0296: public void testBasicMkdirUrl() throws Throwable {
0297: // build the test setup.
0298: OneTest this Test = new OneTest();
0299:
0300: // create Y and Y/Z directories in the repository
0301: addExpectedCommitItem(null, this Test.getUrl(), "Y",
0302: NodeKind.none, CommitItemStateFlags.Add);
0303: addExpectedCommitItem(null, this Test.getUrl(), "Y/Z",
0304: NodeKind.none, CommitItemStateFlags.Add);
0305: client.mkdir(new String[] { this Test.getUrl() + "/Y",
0306: this Test.getUrl() + "/Y/Z" }, "log_msg");
0307:
0308: // add the new directories the expected working copy layout
0309: this Test.getWc().addItem("Y", null);
0310: this Test.getWc().setItemWorkingCopyRevision("Y", 2);
0311: this Test.getWc().addItem("Y/Z", null);
0312: this Test.getWc().setItemWorkingCopyRevision("Y/Z", 2);
0313:
0314: // update the working copy
0315: assertEquals("wrong revision from update", client.update(
0316: this Test.getWCPath(), null, true), 2);
0317:
0318: // check the status of the working copy
0319: this Test.checkStatus();
0320: }
0321:
0322: /**
0323: * test the basic SVNClient.update functionality with concurrent changes
0324: * in the repository and the working copy
0325: * @throws Throwable
0326: */
0327: public void testBasicMergingUpdate() throws Throwable {
0328: // build the first working copy
0329: OneTest this Test = new OneTest();
0330:
0331: // append 10 lines to A/mu
0332: File mu = new File(this Test.getWorkingCopy(), "A/mu");
0333: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
0334: true));
0335: String muContent = this Test.getWc().getItemContent("A/mu");
0336: for (int i = 2; i < 11; i++) {
0337: muPW.print("\nThis is line " + i + " in mu");
0338: muContent = muContent + "\nThis is line " + i + " in mu";
0339: }
0340: muPW.close();
0341: this Test.getWc().setItemWorkingCopyRevision("A/mu", 2);
0342: this Test.getWc().setItemContent("A/mu", muContent);
0343: addExpectedCommitItem(this Test.getWorkingCopy()
0344: .getAbsolutePath(), this Test.getUrl(), "A/mu",
0345: NodeKind.file, CommitItemStateFlags.TextMods);
0346:
0347: // append 10 line to A/D/G/rho
0348: File rho = new File(this Test.getWorkingCopy(), "A/D/G/rho");
0349: PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho,
0350: true));
0351: String rhoContent = this Test.getWc()
0352: .getItemContent("A/D/G/rho");
0353: for (int i = 2; i < 11; i++) {
0354: rhoPW.print("\nThis is line " + i + " in rho");
0355: rhoContent = rhoContent + "\nThis is line " + i + " in rho";
0356: }
0357: rhoPW.close();
0358: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0359: this Test.getWc().setItemContent("A/D/G/rho", rhoContent);
0360: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0361: "A/D/G/rho", NodeKind.file,
0362: CommitItemStateFlags.TextMods);
0363:
0364: // commit the changes
0365: assertEquals("wrong revision number from commit", client
0366: .commit(new String[] { this Test.getWCPath() },
0367: "log msg", true), 2);
0368:
0369: // check the status of the first working copy
0370: this Test.checkStatus();
0371:
0372: // create a backup copy of the working copy
0373: OneTest backupTest = this Test.copy(".backup");
0374:
0375: // change the last line of A/mu in the first working copy
0376: muPW = new PrintWriter(new FileOutputStream(mu, true));
0377: muContent = this Test.getWc().getItemContent("A/mu");
0378: muPW.print(" Appended to line 10 of mu");
0379: muContent = muContent + " Appended to line 10 of mu";
0380: muPW.close();
0381: this Test.getWc().setItemWorkingCopyRevision("A/mu", 3);
0382: this Test.getWc().setItemContent("A/mu", muContent);
0383: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0384: "A/mu", NodeKind.file, CommitItemStateFlags.TextMods);
0385:
0386: // change the last line of A/mu in the first working copy
0387: rhoPW = new PrintWriter(new FileOutputStream(rho, true));
0388: rhoContent = this Test.getWc().getItemContent("A/D/G/rho");
0389: rhoPW.print(" Appended to line 10 of rho");
0390: rhoContent = rhoContent + " Appended to line 10 of rho";
0391: rhoPW.close();
0392: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 3);
0393: this Test.getWc().setItemContent("A/D/G/rho", rhoContent);
0394: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0395: "A/D/G/rho", NodeKind.file,
0396: CommitItemStateFlags.TextMods);
0397:
0398: // commit these changes to the repository
0399: assertEquals("wrong revision number from commit", client
0400: .commit(new String[] { this Test.getWCPath() },
0401: "log msg", true), 3);
0402:
0403: // check the status of the first working copy
0404: this Test.checkStatus();
0405:
0406: // modify the first line of A/mu in the backup working copy
0407: mu = new File(backupTest.getWorkingCopy(), "A/mu");
0408: muPW = new PrintWriter(new FileOutputStream(mu));
0409: muPW.print("This is the new line 1 in the backup copy of mu");
0410: muContent = "This is the new line 1 in the backup copy of mu";
0411: for (int i = 2; i < 11; i++) {
0412: muPW.print("\nThis is line " + i + " in mu");
0413: muContent = muContent + "\nThis is line " + i + " in mu";
0414: }
0415: muPW.close();
0416: backupTest.getWc().setItemWorkingCopyRevision("A/mu", 3);
0417: muContent = muContent + " Appended to line 10 of mu";
0418: backupTest.getWc().setItemContent("A/mu", muContent);
0419: backupTest.getWc().setItemTextStatus("A/mu",
0420: Status.Kind.modified);
0421:
0422: // modify the first line of A/D/G/rho in the backup working copy
0423: rho = new File(backupTest.getWorkingCopy(), "A/D/G/rho");
0424: rhoPW = new PrintWriter(new FileOutputStream(rho));
0425: rhoPW.print("This is the new line 1 in the backup copy of rho");
0426: rhoContent = "This is the new line 1 in the backup copy of rho";
0427: for (int i = 2; i < 11; i++) {
0428: rhoPW.print("\nThis is line " + i + " in rho");
0429: rhoContent = rhoContent + "\nThis is line " + i + " in rho";
0430: }
0431: rhoPW.close();
0432: backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 3);
0433: rhoContent = rhoContent + " Appended to line 10 of rho";
0434: backupTest.getWc().setItemContent("A/D/G/rho", rhoContent);
0435: backupTest.getWc().setItemTextStatus("A/D/G/rho",
0436: Status.Kind.modified);
0437:
0438: // update the backup working copy
0439: assertEquals("wrong revision number from update", client
0440: .update(backupTest.getWCPath(), null, true), 3);
0441:
0442: // check the status of the backup working copy
0443: backupTest.checkStatus();
0444: }
0445:
0446: /**
0447: * test the basic SVNClient.update functionality with concurrent changes
0448: * in the repository and the working copy that generate conflicts
0449: * @throws Throwable
0450: */
0451: public void testBasicConflict() throws Throwable {
0452: // build the first working copy
0453: OneTest this Test = new OneTest();
0454:
0455: // copy the first working copy to the backup working copy
0456: OneTest backupTest = this Test.copy(".backup");
0457:
0458: // append a line to A/mu in the first working copy
0459: File mu = new File(this Test.getWorkingCopy(), "A/mu");
0460: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
0461: true));
0462: String muContent = this Test.getWc().getItemContent("A/mu");
0463: muPW.print("\nOriginal appended text for mu");
0464: muContent = muContent + "\nOriginal appended text for mu";
0465: muPW.close();
0466: this Test.getWc().setItemWorkingCopyRevision("A/mu", 2);
0467: this Test.getWc().setItemContent("A/mu", muContent);
0468: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0469: "A/mu", NodeKind.file, CommitItemStateFlags.TextMods);
0470:
0471: // append a line to A/D/G/rho in the first working copy
0472: File rho = new File(this Test.getWorkingCopy(), "A/D/G/rho");
0473: PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho,
0474: true));
0475: String rhoContent = this Test.getWc()
0476: .getItemContent("A/D/G/rho");
0477: rhoPW.print("\nOriginal appended text for rho");
0478: rhoContent = rhoContent + "\nOriginal appended text for rho";
0479: rhoPW.close();
0480: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0481: this Test.getWc().setItemContent("A/D/G/rho", rhoContent);
0482: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
0483: "A/D/G/rho", NodeKind.file,
0484: CommitItemStateFlags.TextMods);
0485:
0486: // commit the changes in the first working copy
0487: assertEquals("wrong revision number from commit", client
0488: .commit(new String[] { this Test.getWCPath() },
0489: "log msg", true), 2);
0490:
0491: // test the status of the working copy after the commit
0492: this Test.checkStatus();
0493:
0494: // append a different line to A/mu in the backup working copy
0495: mu = new File(backupTest.getWorkingCopy(), "A/mu");
0496: muPW = new PrintWriter(new FileOutputStream(mu, true));
0497: muPW.print("\nConflicting appended text for mu");
0498: muContent = "<<<<<<< .mine\nThis is the file 'mu'.\n"
0499: + "Conflicting appended text for mu=======\n"
0500: + "This is the file 'mu'.\n"
0501: + "Original appended text for mu>>>>>>> .r2";
0502: muPW.close();
0503: backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
0504: backupTest.getWc().setItemContent("A/mu", muContent);
0505: backupTest.getWc().setItemTextStatus("A/mu",
0506: Status.Kind.conflicted);
0507: backupTest.getWc().addItem("A/mu.r1", "");
0508: backupTest.getWc().setItemNodeKind("A/mu.r1", NodeKind.unknown);
0509: backupTest.getWc().setItemTextStatus("A/mu.r1",
0510: Status.Kind.unversioned);
0511: backupTest.getWc().addItem("A/mu.r2", "");
0512: backupTest.getWc().setItemNodeKind("A/mu.r2", NodeKind.unknown);
0513: backupTest.getWc().setItemTextStatus("A/mu.r2",
0514: Status.Kind.unversioned);
0515: backupTest.getWc().addItem("A/mu.mine", "");
0516: backupTest.getWc().setItemNodeKind("A/mu.mine",
0517: NodeKind.unknown);
0518: backupTest.getWc().setItemTextStatus("A/mu.mine",
0519: Status.Kind.unversioned);
0520:
0521: // append a different line to A/D/G/rho in the backup working copy
0522: rho = new File(backupTest.getWorkingCopy(), "A/D/G/rho");
0523: rhoPW = new PrintWriter(new FileOutputStream(rho, true));
0524: rhoPW.print("\nConflicting appended text for rho");
0525: rhoContent = "<<<<<<< .mine\nThis is the file 'rho'.\n"
0526: + "Conflicting appended text for rho=======\n"
0527: + "his is the file 'rho'.\n"
0528: + "Original appended text for rho>>>>>>> .r2";
0529: rhoPW.close();
0530: backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
0531: backupTest.getWc().setItemContent("A/D/G/rho", rhoContent);
0532: backupTest.getWc().setItemTextStatus("A/D/G/rho",
0533: Status.Kind.conflicted);
0534: backupTest.getWc().addItem("A/D/G/rho.r1", "");
0535: backupTest.getWc().setItemNodeKind("A/D/G/rho.r1",
0536: NodeKind.unknown);
0537: backupTest.getWc().setItemTextStatus("A/D/G/rho.r1",
0538: Status.Kind.unversioned);
0539: backupTest.getWc().addItem("A/D/G/rho.r2", "");
0540: backupTest.getWc().setItemNodeKind("A/D/G/rho.r2",
0541: NodeKind.unknown);
0542: backupTest.getWc().setItemTextStatus("A/D/G/rho.r2",
0543: Status.Kind.unversioned);
0544: backupTest.getWc().addItem("A/D/G/rho.mine", "");
0545: backupTest.getWc().setItemNodeKind("A/D/G/rho.mine",
0546: NodeKind.unknown);
0547: backupTest.getWc().setItemTextStatus("A/D/G/rho.mine",
0548: Status.Kind.unversioned);
0549:
0550: // update the backup working copy from the repository
0551: assertEquals("wrong revision number from update", client
0552: .update(backupTest.getWCPath(), null, true), 2);
0553:
0554: // check the status of the backup working copy
0555: backupTest.checkStatus();
0556:
0557: // flag A/mu as resolved
0558: client.resolved(backupTest.getWCPath() + "/A/mu", false);
0559: backupTest.getWc().setItemTextStatus("A/mu",
0560: Status.Kind.modified);
0561: backupTest.getWc().removeItem("A/mu.r1");
0562: backupTest.getWc().removeItem("A/mu.r2");
0563: backupTest.getWc().removeItem("A/mu.mine");
0564:
0565: // flag A/D/G/rho as resolved
0566: client.resolved(backupTest.getWCPath() + "/A/D/G/rho", false);
0567: backupTest.getWc().setItemTextStatus("A/D/G/rho",
0568: Status.Kind.modified);
0569: backupTest.getWc().removeItem("A/D/G/rho.r1");
0570: backupTest.getWc().removeItem("A/D/G/rho.r2");
0571: backupTest.getWc().removeItem("A/D/G/rho.mine");
0572:
0573: // check the status after the conflicts are flaged as resolved
0574: backupTest.checkStatus();
0575: }
0576:
0577: /**
0578: * test the basic SVNClient.cleanup functionality
0579: * @throws Throwable
0580: */
0581: public void testBasicCleanup() throws Throwable {
0582: // create a test working copy
0583: OneTest this Test = new OneTest();
0584:
0585: // create a lock file in A/B
0586: File adminLock = new File(this Test.getWorkingCopy(), "A/B/"
0587: + getAdminDirectoryName() + "/lock");
0588: PrintWriter pw = new PrintWriter(
0589: new FileOutputStream(adminLock));
0590: pw.print("stop looking!");
0591: pw.close();
0592: this Test.getWc().setItemIsLocked("A/B", true);
0593:
0594: // create a lock file in A/D/G
0595: adminLock = new File(this Test.getWorkingCopy(), "A/D/G/"
0596: + getAdminDirectoryName() + "/lock");
0597: pw = new PrintWriter(new FileOutputStream(adminLock));
0598: pw.print("stop looking!");
0599: pw.close();
0600: this Test.getWc().setItemIsLocked("A/D/G", true);
0601:
0602: // create a lock file in A/C
0603: adminLock = new File(this Test.getWorkingCopy(), "A/C/"
0604: + getAdminDirectoryName() + "/lock");
0605: pw = new PrintWriter(new FileOutputStream(adminLock));
0606: pw.print("stop looking!");
0607: pw.close();
0608: this Test.getWc().setItemIsLocked("A/C", true);
0609:
0610: // test the status of the working copy
0611: this Test.checkStatus();
0612:
0613: // run cleanup
0614: client.cleanup(this Test.getWCPath());
0615: this Test.getWc().setItemIsLocked("A/B", false);
0616: this Test.getWc().setItemIsLocked("A/D/G", false);
0617: this Test.getWc().setItemIsLocked("A/C", false);
0618:
0619: // test the status of the working copy
0620: this Test.checkStatus();
0621: }
0622:
0623: /**
0624: * Test the basic SVNClient.revert functionality
0625: * @throws Throwable
0626: */
0627: public void testBasicRevert() throws Throwable {
0628: // create a test working copy
0629: OneTest this Test = new OneTest();
0630:
0631: // modify A/B/E/beta
0632: File file = new File(this Test.getWorkingCopy(), "A/B/E/beta");
0633: PrintWriter pw = new PrintWriter(new FileOutputStream(file,
0634: true));
0635: pw.print("Added some text to 'beta'.");
0636: pw.close();
0637: this Test.getWc().setItemTextStatus("A/B/E/beta",
0638: Status.Kind.modified);
0639:
0640: // modify iota
0641: file = new File(this Test.getWorkingCopy(), "iota");
0642: pw = new PrintWriter(new FileOutputStream(file, true));
0643: pw.print("Added some text to 'iota'.");
0644: pw.close();
0645: this Test.getWc()
0646: .setItemTextStatus("iota", Status.Kind.modified);
0647:
0648: // modify A/D/G/rho
0649: file = new File(this Test.getWorkingCopy(), "A/D/G/rho");
0650: pw = new PrintWriter(new FileOutputStream(file, true));
0651: pw.print("Added some text to 'rho'.");
0652: pw.close();
0653: this Test.getWc().setItemTextStatus("A/D/G/rho",
0654: Status.Kind.modified);
0655:
0656: // create new file A/D/H/zeta and add it to subversion
0657: file = new File(this Test.getWorkingCopy(), "A/D/H/zeta");
0658: pw = new PrintWriter(new FileOutputStream(file, true));
0659: pw.print("Added some text to 'zeta'.");
0660: pw.close();
0661: this Test.getWc().addItem("A/D/H/zeta",
0662: "Added some text to 'zeta'.");
0663: this Test.getWc().setItemTextStatus("A/D/H/zeta",
0664: Status.Kind.added);
0665: client.add(file.getAbsolutePath(), false);
0666:
0667: // test the status of the working copy
0668: this Test.checkStatus();
0669:
0670: // revert the changes
0671: client.revert(this Test.getWCPath() + "/A/B/E/beta", false);
0672: this Test.getWc().setItemTextStatus("A/B/E/beta",
0673: Status.Kind.normal);
0674: client.revert(this Test.getWCPath() + "/iota", false);
0675: this Test.getWc().setItemTextStatus("iota", Status.Kind.normal);
0676: client.revert(this Test.getWCPath() + "/A/D/G/rho", false);
0677: this Test.getWc().setItemTextStatus("A/D/G/rho",
0678: Status.Kind.normal);
0679: client.revert(this Test.getWCPath() + "/A/D/H/zeta", false);
0680: this Test.getWc().setItemTextStatus("A/D/H/zeta",
0681: Status.Kind.unversioned);
0682: this Test.getWc()
0683: .setItemNodeKind("A/D/H/zeta", NodeKind.unknown);
0684:
0685: // test the status of the working copy
0686: this Test.checkStatus();
0687:
0688: // delete A/B/E/beta and revert the change
0689: file = new File(this Test.getWorkingCopy(), "A/B/E/beta");
0690: file.delete();
0691: client.revert(file.getAbsolutePath(), false);
0692:
0693: // resurected file should not be readonly
0694: assertTrue("reverted file is not readonly", file.canWrite()
0695: && file.canRead());
0696:
0697: // test the status of the working copy
0698: this Test.checkStatus();
0699:
0700: // create & add the directory X
0701: client
0702: .mkdir(new String[] { this Test.getWCPath() + "/X" },
0703: null);
0704: this Test.getWc().addItem("X", null);
0705: this Test.getWc().setItemTextStatus("X", Status.Kind.added);
0706:
0707: // test the status of the working copy
0708: this Test.checkStatus();
0709:
0710: // remove & revert X
0711: removeDirectoryWithContent(new File(this Test.getWorkingCopy(),
0712: "X"));
0713: client.revert(this Test.getWCPath() + "/X", false);
0714: this Test.getWc().removeItem("X");
0715:
0716: // test the status of the working copy
0717: this Test.checkStatus();
0718:
0719: // delete the directory A/B/E
0720: client.remove(new String[] { this Test.getWCPath() + "/A/B/E" },
0721: null, true);
0722: removeDirectoryWithContent(new File(this Test.getWorkingCopy(),
0723: "A/B/E"));
0724: this Test.getWc()
0725: .setItemTextStatus("A/B/E", Status.Kind.deleted);
0726: this Test.getWc().removeItem("A/B/E/alpha");
0727: this Test.getWc().removeItem("A/B/E/beta");
0728:
0729: // test the status of the working copy
0730: this Test.checkStatus();
0731:
0732: // revert A/B/E -> this will not resurect it
0733: client.revert(this Test.getWCPath() + "/A/B/E", true);
0734:
0735: // test the status of the working copy
0736: this Test.checkStatus();
0737: }
0738:
0739: /**
0740: * thest the basic SVNClient.switch functionality
0741: * @throws Throwable
0742: */
0743: public void testBasicSwitch() throws Throwable {
0744: // create the test working copy
0745: OneTest this Test = new OneTest();
0746:
0747: // switch iota to A/D/gamma
0748: String iotaPath = this Test.getWCPath() + "/iota";
0749: String gammaUrl = this Test.getUrl() + "/A/D/gamma";
0750: this Test.getWc().setItemContent("iota",
0751: greekWC.getItemContent("A/D/gamma"));
0752: this Test.getWc().setItemIsSwitched("iota", true);
0753: client.doSwitch(iotaPath, gammaUrl, null, true);
0754:
0755: // check the status of the working copy
0756: this Test.checkStatus();
0757:
0758: // switch A/D/H to /A/D/G
0759: String adhPath = this Test.getWCPath() + "/A/D/H";
0760: String adgURL = this Test.getUrl() + "/A/D/G";
0761: this Test.getWc().setItemIsSwitched("A/D/H", true);
0762: this Test.getWc().removeItem("A/D/H/chi");
0763: this Test.getWc().removeItem("A/D/H/omega");
0764: this Test.getWc().removeItem("A/D/H/psi");
0765: this Test.getWc().addItem("A/D/H/pi",
0766: this Test.getWc().getItemContent("A/D/G/pi"));
0767: this Test.getWc().addItem("A/D/H/rho",
0768: this Test.getWc().getItemContent("A/D/G/rho"));
0769: this Test.getWc().addItem("A/D/H/tau",
0770: this Test.getWc().getItemContent("A/D/G/tau"));
0771: client.doSwitch(adhPath, adgURL, null, true);
0772:
0773: // check the status of the working copy
0774: this Test.checkStatus();
0775: }
0776:
0777: /**
0778: * test the basic SVNClient.remove functionality
0779: * @throws Throwable
0780: */
0781: public void testBasicDelete() throws Throwable {
0782: // create the test working copy
0783: OneTest this Test = new OneTest();
0784:
0785: // modify A/D/H/chi
0786: File file = new File(this Test.getWorkingCopy(), "A/D/H/chi");
0787: PrintWriter pw = new PrintWriter(new FileOutputStream(file,
0788: true));
0789: pw.print("added to chi");
0790: pw.close();
0791: this Test.getWc().setItemTextStatus("A/D/H/chi",
0792: Status.Kind.modified);
0793:
0794: // set a property on A/D/G/rho file
0795: client.propertySet(this Test.getWCPath() + "/A/D/G/rho", "abc",
0796: "def", true);
0797: this Test.getWc().setItemPropStatus("A/D/G/rho",
0798: Status.Kind.modified);
0799:
0800: // set a property on A/B/F directory
0801: client.propertySet(this Test.getWCPath() + "/A/B/F", "abc",
0802: "def", false);
0803: this Test.getWc().setItemPropStatus("A/B/F",
0804: Status.Kind.modified);
0805:
0806: // create a unversioned A/C/sigma file
0807: file = new File(this Test.getWCPath(), "A/C/sigma");
0808: pw = new PrintWriter(new FileOutputStream(file));
0809: pw.print("unversioned sigma");
0810: pw.close();
0811: this Test.getWc().addItem("A/C/sigma", "unversioned sigma");
0812: this Test.getWc().setItemTextStatus("A/C/sigma",
0813: Status.Kind.unversioned);
0814: this Test.getWc().setItemNodeKind("A/C/sigma", NodeKind.unknown);
0815:
0816: // create unversioned directory A/C/Q
0817: file = new File(this Test.getWCPath(), "A/C/Q");
0818: file.mkdir();
0819: this Test.getWc().addItem("A/C/Q", null);
0820: this Test.getWc().setItemNodeKind("A/C/Q", NodeKind.unknown);
0821: this Test.getWc().setItemTextStatus("A/C/Q",
0822: Status.Kind.unversioned);
0823:
0824: // create & add the directory A/B/X
0825: file = new File(this Test.getWCPath(), "A/B/X");
0826: client.mkdir(new String[] { file.getAbsolutePath() }, null);
0827: this Test.getWc().addItem("A/B/X", null);
0828: this Test.getWc().setItemTextStatus("A/B/X", Status.Kind.added);
0829:
0830: // create & add the file A/B/X/xi
0831: file = new File(file, "xi");
0832: pw = new PrintWriter(new FileOutputStream(file));
0833: pw.print("added xi");
0834: pw.close();
0835: client.add(file.getAbsolutePath(), false);
0836: this Test.getWc().addItem("A/B/X/xi", "added xi");
0837: this Test.getWc().setItemTextStatus("A/B/X/xi",
0838: Status.Kind.added);
0839:
0840: // create & add the directory A/B/Y
0841: file = new File(this Test.getWCPath(), "A/B/Y");
0842: client.mkdir(new String[] { file.getAbsolutePath() }, null);
0843: this Test.getWc().addItem("A/B/Y", null);
0844: this Test.getWc().setItemTextStatus("A/B/Y", Status.Kind.added);
0845:
0846: // test the status of the working copy
0847: this Test.checkStatus();
0848:
0849: // the following removes should all fail without force
0850:
0851: try {
0852: // remove of A/D/H/chi without force should fail, because it is
0853: // modified
0854: client.remove(new String[] { this Test.getWCPath()
0855: + "/A/D/H/chi" }, null, false);
0856: fail("missing exception");
0857: } catch (ClientException expected) {
0858: }
0859:
0860: try {
0861: // remove of A/D/H without force should fail, because A/D/H/chi is
0862: // modified
0863: client.remove(new String[] { this Test.getWCPath()
0864: + "/A/D/H" }, null, false);
0865: fail("missing exception");
0866: } catch (ClientException expected) {
0867: }
0868:
0869: try {
0870: // remove of A/D/G/rho without force should fail, because it has
0871: // a new property
0872: client.remove(new String[] { this Test.getWCPath()
0873: + "/A/D/G/rho" }, null, false);
0874: fail("missing exception");
0875: } catch (ClientException expected) {
0876: }
0877:
0878: try {
0879: // remove of A/D/G without force should fail, because A/D/G/rho has
0880: // a new property
0881: client.remove(new String[] { this Test.getWCPath()
0882: + "/A/D/G" }, null, false);
0883: fail("missing exception");
0884: } catch (ClientException expected) {
0885: }
0886:
0887: try {
0888: // remove of A/B/F without force should fail, because it has
0889: // a new property
0890: client.remove(new String[] { this Test.getWCPath()
0891: + "/A/B/F" }, null, false);
0892: fail("missing exception");
0893: } catch (ClientException expected) {
0894: }
0895:
0896: try {
0897: // remove of A/B without force should fail, because A/B/F has
0898: // a new property
0899: client.remove(
0900: new String[] { this Test.getWCPath() + "/A/B" },
0901: null, false);
0902: fail("missing exception");
0903: } catch (ClientException expected) {
0904: }
0905:
0906: try {
0907: // remove of A/C/sigma without force should fail, because it is
0908: // unversioned
0909: client.remove(new String[] { this Test.getWCPath()
0910: + "/A/C/sigma" }, null, false);
0911: fail("missing exception");
0912: } catch (ClientException expected) {
0913: }
0914:
0915: try {
0916: // remove of A/C without force should fail, because A/C/sigma is
0917: // unversioned
0918: client.remove(
0919: new String[] { this Test.getWCPath() + "/A/C" },
0920: null, false);
0921: fail("missing exception");
0922: } catch (ClientException expected) {
0923: }
0924:
0925: try {
0926: // remove of A/B/X without force should fail, because it is new
0927: client.remove(new String[] { this Test.getWCPath()
0928: + "/A/B/X" }, null, false);
0929: fail("missing exception");
0930: } catch (ClientException expected) {
0931: }
0932:
0933: // check the status of the working copy
0934: this Test.checkStatus();
0935:
0936: // the following removes should all work
0937: client.remove(new String[] { this Test.getWCPath() + "/A/B/E" },
0938: null, false);
0939: this Test.getWc()
0940: .setItemTextStatus("A/B/E", Status.Kind.deleted);
0941: this Test.getWc().setItemTextStatus("A/B/E/alpha",
0942: Status.Kind.deleted);
0943: this Test.getWc().setItemTextStatus("A/B/E/beta",
0944: Status.Kind.deleted);
0945: client.remove(new String[] { this Test.getWCPath() + "/A/D/H" },
0946: null, true);
0947: this Test.getWc()
0948: .setItemTextStatus("A/D/H", Status.Kind.deleted);
0949: this Test.getWc().setItemTextStatus("A/D/H/chi",
0950: Status.Kind.deleted);
0951: this Test.getWc().setItemTextStatus("A/D/H/omega",
0952: Status.Kind.deleted);
0953: this Test.getWc().setItemTextStatus("A/D/H/psi",
0954: Status.Kind.deleted);
0955: client.remove(new String[] { this Test.getWCPath() + "/A/D/G" },
0956: null, true);
0957: this Test.getWc()
0958: .setItemTextStatus("A/D/G", Status.Kind.deleted);
0959: this Test.getWc().setItemTextStatus("A/D/G/rho",
0960: Status.Kind.deleted);
0961: this Test.getWc().setItemPropStatus("A/D/G/rho",
0962: Status.Kind.none);
0963: this Test.getWc().setItemTextStatus("A/D/G/pi",
0964: Status.Kind.deleted);
0965: this Test.getWc().setItemTextStatus("A/D/G/tau",
0966: Status.Kind.deleted);
0967: client.remove(new String[] { this Test.getWCPath() + "/A/B/F" },
0968: null, true);
0969: this Test.getWc()
0970: .setItemTextStatus("A/B/F", Status.Kind.deleted);
0971: this Test.getWc().setItemPropStatus("A/B/F", Status.Kind.none);
0972: client.remove(new String[] { this Test.getWCPath() + "/A/C" },
0973: null, true);
0974: this Test.getWc().setItemTextStatus("A/C", Status.Kind.deleted);
0975: client.remove(new String[] { this Test.getWCPath() + "/A/B/X" },
0976: null, true);
0977: file = new File(this Test.getWorkingCopy(), "iota");
0978: file.delete();
0979: client.remove(new String[] { file.getAbsolutePath() }, null,
0980: true);
0981: this Test.getWc().setItemTextStatus("iota", Status.Kind.deleted);
0982: file = new File(this Test.getWorkingCopy(), "A/D/gamma");
0983: file.delete();
0984: client.remove(new String[] { file.getAbsolutePath() }, null,
0985: false);
0986: this Test.getWc().setItemTextStatus("A/D/gamma",
0987: Status.Kind.deleted);
0988: client.remove(new String[] { file.getAbsolutePath() }, null,
0989: true);
0990: client.remove(new String[] { this Test.getWCPath() + "/A/B/E" },
0991: null, false);
0992: this Test.getWc().removeItem("A/B/X");
0993: this Test.getWc().removeItem("A/B/X/xi");
0994: this Test.getWc().removeItem("A/C/sigma");
0995: this Test.getWc().removeItem("A/C/Q");
0996: this Test.checkStatus();
0997: client.remove(new String[] { this Test.getWCPath() + "/A/D" },
0998: null, true);
0999: this Test.getWc().setItemTextStatus("A/D", Status.Kind.deleted);
1000: this Test.getWc().removeItem("A/D/Y");
1001:
1002: // check the status of the working copy
1003: this Test.checkStatus();
1004:
1005: // confirm that the file are realy deleted
1006: assertFalse("failed to remove text modified file", new File(
1007: this Test.getWorkingCopy(), "A/D/G/rho").exists());
1008: assertFalse("failed to remove prop modified file", new File(
1009: this Test.getWorkingCopy(), "A/D/H/chi").exists());
1010: assertFalse("failed to remove unversioned file", new File(
1011: this Test.getWorkingCopy(), "A/C/sigma").exists());
1012: assertFalse("failed to remove unmodified file", new File(
1013: this Test.getWorkingCopy(), "A/B/E/alpha").exists());
1014: file = new File(this Test.getWorkingCopy(), "A/B/F");
1015: assertTrue("removed versioned dir", file.exists()
1016: && file.isDirectory());
1017: assertFalse("failed to remove unversioned dir", new File(
1018: this Test.getWorkingCopy(), "A/C/Q").exists());
1019: assertFalse("failed to remove added dir", new File(this Test
1020: .getWorkingCopy(), "A/B/X").exists());
1021:
1022: // delete unversioned file foo
1023: file = new File(this Test.getWCPath(), "foo");
1024: pw = new PrintWriter(new FileOutputStream(file));
1025: pw.print("unversioned foo");
1026: pw.close();
1027: client.remove(new String[] { file.getAbsolutePath() }, null,
1028: true);
1029: assertFalse("failed to remove unversioned file foo", file
1030: .exists());
1031:
1032: try {
1033: // delete non-existant file foo
1034: client.remove(new String[] { file.getAbsolutePath() },
1035: null, true);
1036: fail("missing exception");
1037: } catch (ClientException expected) {
1038: }
1039:
1040: // delete file iota in the repository
1041: addExpectedCommitItem(null, this Test.getUrl(), "iota",
1042: NodeKind.none, CommitItemStateFlags.Delete);
1043: client.remove(new String[] { this Test.getUrl() + "/iota" },
1044: "delete iota URL", false);
1045: }
1046:
1047: public void testBasicCheckoutDeleted() throws Throwable {
1048: // create working copy
1049: OneTest this Test = new OneTest();
1050:
1051: // delete A/D and its content
1052: client.remove(new String[] { this Test.getWCPath() + "/A/D" },
1053: null, true);
1054: this Test.getWc().setItemTextStatus("A/D", Status.Kind.deleted);
1055: this Test.getWc()
1056: .setItemTextStatus("A/D/G", Status.Kind.deleted);
1057: this Test.getWc().setItemTextStatus("A/D/G/rho",
1058: Status.Kind.deleted);
1059: this Test.getWc().setItemTextStatus("A/D/G/pi",
1060: Status.Kind.deleted);
1061: this Test.getWc().setItemTextStatus("A/D/G/tau",
1062: Status.Kind.deleted);
1063: this Test.getWc()
1064: .setItemTextStatus("A/D/H", Status.Kind.deleted);
1065: this Test.getWc().setItemTextStatus("A/D/H/chi",
1066: Status.Kind.deleted);
1067: this Test.getWc().setItemTextStatus("A/D/H/psi",
1068: Status.Kind.deleted);
1069: this Test.getWc().setItemTextStatus("A/D/H/omega",
1070: Status.Kind.deleted);
1071: this Test.getWc().setItemTextStatus("A/D/gamma",
1072: Status.Kind.deleted);
1073:
1074: // check the working copy status
1075: this Test.checkStatus();
1076:
1077: // commit the change
1078: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1079: "A/D", NodeKind.dir, CommitItemStateFlags.Delete);
1080: assertEquals("wrong revision from commit", client.commit(
1081: new String[] { this Test.getWCPath() }, "log message",
1082: true), 2);
1083: this Test.getWc().removeItem("A/D");
1084: this Test.getWc().removeItem("A/D/G");
1085: this Test.getWc().removeItem("A/D/G/rho");
1086: this Test.getWc().removeItem("A/D/G/pi");
1087: this Test.getWc().removeItem("A/D/G/tau");
1088: this Test.getWc().removeItem("A/D/H");
1089: this Test.getWc().removeItem("A/D/H/chi");
1090: this Test.getWc().removeItem("A/D/H/psi");
1091: this Test.getWc().removeItem("A/D/H/omega");
1092: this Test.getWc().removeItem("A/D/gamma");
1093:
1094: // check the working copy status
1095: this Test.checkStatus();
1096:
1097: // check out the previous revision
1098: client.checkout(this Test.getUrl() + "/A/D", this Test
1099: .getWCPath()
1100: + "/new_D", new Revision.Number(1), true);
1101: }
1102:
1103: /**
1104: * Test if Subversion will detect the change of a file to a direcory
1105: * @throws Throwable
1106: */
1107: public void testBasicNodeKindChange() throws Throwable {
1108: // create working copy
1109: OneTest this Test = new OneTest();
1110:
1111: // remove A/D/gamma
1112: client.remove(new String[] { this Test.getWCPath()
1113: + "/A/D/gamma" }, null, false);
1114: this Test.getWc().setItemTextStatus("A/D/gamma",
1115: Status.Kind.deleted);
1116:
1117: // check the working copy status
1118: this Test.checkStatus();
1119:
1120: try {
1121: // creating a directory in the place of the deleted file should
1122: // fail
1123: client.mkdir(new String[] { this Test.getWCPath()
1124: + "/A/D/gamma" }, null);
1125: fail("can change node kind");
1126: } catch (ClientException e) {
1127:
1128: }
1129:
1130: // check the working copy status
1131: this Test.checkStatus();
1132:
1133: // commit the deletion
1134: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1135: "A/D/gamma", NodeKind.file, CommitItemStateFlags.Delete);
1136: assertEquals("wrong revision number from commit", client
1137: .commit(new String[] { this Test.getWCPath() },
1138: "log message", true), 2);
1139: this Test.getWc().removeItem("A/D/gamma");
1140:
1141: // check the working copy status
1142: this Test.checkStatus();
1143:
1144: try {
1145: // creating a directory in the place of the deleted file should
1146: // still fail
1147: client.mkdir(new String[] { this Test.getWCPath()
1148: + "/A/D/gamma" }, null);
1149: fail("can change node kind");
1150: } catch (ClientException e) {
1151:
1152: }
1153:
1154: // check the working copy status
1155: this Test.checkStatus();
1156:
1157: // update the working copy
1158: client.update(this Test.getWCPath(), null, true);
1159:
1160: // check the working copy status
1161: this Test.checkStatus();
1162:
1163: // now creating the directory should succeed
1164: client.mkdir(
1165: new String[] { this Test.getWCPath() + "/A/D/gamma" },
1166: null);
1167: this Test.getWc().addItem("A/D/gamma", null);
1168: this Test.getWc().setItemTextStatus("A/D/gamma",
1169: Status.Kind.added);
1170:
1171: // check the working copy status
1172: this Test.checkStatus();
1173: }
1174:
1175: /**
1176: * Test the basic SVNClient.import functionality
1177: * @throws Throwable
1178: */
1179: public void testBasicImport() throws Throwable {
1180: // create the working copy
1181: OneTest this Test = new OneTest();
1182:
1183: // create new_file
1184: File file = new File(this Test.getWCPath(), "new_file");
1185: PrintWriter pw = new PrintWriter(new FileOutputStream(file));
1186: pw.print("some text");
1187: pw.close();
1188:
1189: // import new_file info dirA/dirB/newFile
1190: addExpectedCommitItem(this Test.getWCPath(), null, "new_file",
1191: NodeKind.none, CommitItemStateFlags.Add);
1192: client.doImport(file.getAbsolutePath(), this Test.getUrl()
1193: + "/dirA/dirB/new_file", "log message for new import",
1194: true);
1195:
1196: // delete new_file
1197: file.delete();
1198:
1199: // update the working
1200: assertEquals("wrong revision from update", client.update(
1201: this Test.getWCPath(), null, true), 2);
1202: this Test.getWc().addItem("dirA", null);
1203: this Test.getWc().setItemWorkingCopyRevision("dirA", 2);
1204: this Test.getWc().addItem("dirA/dirB", null);
1205: this Test.getWc().setItemWorkingCopyRevision("dirA/dirB", 2);
1206: this Test.getWc().addItem("dirA/dirB/new_file", "some text");
1207: this Test.getWc().setItemWorkingCopyRevision(
1208: "dirA/dirB/new_file", 2);
1209:
1210: // test the working copy status
1211: this Test.checkStatus();
1212: }
1213:
1214: /**
1215: * test the basic SVNClient.fileContent functionality
1216: * @throws Throwable
1217: */
1218: public void testBasicCat() throws Throwable {
1219: // create the working copy
1220: OneTest this Test = new OneTest();
1221:
1222: // modify A/mu
1223: File mu = new File(this Test.getWorkingCopy(), "A/mu");
1224: PrintWriter pw = new PrintWriter(new FileOutputStream(mu, true));
1225: pw.print("some text");
1226: pw.close();
1227: // get the content from the repository
1228: byte[] content = client.fileContent(this Test.getWCPath()
1229: + "/A/mu", null);
1230: byte[] testContent = this Test.getWc().getItemContent("A/mu")
1231: .getBytes();
1232:
1233: // the content should be the same
1234: assertTrue("content changed", Arrays.equals(content,
1235: testContent));
1236: }
1237:
1238: /**
1239: * test the basic SVNClient.fileContent functionality
1240: * @throws Throwable
1241: */
1242: public void testBasicCatStream() throws Throwable {
1243: // create the working copy
1244: OneTest this Test = new OneTest();
1245:
1246: // modify A/mu
1247: File mu = new File(this Test.getWorkingCopy(), "A/mu");
1248: PrintWriter pw = new PrintWriter(new FileOutputStream(mu, true));
1249: pw.print("some text");
1250: pw.close();
1251: // get the content from the repository
1252: ByteArrayOutputStream baos = new ByteArrayOutputStream();
1253: client.streamFileContent(this Test.getWCPath() + "/A/mu", null,
1254: null, 100, baos);
1255:
1256: byte[] content = baos.toByteArray();
1257: byte[] testContent = this Test.getWc().getItemContent("A/mu")
1258: .getBytes();
1259:
1260: // the content should be the same
1261: assertTrue("content changed", Arrays.equals(content,
1262: testContent));
1263: }
1264:
1265: /**
1266: * test the basic SVNClient.list functionality
1267: * @throws Throwable
1268: */
1269: public void testBasicLs() throws Throwable {
1270: // create the working copy
1271: OneTest this Test = new OneTest();
1272:
1273: // list the repository root dir
1274: DirEntry[] entries = client.list(this Test.getWCPath(), null,
1275: false);
1276: this Test.getWc().check(entries, "", false);
1277:
1278: // list directory A
1279: entries = client.list(this Test.getWCPath() + "/A", null, false);
1280: this Test.getWc().check(entries, "A", false);
1281:
1282: // list directory A in BASE revision
1283: entries = client.list(this Test.getWCPath() + "/A",
1284: Revision.BASE, false);
1285: this Test.getWc().check(entries, "A", false);
1286:
1287: // list file A/mu
1288: entries = client.list(this Test.getWCPath() + "/A/mu", null,
1289: false);
1290: this Test.getWc().check(entries, "A/mu");
1291: }
1292:
1293: /**
1294: * test the basis SVNClient.add functionality with files that should be
1295: * ignored
1296: * @throws Throwable
1297: */
1298: public void testBasicAddIgnores() throws Throwable {
1299: // create working copy
1300: OneTest this Test = new OneTest();
1301:
1302: // create dir
1303: File dir = new File(this Test.getWorkingCopy(), "dir");
1304: dir.mkdir();
1305:
1306: // create dir/foo.c
1307: File fileC = new File(dir, "foo.c");
1308: new FileOutputStream(fileC).close();
1309:
1310: // create dir/foo.o (should be ignored)
1311: File fileO = new File(dir, "foo.o");
1312: new FileOutputStream(fileO).close();
1313:
1314: // add dir
1315: client.add(dir.getAbsolutePath(), true);
1316: this Test.getWc().addItem("dir", null);
1317: this Test.getWc().setItemTextStatus("dir", Status.Kind.added);
1318: this Test.getWc().addItem("dir/foo.c", "");
1319: this Test.getWc().setItemTextStatus("dir/foo.c",
1320: Status.Kind.added);
1321: this Test.getWc().addItem("dir/foo.o", "");
1322: this Test.getWc().setItemTextStatus("dir/foo.o",
1323: Status.Kind.ignored);
1324: this Test.getWc().setItemNodeKind("dir/foo.o", NodeKind.unknown);
1325:
1326: // test the working copy status
1327: this Test.checkStatus();
1328: }
1329:
1330: /**
1331: * test the basis SVNClient.import functionality with files that should be
1332: * ignored
1333: * @throws Throwable
1334: */
1335: public void testBasicImportIgnores() throws Throwable {
1336: // create working copy
1337: OneTest this Test = new OneTest();
1338:
1339: // create dir
1340: File dir = new File(this Test.getWorkingCopy(), "dir");
1341: dir.mkdir();
1342:
1343: // create dir/foo.c
1344: File fileC = new File(dir, "foo.c");
1345: new FileOutputStream(fileC).close();
1346:
1347: // create dir/foo.o (should be ignored)
1348: File fileO = new File(dir, "foo.o");
1349: new FileOutputStream(fileO).close();
1350:
1351: // import dir
1352: addExpectedCommitItem(this Test.getWCPath(), null, "dir",
1353: NodeKind.none, CommitItemStateFlags.Add);
1354: client.doImport(dir.getAbsolutePath(), this Test.getUrl()
1355: + "/dir", "log message for import", true);
1356:
1357: // remove dir
1358: removeDirectoryWithContent(dir);
1359:
1360: // udpate the working copy
1361: assertEquals("wrong revision from update", 2, client.update(
1362: this Test.getWCPath(), null, true));
1363: this Test.getWc().addItem("dir", null);
1364: this Test.getWc().addItem("dir/foo.c", "");
1365:
1366: // test the working copy status
1367: this Test.checkStatus();
1368: }
1369:
1370: /**
1371: * test the basic SVNClient.info functionality
1372: * @throws Throwable
1373: */
1374: public void testBasicInfo() throws Throwable {
1375: // create the working copy
1376: OneTest this Test = new OneTest();
1377:
1378: // get the item information and test it
1379: Info info = client.info(this Test.getWCPath() + "/A/mu");
1380: assertEquals("wrong revision from info", 1, info
1381: .getLastChangedRevision());
1382: assertEquals("wrong schedule kind from info",
1383: ScheduleKind.normal, info.getSchedule());
1384: assertEquals("wrong node kind from info", NodeKind.file, info
1385: .getNodeKind());
1386: }
1387:
1388: /**
1389: * test the basic SVNClient.logMessage functionality
1390: * @throws Throwable
1391: */
1392: public void testBasicLogMessage() throws Throwable {
1393: // create the working copy
1394: OneTest this Test = new OneTest();
1395:
1396: // get the commit message of the initial import and test it
1397: LogMessage lm[] = client.logMessages(this Test.getWCPath(),
1398: null, null, false, true);
1399: assertEquals("wrong number of objects", 1, lm.length);
1400: assertEquals("wrong message", "Log Message", lm[0].getMessage());
1401: assertEquals("wrong revision", 1, lm[0].getRevisionNumber());
1402: assertEquals("wrong user", "jrandom", lm[0].getAuthor());
1403: assertNotNull("changed paths set", lm[0].getChangedPaths());
1404: ChangePath cp[] = lm[0].getChangedPaths();
1405: assertEquals("wrong number of chang pathes", 20, cp.length);
1406: assertEquals("wrong path", "/A", cp[0].getPath());
1407: assertEquals("wrong copy source rev", -1, cp[0]
1408: .getCopySrcRevision());
1409: assertNull("wrong copy source path", cp[0].getCopySrcPath());
1410: assertEquals("wrong action", 'A', cp[0].getAction());
1411: }
1412:
1413: /**
1414: * test the basic SVNClient.getVersionInfo functionality
1415: * @throws Throwable
1416: * @since 1.2
1417: */
1418: public void testBasicVersionInfo() throws Throwable {
1419: // create the working copy
1420: OneTest this Test = new OneTest();
1421: assertEquals("wrong version info", "1", client.getVersionInfo(
1422: this Test.getWCPath(), null, false));
1423: }
1424:
1425: /**
1426: * test the baisc SVNClient locking functionality
1427: * @throws Throwable
1428: * @since 1.2
1429: */
1430: public void testBasicLocking() throws Throwable {
1431: // build the first working copy
1432: OneTest this Test = new OneTest();
1433:
1434: client.propertySet(this Test.getWCPath() + "/A/mu",
1435: PropertyData.NEEDS_LOCK, "*", false);
1436:
1437: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1438: "A/mu", NodeKind.file, CommitItemStateFlags.PropMods);
1439: assertEquals("bad revision number on commit", 2, client.commit(
1440: new String[] { this Test.getWCPath() }, "message", true));
1441: File f = new File(this Test.getWCPath() + "/A/mu");
1442: assertEquals("file should be read only now", false, f
1443: .canWrite());
1444: client.lock(new String[] { this Test.getWCPath() + "/A/mu" },
1445: "comment", false);
1446: assertEquals("file should be read write now", true, f
1447: .canWrite());
1448: client.unlock(new String[] { this Test.getWCPath() + "/A/mu" },
1449: false);
1450: assertEquals("file should be read only now", false, f
1451: .canWrite());
1452: client.lock(new String[] { this Test.getWCPath() + "/A/mu" },
1453: "comment", false);
1454: assertEquals("file should be read write now", true, f
1455: .canWrite());
1456: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1457: "A/mu", NodeKind.file, 0);
1458: assertEquals("rev number from commit", -1, client.commit(
1459: new String[] { this Test.getWCPath() }, "message", true));
1460: assertEquals("file should be read write now", true, f
1461: .canWrite());
1462:
1463: try {
1464: // Attempt to lock an invalid path
1465: client.lock(
1466: new String[] { this Test.getWCPath() + "/A/mu2" },
1467: "comment", false);
1468: fail("missing exception");
1469: } catch (ClientException expected) {
1470: }
1471: }
1472:
1473: /**
1474: * test the baisc SVNClient.info2 functionality
1475: * @throws Throwable
1476: * @since 1.2
1477: */
1478: public void testBasicInfo2() throws Throwable {
1479: // build the first working copy
1480: OneTest this Test = new OneTest();
1481:
1482: Info2[] infos = client.info2(this Test.getWCPath(), null, null,
1483: false);
1484: assertEquals("this should return 1 info object", 1,
1485: infos.length);
1486: infos = client.info2(this Test.getWCPath(), null, null, true);
1487: assertEquals("this should return 21 info objects", 21,
1488: infos.length);
1489: infos = client.info2(this Test.getWCPath(), new Revision.Number(
1490: 1), new Revision.Number(1), true);
1491: assertEquals("this should return 21 info objects", 21,
1492: infos.length);
1493: }
1494:
1495: /**
1496: * test the basic SVNClient.merge functionality
1497: * @throws Throwable
1498: * @since 1.2
1499: */
1500: public void testBasicMerge() throws Throwable {
1501: // build the test setup
1502: OneTest this Test = new OneTest();
1503:
1504: // create branches directory in the repository
1505: addExpectedCommitItem(null, this Test.getUrl(), "branches",
1506: NodeKind.none, CommitItemStateFlags.Add);
1507: client.mkdir(new String[] { this Test.getUrl() + "/branches" },
1508: "log_msg");
1509:
1510: // copy A to branches
1511: addExpectedCommitItem(null, this Test.getUrl(), "branches/A",
1512: NodeKind.none, CommitItemStateFlags.Add);
1513: client.copy(this Test.getUrl() + "/A", this Test.getUrl()
1514: + "/branches/A", "create A branch", Revision.HEAD);
1515:
1516: // update the WC so that it has the branches folder
1517: client.update(this Test.getWCPath(), Revision.HEAD, true);
1518:
1519: // modify file A/mu
1520: File mu = new File(this Test.getWorkingCopy(), "A/mu");
1521: PrintWriter muPW = new PrintWriter(new FileOutputStream(mu,
1522: true));
1523: muPW.print("appended mu text");
1524: muPW.close();
1525: this Test.getWc().setItemWorkingCopyRevision("A/mu", 4);
1526: this Test.getWc().setItemContent(
1527: "A/mu",
1528: this Test.getWc().getItemContent("A/mu")
1529: + "appended mu text");
1530: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1531: "A/mu", NodeKind.file, CommitItemStateFlags.TextMods);
1532:
1533: // modify file A/D/G/rho
1534: File rho = new File(this Test.getWorkingCopy(), "A/D/G/rho");
1535: PrintWriter rhoPW = new PrintWriter(new FileOutputStream(rho,
1536: true));
1537: rhoPW.print("new appended text for rho");
1538: rhoPW.close();
1539: this Test.getWc().setItemWorkingCopyRevision("A/D/G/rho", 4);
1540: this Test.getWc().setItemContent(
1541: "A/D/G/rho",
1542: this Test.getWc().getItemContent("A/D/G/rho")
1543: + "new appended text for rho");
1544: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1545: "A/D/G/rho", NodeKind.file,
1546: CommitItemStateFlags.TextMods);
1547: // commit the changes
1548: assertEquals("wrong revision number from commit", client
1549: .commit(new String[] { this Test.getWCPath() },
1550: "log msg", true), 4);
1551:
1552: // merge changes in A to branches/A
1553: String branchPath = this Test.getWCPath() + "/branches/A";
1554: String modUrl = this Test.getUrl() + "/A";
1555: // test --dry-run
1556: client.merge(modUrl, new Revision.Number(2), modUrl,
1557: Revision.HEAD, branchPath, false, true, false, true);
1558:
1559: // now do the real merge
1560: client.merge(modUrl, new Revision.Number(2), modUrl,
1561: Revision.HEAD, branchPath, false, true, false, false);
1562:
1563: // commit the changes so that we can verify merge
1564: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1565: "branches/A/mu", NodeKind.file,
1566: CommitItemStateFlags.TextMods);
1567: addExpectedCommitItem(this Test.getWCPath(), this Test.getUrl(),
1568: "branches/A/D/G/rho", NodeKind.file,
1569: CommitItemStateFlags.TextMods);
1570: assertEquals("wrong revision number from commit", client
1571: .commit(new String[] { this Test.getWCPath() },
1572: "log msg", true), 5);
1573:
1574: }
1575:
1576: /**
1577: * test the basic SVNClient.isAdminDirectory functionality
1578: * @throws Throwable
1579: * @since 1.2
1580: */
1581: public void testBasicIsAdminDirectory() throws Throwable {
1582: // build the test setup
1583: OneTest this Test = new OneTest();
1584: Notify2 notify = new Notify2() {
1585: public void onNotify(NotifyInformation info) {
1586: client.isAdminDirectory(".svn");
1587: }
1588: };
1589: client.notification2(notify);
1590: // update the test
1591: assertEquals("wrong revision number from update", client
1592: .update(this Test.getWCPath(), null, true), 1);
1593: }
1594:
1595: public void testBasicCancelOperation() throws Throwable {
1596: // build the test setup
1597: OneTest this Test = new OneTest();
1598: Notify2 notify = new Notify2() {
1599: public void onNotify(NotifyInformation info) {
1600: try {
1601: client.cancelOperation();
1602: } catch (ClientException e) {
1603: fail(e.getMessage());
1604: }
1605: }
1606: };
1607: client.notification2(notify);
1608: // update the test to try to cancel an operation
1609: try {
1610: client.update(this Test.getWCPath(), null, true);
1611: fail("missing exception for canceled operation");
1612: } catch (ClientException e) {
1613: // this is expected
1614: }
1615: }
1616: }
|