Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
* that execution goes down to the C layer and back.
* @throws Throwable
*/
public void testPatch() throws SubversionException, IOException
{
OneTest thisTest = new OneTest(true);
File patchInput = new File(super.localTmp, thisTest.testName);
final String NL = System.getProperty("line.separator");
final String patchText = "Index: iota" + NL +
"===================================================================" + NL +
"--- iota\t(revision 1)" + NL +
"+++ iota\t(working copy)" + NL +
"@@ -1 +1,2 @@" + NL +
" This is the file 'iota'." + NL +
"+No, this is *really* the file 'iota'." + NL;
PrintWriter writer = new PrintWriter(new FileOutputStream(patchInput));
writer.print(patchText);
writer.flush();
writer.close();
client.patch(patchInput.getAbsolutePath(),
thisTest.getWCPath().replace('\\', '/'), false, 0,
false, true, true,
new PatchCallback() {
public boolean singlePatch(String pathFromPatchfile,
String patchPath,
String rejectPath) {
// Do nothing, right now.
return false;
}
});
}
/**
* Test the {@link ISVNClient.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,
null, diffOutput.getPath(), Depth.files, null, true, true,
false, false);
assertFileContentsEquals("Unexpected diff output in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
// Test relativeToDir fails with urls. */
try
{
client.diff(thisTest.getUrl().toString() + "/iota", Revision.HEAD,
thisTest.getUrl().toString() + "/A/mu", Revision.HEAD,
thisTest.getUrl().toString(), diffOutput.getPath(),
Depth.infinity, null, true, true, false, 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, 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;
setprop(aPath, "testprop", "Test property value." + NL);
client.diff(aPath, Revision.BASE, aPath, Revision.WORKING, wcPath,
diffOutput.getPath(), Depth.infinity, null, true, true,
false, 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;
setprop(aPath, "testprop", "Test property value." + NL);
client.diff(aPath, Revision.BASE, aPath, Revision.WORKING, aPath,
diffOutput.getPath(), Depth.infinity, null, true, true,
false, 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, Depth.infinity, null);
if (operativeRevision == 2) {
// Set svn:eol-style=native on iota
setprop(iotaPath, "svn:eol-style", "native");
Set<String> paths = new HashSet<String>(1);
paths.add(iotaPath);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl().toString(), "iota",NodeKind.file,
CommitItemStateFlags.PropMods);
client.commit(paths, Depth.empty, false, false, null, null,
new ConstMsg("Set svn:eol-style to native"),
null);
}
// 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, null, diffOutput.getPath(),
Depth.files, null, true, true, false, 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, null, diffOutput.getPath(),
Depth.files, null, true, true, false, 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,
false);
assertFileContentsEquals(assertPrefix +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(revisionPrefix + e.getMessage());
}
try
{
// Test svn diff with a relative path and trailing slash.
client.diff(iotaPath, Revision.BASE, iotaPath,
Revision.WORKING, wcPath + "/",
diffOutput.getPath(), Depth.infinity, null,
true, true, false, false);
assertFileContentsEquals(assertPrefix +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(revisionPrefix + e.getMessage());
}
}
}
/**
* Test the {@link ISVNClient.diff()} with {@link DiffOptions}.
* @since 1.8
*/
public void testDiffOptions()
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 iotaPath = thisTest.getWCPath().replace('\\', '/') + "/iota";
final String wcPath = fileToSVNPath(new File(thisTest.getWCPath()),
false);
final String expectedDiffHeader =
"Index: iota" + NL + sepLine +
"--- iota\t(revision 1)" + NL +
"+++ iota\t(working copy)" + NL;
// make edits to iota
PrintWriter writer = new PrintWriter(new FileOutputStream(iotaPath));
writer.print("This is the file 'iota'.");
writer.flush();
writer.close();
try
{
final String expectedDiffOutput = expectedDiffHeader +
"@@ -1 +1 @@" + NL +
"-This is the file 'iota'." + NL +
"\\ No newline at end of file" + NL +
"+This is the file 'iota'." + NL +
"\\ No newline at end of file" + NL;
client.diff(iotaPath, Revision.BASE, iotaPath, Revision.WORKING,
wcPath, new FileOutputStream(diffOutput.getPath()),
Depth.infinity, null,
false, false, false, false, false, false, null);
assertFileContentsEquals(
"Unexpected diff output with no options in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail(e.getMessage());
}
try
{
final String expectedDiffOutput = "";
client.diff(iotaPath, Revision.BASE, iotaPath, Revision.WORKING,
wcPath, new FileOutputStream(diffOutput.getPath()),
Depth.infinity, null,
false, false, false, false, false, false,
new DiffOptions(DiffOptions.Flag.IgnoreWhitespace));
assertFileContentsEquals(
"Unexpected diff output with Flag.IgnoreWhitespace in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail("Using Flag.IgnoreWhitespace: "
+ e.getMessage());
}
try
{
final String expectedDiffOutput = "";
client.diff(iotaPath, Revision.BASE, iotaPath, Revision.WORKING,
wcPath, diffOutput.getPath(), Depth.infinity, null,
false, false, false, false, false, false,
new DiffOptions(DiffOptions.Flag.IgnoreSpaceChange));
assertFileContentsEquals(
"Unexpected diff output with Flag.IgnoreSpaceChange in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail("Using Flag.IgnoreSpaceChange: "
+ e.getMessage());
}
// make edits to iota
writer = new PrintWriter(new FileOutputStream(iotaPath));
writer.print("This is the file 'io ta'.");
writer.flush();
writer.close();
try
{
final String expectedDiffOutput = expectedDiffHeader +
"@@ -1 +1 @@" + NL +
"-This is the file 'iota'." + NL +
"\\ No newline at end of file" + NL +
"+This is the file 'io ta'." + NL +
"\\ No newline at end of file" + NL;
client.diff(iotaPath, Revision.BASE, iotaPath, Revision.WORKING,
wcPath, diffOutput.getPath(), Depth.infinity, null,
false, false, false, false, false, false,
new DiffOptions(DiffOptions.Flag.IgnoreSpaceChange));
assertFileContentsEquals(
"Unexpected diff output with Flag.IgnoreSpaceChange in file '" +
diffOutput.getPath() + '\'',
expectedDiffOutput, diffOutput);
diffOutput.delete();
}
catch (ClientException e)
{
fail("Using Flag.IgnoreSpaceChange: "
+ e.getMessage());
}
}
private void assertFileContentsEquals(String msg, String expected,
File actual)
throws IOException
{
FileReader reader = new FileReader(actual);
StringBuffer buf = new StringBuffer();
int ch;
while ((ch = reader.read()) != -1)
{
buf.append((char) ch);
}
assertEquals(msg, expected, buf.toString());
}
/**
* Test the {@link SVNClientInterface.diffSummarize()} API.
* @since 1.5
*/
public void testDiffSummarize()
throws SubversionException, IOException
{
OneTest thisTest = new OneTest(false);
DiffSummaries summaries = new DiffSummaries();
// Perform a recursive diff summary, ignoring ancestry.
client.diffSummarize(thisTest.getUrl().toString(), new Revision.Number(0),
thisTest.getUrl().toString(), Revision.HEAD, Depth.infinity,
null, false, summaries);
assertExpectedDiffSummaries(summaries);
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
// get the Info2 of the tree conflict
MyInfoCallback callback = new MyInfoCallback();
client.info2(tcTest.getWCPath() + "/A/B/E/alpha", null,
null, Depth.unknown, null, callback);
Set<ConflictDescriptor> conflicts = callback.getInfo().getConflicts();
assertNotNull("Conflict should not be null", conflicts);
ConflictDescriptor conflict = conflicts.iterator().next();
assertNotNull("Conflict should not be null", conflict);
assertNotNull("Repository UUID must be set", conflict.getSrcLeftVersion().getReposUUID());
assertEquals(conflict.getSrcLeftVersion().getNodeKind(), NodeKind.file);
assertEquals(conflict.getSrcLeftVersion().getReposURL() + "/" +
conflict.getSrcLeftVersion().getPathInRepos(), tcTest.getUrl() + "/A/B/E/alpha");
assertEquals(conflict.getSrcLeftVersion().getPegRevision(), 1L);
if (conflict.getSrcRightVersion() != null)
{
assertEquals(conflict.getSrcLeftVersion().getReposUUID(),
conflict.getSrcRightVersion().getReposUUID());
assertEquals(conflict.getSrcRightVersion().getNodeKind(), NodeKind.none);
assertEquals(conflict.getSrcRightVersion().getReposURL(), tcTest.getUrl().toString());
assertEquals(conflict.getSrcRightVersion().getPegRevision(), 2L);
}
}
/**
* Test the basic SVNClient.propertySetRemote functionality.
* @throws Throwable
*/
public void testPropEdit() throws Throwable
{
final String PROP = "abc";
final byte[] VALUE = new String("def").getBytes();
final byte[] NEWVALUE = new String("newvalue").getBytes();
// create the test working copy
OneTest thisTest = new OneTest();
Set<String> pathSet = new HashSet<String>();
// set a property on A/D/G/rho file
pathSet.clear();
pathSet.add(thisTest.getWCPath()+"/A/D/G/rho");
client.propertySetLocal(pathSet, PROP, VALUE,
Depth.infinity, null, false);
thisTest.getWc().setItemPropStatus("A/D/G/rho", Status.Kind.modified);
// test the status of the working copy
thisTest.checkStatus();
// commit the changes
checkCommitRevision(thisTest, "wrong revision number from commit", 2,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
thisTest.getWc().setItemPropStatus("A/D/G/rho", Status.Kind.normal);
// check the status of the working copy
thisTest.checkStatus();
// now edit the propval directly in the repository
long baseRev = 2L;
client.propertySetRemote(thisTest.getUrl()+"/A/D/G/rho", baseRev, PROP, NEWVALUE,
new ConstMsg("edit prop"), false, null, null);
// update the WC and verify that the property was changed
client.update(thisTest.getWCPathSet(), Revision.HEAD, Depth.infinity, false, false,
false, false);
byte[] propVal = client.propertyGet(thisTest.getWCPath()+"/A/D/G/rho", PROP, null, null);
assertEquals(new String(propVal), new String(NEWVALUE));
}
/**
* Test tolerance of unversioned obstructions when adding paths with
* {@link org.apache.subversion.javahl.SVNClient#checkout()},
* {@link org.apache.subversion.javahl.SVNClient#update()}, and
* {@link org.apache.subversion.javahl.SVNClient#doSwitch()}
* @throws IOException
* @throws SubversionException
*/
/*
This is currently commented out, because we don't have an XFail method
for JavaHL. The resolution is pending the result of issue #3680:
http://subversion.tigris.org/issues/show_bug.cgi?id=3680
public void testObstructionTolerance()
throws SubversionException, IOException
{
// build the test setup
OneTest thisTest = new OneTest();
File file;
PrintWriter pw;
// ----- TEST CHECKOUT -----
// Use export to make unversioned obstructions for a second
// WC checkout (deleting export target from previous tests
// first if it exists).
String secondWC = thisTest.getWCPath() + ".backup1";
removeDirOrFile(new File(secondWC));
client.doExport(thisTest.getUrl(), secondWC, null, null, false, false,
Depth.infinity, null);
// Make an obstructing file that conflicts with add coming from repos
file = new File(secondWC, "A/B/lambda");
pw = new PrintWriter(new FileOutputStream(file));
pw.print("This is the conflicting obstructiong file 'lambda'.");
pw.close();
// Attempt to checkout backup WC without "--force"...
try
{
// ...should fail
client.checkout(thisTest.getUrl(), secondWC, null, null,
Depth.infinity, false, false);
fail("obstructed checkout should fail by default");
}
catch (ClientException expected)
{
}
// Attempt to checkout backup WC with "--force"
( run in 1.000 second using v1.01-cache-2.11-cpan-411bb0df24b )