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
* @since 1.2
*/
public void testBasicMerge() throws Throwable
{
OneTest thisTest = setupAndPerformMerge();
// Verify that there are now potential merge sources.
String[] suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath() + "/branches/A",
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(1, suggestedSrcs.length);
// 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);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
4);
// Add a "begin merge" notification handler.
final Revision[] actualRange = new Revision[2];
Notify2 notify = new Notify2()
{
public void onNotify(NotifyInformation info)
{
if (info.getAction() == NotifyAction.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, true, false, true);
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, true, 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(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A/D/G/rho", NodeKind.file,
CommitItemStateFlags.TextMods);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true), 5);
// Merge and commit some more changes (r6).
appendText(thisTest, "A/mu", "xxxr6", 6);
appendText(thisTest, "A/D/G/rho", "yyyr6", 6);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
6);
// 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);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
4);
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
Revision unspec = new Revision(RevisionKind.unspecified);
client.merge(modUrl, Revision.HEAD,
new RevisionRange[] { new RevisionRange(unspec, unspec) },
branchPath, true, Depth.infinity, false, false, false);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true), 5);
}
/**
* 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);
assertEquals("wrong revision number from main commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
4);
// Merge and commit some changes to branch (r5).
appendText(thisTest, "branches/A/D/G/rho", "yyy", -1);
assertEquals("wrong revision number from branch commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
5);
// update the branch WC (to r5) before merge
client.update(thisTest.getWCPath() + "/branches", Revision.HEAD, true);
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
Revision unspec = new Revision(RevisionKind.unspecified);
client.merge(modUrl, Revision.HEAD,
new RevisionRange[] { new RevisionRange(unspec, unspec) },
branchPath, true, Depth.infinity, false, false, false);
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"branches/A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true), 6);
// 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
client.update(thisTest.getWCPath(), Revision.HEAD, true);
client.mergeReintegrate(branchUrl, Revision.HEAD,
thisTest.getWCPath() + "/A", false);
}
// commit the changes so that we can verify merge
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A", NodeKind.dir,
CommitItemStateFlags.PropMods);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/D/G/rho", NodeKind.file,
CommitItemStateFlags.TextMods);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true), 7);
}
/**
* 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.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);
assertEquals("wrong revision number from commit", 2,
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true));
// Backdate the WC to the previous revision (r1).
client.update(thisTest.getWCPath(), Revision.getInstance(1), true);
// 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).
RevisionRange[] ranges = new RevisionRange[1];
ranges[0] = new RevisionRange(new Revision.Number(1),
new Revision.Number(2));
client.merge(thisTest.getUrl(), 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.
String[] suggestedSrcs =
client.suggestMergeSources(thisTest.getWCPath() + "/branches/A",
Revision.WORKING);
assertNotNull(suggestedSrcs);
assertEquals(1, suggestedSrcs.length);
// 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);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true),
4);
// --record-only merge changes in A to branches/A
String branchPath = thisTest.getWCPath() + "/branches/A";
String modUrl = thisTest.getUrl() + "/A";
RevisionRange[] ranges = new RevisionRange[1];
ranges[0] = 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(),
"branches/A", NodeKind.dir,
CommitItemStateFlags.PropMods);
assertEquals("wrong revision number from commit",
client.commit(new String[] { thisTest.getWCPath() },
"log msg", true), 5);
// 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.
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 =
( run in 1.032 second using v1.01-cache-2.11-cpan-99c4e6809bf )