📄 basictests.java
字号:
muPW = new PrintWriter(new FileOutputStream(mu, true));
muContent = thisTest.getWc().getItemContent("A/mu");
muPW.print(" Appended to line 10 of mu");
muContent = muContent + " Appended to line 10 of mu";
muPW.close();
thisTest.getWc().setItemWorkingCopyRevision("A/mu", 3);
thisTest.getWc().setItemContent("A/mu", muContent);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
// change the last line of A/mu in the first working copy
rhoPW = new PrintWriter(new FileOutputStream(rho, true));
rhoContent = thisTest.getWc().getItemContent("A/D/G/rho");
rhoPW.print(" Appended to line 10 of rho");
rhoContent = rhoContent + " Appended to line 10 of rho";
rhoPW.close();
thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 3);
thisTest.getWc().setItemContent("A/D/G/rho", rhoContent);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/D/G/rho", NodeKind.file,
CommitItemStateFlags.TextMods);
// commit these changes to the repository
assertEquals("wrong revision number from commit",
client.commit(new String[]{thisTest.getWCPath()}, "log msg",
true), 3);
// check the status of the first working copy
thisTest.checkStatus();
// modify the first line of A/mu in the backup working copy
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";
for (int i = 2; i < 11; i++)
{
muPW.print("\nThis is line " + i + " in mu");
muContent = muContent + "\nThis is line " + i + " in mu";
}
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);
// modify the first line of A/D/G/rho in the backup working copy
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++)
{
rhoPW.print("\nThis is line " + i + " in rho");
rhoContent = rhoContent + "\nThis is line " + i + " in rho";
}
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);
// update the backup working copy
assertEquals("wrong revision number from update",
client.update(backupTest.getWCPath(), null, true), 3);
// check the status of the backup working copy
backupTest.checkStatus();
}
/**
* test the basic SVNClient.update functionality with concurrent changes
* in the repository and the working copy that generate conflicts
* @throws Throwable
*/
public void testBasicConflict() throws Throwable
{
// build the first working copy
OneTest thisTest = new OneTest();
// copy the first working copy to the backup working copy
OneTest backupTest = thisTest.copy(".backup");
// append a line to A/mu in the first working copy
File mu = new File(thisTest.getWorkingCopy(), "A/mu");
PrintWriter muPW = new PrintWriter(new FileOutputStream(mu, true));
String muContent = thisTest.getWc().getItemContent("A/mu");
muPW.print("\nOriginal appended text for mu");
muContent = muContent + "\nOriginal appended text for mu";
muPW.close();
thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
thisTest.getWc().setItemContent("A/mu", muContent);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
// append a line to A/D/G/rho in the first working copy
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");
rhoPW.print("\nOriginal appended text for rho");
rhoContent = rhoContent + "\nOriginal appended text for rho";
rhoPW.close();
thisTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
thisTest.getWc().setItemContent("A/D/G/rho", rhoContent);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/D/G/rho", NodeKind.file,
CommitItemStateFlags.TextMods);
// commit the changes in the first working copy
assertEquals("wrong revision number from commit",
client.commit(new String[]{thisTest.getWCPath()}, "log msg",
true), 2);
// test the status of the working copy after the commit
thisTest.checkStatus();
// append a different line to A/mu in the backup working copy
mu = new File(backupTest.getWorkingCopy(), "A/mu");
muPW = new PrintWriter(new FileOutputStream(mu, true));
muPW.print("\nConflicting appended text for mu");
muContent = "<<<<<<< .mine\nThis is the file 'mu'.\n"+
"Conflicting appended text for mu=======\n"+
"This is the file 'mu'.\n"+
"Original appended text for mu>>>>>>> .r2";
muPW.close();
backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
backupTest.getWc().setItemContent("A/mu", muContent);
backupTest.getWc().setItemTextStatus("A/mu", Status.Kind.conflicted);
backupTest.getWc().addItem("A/mu.r1", "");
backupTest.getWc().setItemNodeKind("A/mu.r1", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/mu.r1",
Status.Kind.unversioned);
backupTest.getWc().addItem("A/mu.r2", "");
backupTest.getWc().setItemNodeKind("A/mu.r2", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/mu.r2",
Status.Kind.unversioned);
backupTest.getWc().addItem("A/mu.mine", "");
backupTest.getWc().setItemNodeKind("A/mu.mine", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/mu.mine",
Status.Kind.unversioned);
// append a different line to A/D/G/rho in the backup working copy
rho = new File(backupTest.getWorkingCopy(), "A/D/G/rho");
rhoPW = new PrintWriter(new FileOutputStream(rho, true));
rhoPW.print("\nConflicting appended text for rho");
rhoContent = "<<<<<<< .mine\nThis is the file 'rho'.\n"+
"Conflicting appended text for rho=======\n"+
"his is the file 'rho'.\n"+
"Original appended text for rho>>>>>>> .r2";
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/D/G/rho.r1", "");
backupTest.getWc().setItemNodeKind("A/D/G/rho.r1", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/D/G/rho.r1",
Status.Kind.unversioned);
backupTest.getWc().addItem("A/D/G/rho.r2", "");
backupTest.getWc().setItemNodeKind("A/D/G/rho.r2", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/D/G/rho.r2",
Status.Kind.unversioned);
backupTest.getWc().addItem("A/D/G/rho.mine", "");
backupTest.getWc().setItemNodeKind("A/D/G/rho.mine", NodeKind.unknown);
backupTest.getWc().setItemTextStatus("A/D/G/rho.mine",
Status.Kind.unversioned);
// update the backup working copy from the repository
assertEquals("wrong revision number from update",
client.update(backupTest.getWCPath(), null, true), 2);
// check the status of the backup working copy
backupTest.checkStatus();
// flag A/mu as resolved
client.resolved(backupTest.getWCPath()+"/A/mu",false);
backupTest.getWc().setItemTextStatus("A/mu", Status.Kind.modified);
backupTest.getWc().removeItem("A/mu.r1");
backupTest.getWc().removeItem("A/mu.r2");
backupTest.getWc().removeItem("A/mu.mine");
// flag A/D/G/rho as resolved
client.resolved(backupTest.getWCPath()+"/A/D/G/rho",false);
backupTest.getWc().setItemTextStatus("A/D/G/rho", Status.Kind.modified);
backupTest.getWc().removeItem("A/D/G/rho.r1");
backupTest.getWc().removeItem("A/D/G/rho.r2");
backupTest.getWc().removeItem("A/D/G/rho.mine");
// check the status after the conflicts are flaged as resolved
backupTest.checkStatus();
}
/**
* test the basic SVNClient.cleanup functionality
* @throws Throwable
*/
public void testBasicCleanup() throws Throwable
{
// create a test working copy
OneTest thisTest = new OneTest();
// create a lock file in A/B
File adminLock = new File(thisTest.getWorkingCopy(),"A/B/.svn/lock");
PrintWriter pw = new PrintWriter(new FileOutputStream(adminLock));
pw.print("stop looking!");
pw.close();
thisTest.getWc().setItemIsLocked("A/B", true);
// create a lock file in A/D/G
adminLock = new File(thisTest.getWorkingCopy(),"A/D/G/.svn/lock");
pw = new PrintWriter(new FileOutputStream(adminLock));
pw.print("stop looking!");
pw.close();
thisTest.getWc().setItemIsLocked("A/D/G", true);
// create a lock file in A/C
adminLock = new File(thisTest.getWorkingCopy(),"A/C/.svn/lock");
pw = new PrintWriter(new FileOutputStream(adminLock));
pw.print("stop looking!");
pw.close();
thisTest.getWc().setItemIsLocked("A/C", true);
// test the status of the working copy
thisTest.checkStatus();
// run cleanup
client.cleanup(thisTest.getWCPath());
thisTest.getWc().setItemIsLocked("A/B", false);
thisTest.getWc().setItemIsLocked("A/D/G", false);
thisTest.getWc().setItemIsLocked("A/C", false);
// test the status of the working copy
thisTest.checkStatus();
}
/**
* Test the basic SVNClient.revert functionality
* @throws Throwable
*/
public void testBasicRevert() throws Throwable
{
// create a test working copy
OneTest thisTest = new OneTest();
// modify A/B/E/beta
File file = new File(thisTest.getWorkingCopy(), "A/B/E/beta");
PrintWriter pw = new PrintWriter(new FileOutputStream(file, true));
pw.print("Added some text to 'beta'.");
pw.close();
thisTest.getWc().setItemTextStatus("A/B/E/beta", Status.Kind.modified);
// modify iota
file = new File(thisTest.getWorkingCopy(), "iota");
pw = new PrintWriter(new FileOutputStream(file, true));
pw.print("Added some text to 'iota'.");
pw.close();
thisTest.getWc().setItemTextStatus("iota", Status.Kind.modified);
// modify A/D/G/rho
file = new File(thisTest.getWorkingCopy(), "A/D/G/rho");
pw = new PrintWriter(new FileOutputStream(file, true));
pw.print("Added some text to 'rho'.");
pw.close();
thisTest.getWc().setItemTextStatus("A/D/G/rho", Status.Kind.modified);
// create new file A/D/H/zeta and add it to subversion
file = new File(thisTest.getWorkingCopy(), "A/D/H/zeta");
pw = new PrintWriter(new FileOutputStream(file, true));
pw.print("Added some text to 'zeta'.");
pw.close();
thisTest.getWc().addItem("A/D/H/zeta", "Added some text to 'zeta'.");
thisTest.getWc().setItemTextStatus("A/D/H/zeta", Status.Kind.added);
client.add(file.getAbsolutePath(), false);
// test the status of the working copy
thisTest.checkStatus();
// revert the changes
client.revert(thisTest.getWCPath()+"/A/B/E/beta", false);
thisTest.getWc().setItemTextStatus("A/B/E/beta", Status.Kind.normal);
client.revert(thisTest.getWCPath()+"/iota", false);
thisTest.getWc().setItemTextStatus("iota", Status.Kind.normal);
client.revert(thisTest.getWCPath()+"/A/D/G/rho", false);
thisTest.getWc().setItemTextStatus("A/D/G/rho", Status.Kind.normal);
client.revert(thisTest.getWCPath()+"/A/D/H/zeta", false);
thisTest.getWc().setItemTextStatus("A/D/H/zeta",
Status.Kind.unversioned);
thisTest.getWc().setItemNodeKind("A/D/H/zeta", NodeKind.unknown);
// test the status of the working copy
thisTest.checkStatus();
// delete A/B/E/beta and revert the change
file = new File(thisTest.getWorkingCopy(), "A/B/E/beta");
file.delete();
client.revert(file.getAbsolutePath(), false);
// resurected file should not be readonly
assertTrue("reverted file is not readonly",
file.canWrite()&& file.canRead());
// test the status of the working copy
thisTest.checkStatus();
// create & add the directory X
client.mkdir(new String[] {thisTest.getWCPath()+"/X"}, null);
thisTest.getWc().addItem("X", null);
thisTest.getWc().setItemTextStatus("X", Status.Kind.added);
// test the status of the working copy
thisTest.checkStatus();
// remove & revert X
removeDirectoryWithContent(new File(thisTest.getWorkingCopy(), "X"));
client.revert(thisTest.getWCPath()+"/X", false);
thisTest.getWc().removeItem("X");
// test the status of the working copy
thisTest.checkStatus();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -