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
* @throws Throwable
* @since 1.2
*/
public void testBasicMerge() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Verify that there are now potential merge sources.
Set<String> suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath() + "/branches/A",
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(1, suggestedSrcs.size());
// Test that getMergeinfo() returns null.
assertNull(client.getMergeinfo(new File(thisTest.getWCPath(), "A")
.toString(), Revision.HEAD));
// Merge and commit some changes (r4).
appendText(thisTest, "A/mu", "xxx", 4);
appendText(thisTest, "A/D/G/rho", "yyy", 4);
checkCommitRevision(thisTest, "wrong revision number from commit", 4,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Add a "begin merge" notification handler.
final Revision[] actualRange = new Revision[2];
ClientNotifyCallback notify = new ClientNotifyCallback()
{
public void onNotify(ClientNotifyInformation info)
{
if (info.getAction() == ClientNotifyInformation.Action.merge_begin)
{
RevisionRange r = info.getMergeRange();
actualRange[0] = r.getFromRevision();
actualRange[1] = r.getToRevision();
}
}
};
client.notification2(notify);
// merge changes in A to branches/A
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
// test --dry-run
client.merge(modUrl, new Revision.Number(2), modUrl, Revision.HEAD,
branchPath, false, Depth.infinity, false, true, false);
assertEquals("Notification of beginning of merge reported incorrect " +
"start revision", new Revision.Number(2), actualRange[0]);
assertEquals("Notification of beginning of merge reported incorrect " +
"end revision", new Revision.Number(4), actualRange[1]);
// now do the real merge
client.merge(modUrl, new Revision.Number(2), modUrl, Revision.HEAD,
branchPath, false, Depth.infinity, false, false, false);
assertEquals("Notification of beginning of merge reported incorrect " +
"start revision", new Revision.Number(2), actualRange[0]);
assertEquals("Notification of beginning of merge reported incorrect " +
"end revision", new Revision.Number(4), actualRange[1]);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A/D/G/rho", NodeKind.file,
CommitItemStateFlags.TextMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 5,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Merge and commit some more changes (r6).
appendText(thisTest, "A/mu", "xxxr6", 6);
appendText(thisTest, "A/D/G/rho", "yyyr6", 6);
checkCommitRevision(thisTest, "wrong revision number from commit", 6,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Test retrieval of mergeinfo from a WC path.
String targetPath =
new File(thisTest.getWCPath(), "branches/A/mu").getPath();
final String mergeSrc = thisTest.getUrl() + "/A/mu";
acquireMergeinfoAndAssertEquals(2, 4, 6, 6, targetPath, mergeSrc);
// Test retrieval of mergeinfo from the repository.
targetPath = thisTest.getUrl() + "/branches/A/mu";
acquireMergeinfoAndAssertEquals(2, 4, 6, 6, targetPath, mergeSrc);
}
/**
* Test merge with automatic source and revision determination
* (e.g. 'svn merge -g').
* @throws Throwable
* @since 1.5
*/
public void testMergeUsingHistory() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Test that getMergeinfo() returns null.
assertNull(client.getMergeinfo(new File(thisTest.getWCPath(), "A")
.toString(), Revision.HEAD));
// Merge and commit some changes (r4).
appendText(thisTest, "A/mu", "xxx", 4);
checkCommitRevision(thisTest, "wrong revision number from commit", 4,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
Revision unspec = new Revision(Revision.Kind.unspecified);
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
ranges.add(new RevisionRange(unspec, unspec));
client.merge(modUrl, Revision.HEAD, ranges,
branchPath, true, Depth.infinity, false, false, false);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 5,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
}
/**
* Test merge with automatic source and revision determination
* (e.g. 'svn merge -g) with implied revision range.
* @throws Throwable
* @since 1.8
*/
public void testMergeUsingHistoryImpliedRange() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Test that getMergeinfo() returns null.
assertNull(client.getMergeinfo(new File(thisTest.getWCPath(), "A")
.toString(), Revision.HEAD));
// Merge and commit some changes (r4).
appendText(thisTest, "A/mu", "xxx", 4);
checkCommitRevision(thisTest, "wrong revision number from commit", 4,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
client.merge(modUrl, Revision.HEAD, null,
branchPath, true, Depth.infinity, false, false, false);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 5,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
}
/**
* Test reintegrating a branch with trunk
* (e.g. 'svn merge --reintegrate').
* @throws Throwable
* @since 1.5
*/
public void testMergeReintegrate() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Test that getMergeinfo() returns null.
assertNull(client.getMergeinfo(new File(thisTest.getWCPath(), "A")
.toString(), Revision.HEAD));
// Merge and commit some changes to main (r4).
appendText(thisTest, "A/mu", "xxx", 4);
checkCommitRevision(thisTest,
"wrong revision number from main commit", 4,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Merge and commit some changes to branch (r5).
appendText(thisTest, "branches/A/D/G/rho", "yyy", -1);
checkCommitRevision(thisTest,
"wrong revision number from branch commit", 5,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// update the branch WC (to r5) before merge
update(thisTest, "/branches");
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
Revision unspec = new Revision(Revision.Kind.unspecified);
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
ranges.add(new RevisionRange(unspec, unspec));
client.merge(modUrl, Revision.HEAD, ranges,
branchPath, true, Depth.infinity, false, false, false);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 6,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// now we --reintegrate the branch with main
String branchUrl = thisTest.getUrl() + "/branches/A";
try
{
client.mergeReintegrate(branchUrl, Revision.HEAD,
thisTest.getWCPath() + "/A", false);
fail("reintegrate merged into a mixed-revision WC");
}
catch(ClientException e)
{
// update the WC (to r6) and try again
update(thisTest);
client.mergeReintegrate(branchUrl, Revision.HEAD,
thisTest.getWCPath() + "/A", false);
}
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl().toString(), "A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl().toString(), "A/D/G/rho",
NodeKind.file, CommitItemStateFlags.TextMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 7,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
}
/**
* Test automatic merge conflict resolution.
* @throws Throwable
* @since 1.5
*/
public void testMergeConflictResolution() throws Throwable
{
// Add a conflict resolution callback which always chooses the
// user's version of a conflicted file.
client.setConflictResolver(new ConflictResolverCallback()
{
public ConflictResult resolve(ConflictDescriptor descrip)
{
return new ConflictResult(ConflictResult.Choice.chooseTheirsConflict,
null);
}
});
OneTest thisTest = new OneTest();
String originalContents = thisTest.getWc().getItemContent("A/mu");
String expectedContents = originalContents + "xxx";
// Merge and commit a change (r2).
File mu = appendText(thisTest, "A/mu", "xxx", 2);
checkCommitRevision(thisTest, "wrong revision number from commit", 2,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Backdate the WC to the previous revision (r1).
client.update(thisTest.getWCPathSet(), Revision.getInstance(1),
Depth.unknown, false, false, false, false);
// Prep for a merge conflict by changing A/mu in a different
// way.
mu = appendText(thisTest, "A/mu", "yyy", 1);
// Merge in the previous changes to A/mu (from r2).
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
ranges.add(new RevisionRange(new Revision.Number(1),
new Revision.Number(2)));
client.merge(thisTest.getUrl().toString(), Revision.HEAD, ranges,
thisTest.getWCPath(), false, Depth.infinity, false,
false, false);
assertFileContentsEquals("Unexpected conflict resolution",
expectedContents, mu);
}
/**
* Test merge --record-only
* @throws Throwable
* @since 1.5
*/
public void testRecordOnlyMerge() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Verify that there are now potential merge sources.
Set<String> suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath() + "/branches/A",
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(1, suggestedSrcs.size());
// Test that getMergeinfo() returns null.
assertNull(client.getMergeinfo(new File(thisTest.getWCPath(), "A")
.toString(), Revision.HEAD));
// Merge and commit some changes (r4).
appendText(thisTest, "A/mu", "xxx", 4);
appendText(thisTest, "A/D/G/rho", "yyy", 4);
checkCommitRevision(thisTest, "wrong revision number from commit", 4,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// --record-only merge changes in A to branches/A
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
ranges.add(new RevisionRange(new Revision.Number(2),
new Revision.Number(4)));
client.merge(modUrl, Revision.HEAD, ranges,
branchPath, true, Depth.infinity, false, false, true);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl().toString(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
checkCommitRevision(thisTest, "wrong revision number from commit", 5,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// Test retrieval of mergeinfo from a WC path.
String targetPath =
new File(thisTest.getWCPath(), "branches/A").getPath();
final String mergeSrc = thisTest.getUrl() + "/A";
acquireMergeinfoAndAssertEquals(2, 4, 0, 0, targetPath, mergeSrc);
}
/**
* 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.
Set<String> suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath(),
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(0, suggestedSrcs.size());
// create branches directory in the repository (r2)
addExpectedCommitItem(null, thisTest.getUrl().toString(), "branches",
NodeKind.none, CommitItemStateFlags.Add);
Set<String> paths = new HashSet<String>(1);
paths.add(thisTest.getUrl() + "/branches");
client.mkdir(paths, false, null, new ConstMsg("log_msg"), null);
// copy A to branches (r3)
addExpectedCommitItem(null, thisTest.getUrl().toString(), "branches/A",
NodeKind.none, CommitItemStateFlags.Add);
List<CopySource> srcs = new ArrayList<CopySource>(1);
srcs.add(new CopySource(thisTest.getUrl() + "/A", Revision.HEAD,
Revision.HEAD));
client.copy(srcs, thisTest.getUrl() + "/branches/A",
true, false, false, null,
new ConstMsg("create A branch"), null);
// update the WC (to r3) so that it has the branches folder
update(thisTest);
return thisTest;
}
/**
* Test the patch API. This doesn't yet test the results, it only ensures
* that execution goes down to the C layer and back.
* @throws Throwable
*/
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
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"
// so obstructions are tolerated
client.checkout(thisTest.getUrl(), secondWC, null, null,
( run in 1.702 second using v1.01-cache-2.11-cpan-39bf76dae61 )