Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
/**
* Setup a test with a WC. In the repository, create a
* "/branches" directory, with a branch of "/A" underneath it.
* Update the WC to reflect these modifications.
* @return This test.
*/
private OneTest setupAndPerformMerge()
throws Exception
{
OneTest thisTest = new OneTest();
// Verify that there are initially no potential merge sources.
String[] suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath(),
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(0, suggestedSrcs.length);
// create branches directory in the repository (r2)
addExpectedCommitItem(null, thisTest.getUrl(), "branches",
NodeKind.none, CommitItemStateFlags.Add);
client.mkdir(new String[]{thisTest.getUrl() + "/branches"}, "log_msg");
// copy A to branches (r3)
addExpectedCommitItem(null, thisTest.getUrl(), "branches/A",
NodeKind.none, CommitItemStateFlags.Add);
client.copy(thisTest.getUrl() + "/A", thisTest.getUrl() +
"/branches/A", "create A branch", Revision.HEAD);
// update the WC (to r3) so that it has the branches folder
client.update(thisTest.getWCPath(), Revision.HEAD, true);
return thisTest;
}
/**
* Test the {@link SVNClientInterface.diff()} APIs.
* @since 1.5
*/
public void testDiff()
throws SubversionException, IOException
{
OneTest thisTest = new OneTest(true);
File diffOutput = new File(super.localTmp, thisTest.testName);
final String NL = System.getProperty("line.separator");
final String sepLine =
"===================================================================" + NL;
final String underSepLine =
"___________________________________________________________________" + NL;
final String expectedDiffBody =
"@@ -1 +1 @@" + NL +
"-This is the file 'iota'." + NL +
"\\ No newline at end of file" + NL +
"+This is the file 'mu'." + NL +
"\\ No newline at end of file" + NL;
final String iotaPath = thisTest.getWCPath().replace('\\', '/') + "/iota";
final String wcPath = fileToSVNPath(new File(thisTest.getWCPath()),
false);
// make edits to iota
PrintWriter writer = new PrintWriter(new FileOutputStream(iotaPath));
writer.print("This is the file 'mu'.");
writer.flush();
writer.close();
/*
* This test does tests with and without svn:eol-style set to native
* We will first run all of the tests where this does not matter so
* that they are not run twice.
*/
// Two-path diff of URLs.
String expectedDiffOutput = "Index: iota" + NL + sepLine +
"--- iota\t(.../iota)\t(revision 1)" + NL +
"+++ iota\t(.../A/mu)\t(revision 1)" + NL +
expectedDiffBody;
client.diff(thisTest.getUrl() + "/iota", Revision.HEAD,
thisTest.getUrl() + "/A/mu", Revision.HEAD,
diffOutput.getPath(), false, true, true, false);
assertFileContentsEquals("Unexpected diff output in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
// Test relativeToDir fails with urls. */
try
{
client.diff(thisTest.getUrl() + "/iota", Revision.HEAD,
thisTest.getUrl() + "/A/mu", Revision.HEAD,
thisTest.getUrl(), diffOutput.getPath(),
Depth.infinity, null, true, true, false);
fail("This test should fail becaus the relativeToDir parameter " +
"does not work with URLs");
}
catch (Exception ignored)
{
}
/* Testing the expected failure when relativeToDir is not a parent
path of the target. */
try
{
client.diff(iotaPath, Revision.BASE, iotaPath, Revision.WORKING,
"/non/existent/path", diffOutput.getPath(),
Depth.infinity, null, true, true, false);
fail("This test should fail because iotaPath is not a child of " +
"the relativeToDir parameter");
}
catch (Exception ignored)
{
}
// Test diff with a relative path on a directory with prop
// changes.
String aPath = fileToSVNPath(new File(thisTest.getWCPath() + "/A"),
false);
expectedDiffOutput = "Index: A" + NL + sepLine +
"--- A\t(revision 1)" + NL +
"+++ A\t(working copy)" + NL +
NL + "Property changes on: A" + NL +
underSepLine +
"Added: testprop" + NL +
"## -0,0 +1 ##" + NL +
"+Test property value." + NL;
client.propertySet(aPath, "testprop", "Test property value." + NL,
false);
client.diff(aPath, Revision.BASE, aPath, Revision.WORKING, wcPath,
diffOutput.getPath(), Depth.infinity, null, true, true,
false);
assertFileContentsEquals("Unexpected diff output in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
// Test diff where relativeToDir and path are the same.
expectedDiffOutput = "Index: ." + NL + sepLine +
"--- .\t(revision 1)" + NL +
"+++ .\t(working copy)" + NL +
NL + "Property changes on: ." + NL +
underSepLine +
"Added: testprop" + NL +
"## -0,0 +1 ##" + NL +
"+Test property value." + NL;
client.propertySet(aPath, "testprop", "Test property value." + NL,
false);
client.diff(aPath, Revision.BASE, aPath, Revision.WORKING, aPath,
diffOutput.getPath(), Depth.infinity, null, true, true,
false);
assertFileContentsEquals("Unexpected diff output in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
/*
* The rest of these tests are run twice. The first time
* without svn:eol-style set and the second time with the
* property set to native. This is tracked by the int named
* operativeRevision. It will have a value = 2 after the
* commit which sets the property
*/
for (int operativeRevision = 1; operativeRevision < 3; operativeRevision++)
{
String revisionPrefix = "While processing operativeRevison=" + operativeRevision + ". ";
String assertPrefix = revisionPrefix + "Unexpected diff output in file '";
// Undo previous edits to working copy
client.revert(wcPath, true);
if (operativeRevision == 2) {
// Set svn:eol-style=native on iota
client.propertyCreate(iotaPath, "svn:eol-style", "native", false);
String[] paths = new String[] {iotaPath};
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "iota",NodeKind.file,
CommitItemStateFlags.PropMods);
client.commit(paths, "Set svn:eol-style to native", false);
}
// make edits to iota and set expected output.
writer = new PrintWriter(new FileOutputStream(iotaPath));
writer.print("This is the file 'mu'.");
writer.flush();
writer.close();
expectedDiffOutput = "Index: " + iotaPath + NL + sepLine +
"--- " + iotaPath + "\t(revision " + operativeRevision + ")" + NL +
"+++ " + iotaPath + "\t(working copy)" + NL +
expectedDiffBody;
try
{
// Two-path diff of WC paths.
client.diff(iotaPath, Revision.BASE,
iotaPath, Revision.WORKING,
diffOutput.getPath(), false, true, true, false);
assertFileContentsEquals(assertPrefix +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(revisionPrefix + e.getMessage());
}
try
{
// Peg revision diff of a single file.
client.diff(thisTest.getUrl() + "/iota", Revision.HEAD,
new Revision.Number(operativeRevision), Revision.HEAD,
diffOutput.getPath(), false, true, true, false);
assertFileContentsEquals(assertPrefix +
diffOutput.getPath() + '\'',
"", diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(revisionPrefix + e.getMessage());
}
// Test svn diff with a relative path.
expectedDiffOutput = "Index: iota" + NL + sepLine +
"--- iota\t(revision " + operativeRevision + ")" + NL +
"+++ iota\t(working copy)" + NL +
expectedDiffBody;
try
{
client.diff(iotaPath, Revision.BASE, iotaPath,
Revision.WORKING, wcPath, diffOutput.getPath(),
Depth.infinity, null, true, true, false);
assertFileContentsEquals(assertPrefix +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(revisionPrefix + e.getMessage());
( run in 0.435 second using v1.01-cache-2.11-cpan-754626df90b )