view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
public BasicTests()
{
init();
}
public BasicTests(String name)
{
super(name);
init();
}
/**
* Initialize the testBaseName and the testCounter, if this is the
* first test of this class.
*/
private void init()
{
if (!testName.equals(testBaseName))
{
testCounter = 0;
testBaseName = testName;
}
}
/**
* Test LogDate().
* @throws Throwable
*/
public void testLogDate() throws Throwable
{
String goodDate = "2007-10-04T03:00:52.134992Z";
String badDate = "2008-01-14";
LogDate logDate;
try
{
logDate = new LogDate(goodDate);
assertEquals(1191466852134992L, logDate.getTimeMicros());
} catch (ParseException e) {
fail("Failed to parse date " + goodDate);
}
try
{
logDate = new LogDate(badDate);
fail("Failed to throw exception on bad date " + badDate);
} catch (ParseException e) {
}
}
/**
* Test SVNClient.getVersion().
* @throws Throwable
*/
public void testVersion() throws Throwable
{
try
{
Version version = client.getVersion();
String versionString = version.toString();
if (versionString == null || versionString.trim().length() == 0)
{
throw new Exception("Version string empty");
}
}
catch (Exception e)
{
fail("Version should always be available unless the " +
"native libraries failed to initialize: " + e);
}
}
/**
* Tests Subversion path validation.
*/
public void testPathValidation() throws Throwable
{
// Rather than segfaulting, JavaHL considers null an invalid path.
assertFalse("Path validation produced false-positive for null path",
Path.isValid(null));
String path = "valid-path";
assertTrue("Validation check of valid path '" + path +
"' should succeed", Path.isValid(path));
// File names cannot contain control characters.
path = "invalid-\u0001-path";
assertFalse("Validation check of invalid path '" + path +
"' (which contains control characters) should fail",
Path.isValid(path));
}
/**
* Tests Subversion path as URL predicate.
*/
public void testPathIsURL() throws Throwable
{
try
{
Path.isURL(null);
fail("A null path should raise an exception");
}
catch (IllegalArgumentException expected)
{
}
// Subversion "paths" which aren't URLs.
String[] paths = { "/path", "c:\\path" };
for (int i = 0; i < paths.length; i++)
{
assertFalse("'" + paths[i] + "' should not be considered a URL",
Path.isURL(paths[i]));
}
// Subversion "paths" which are URLs.
paths = new String[] { "http://example.com", "svn://example.com",
"svn+ssh://example.com", "file:///src/svn/" };
for (int i = 0; i < paths.length; i++)
{
assertTrue("'" + paths[i] + "' should be considered a URL",
Path.isURL(paths[i]));
}
}
/**
* Tests Mergeinfo and RevisionRange classes.
* @since 1.5
*/
public void testMergeinfoParser() throws Throwable
{
String mergeInfoPropertyValue =
"/trunk:1-300,305,307,400-405\n/branches/branch:308-400";
Mergeinfo info = new Mergeinfo(mergeInfoPropertyValue);
String[] paths = info.getPaths();
assertEquals(2, paths.length);
RevisionRange[] trunkRange = info.getRevisionRange("/trunk");
assertEquals(4, trunkRange.length);
assertEquals("1-300", trunkRange[0].toString());
assertEquals("305", trunkRange[1].toString());
assertEquals("307", trunkRange[2].toString());
assertEquals("400-405", trunkRange[3].toString());
RevisionRange[] branchRange =
info.getRevisionRange("/branches/branch");
assertEquals(1, branchRange.length);
}
/**
* Test the basic SVNClient.status functionality.
* @throws Throwable
*/
public void testBasicStatus() throws Throwable
{
// build the test setup
OneTest thisTest = new OneTest();
// check the status of the working copy
thisTest.checkStatus();
// Test status of non-existent file
File fileC = new File(thisTest.getWorkingCopy() + "/A", "foo.c");
Status s = client.singleStatus(fileToSVNPath(fileC, false), false);
if (s != null)
fail("File foo.c should not return a status.");
}
/**
* Test the "out of date" info from {@link
* org.tigris.subversion.javahl.SVNClient#status()}.
*
* @throws SubversionException
* @throws IOException
*/
public void testOODStatus() throws SubversionException, IOException
{
// build the test setup
OneTest thisTest = new OneTest();
// Make a whole slew of changes to a WC:
//
// (root) r7 - prop change
// iota
// A
// |__mu
// |
// |__B
// | |__lambda
// | |
// | |__E r12 - deleted
// | | |__alpha
// | | |__beta
// | |
// | |__F r9 - prop change
// | |__I r6 - added dir
// |
// |__C r5 - deleted
// |
// |__D
// |__gamma
// |
// |__G
// | |__pi r3 - deleted
// | |__rho r2 - modify text
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
// set the expected working copy layout for the backup test
backupTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
backupTest.getWc().setItemContent("A/mu",
backupTest.getWc().getItemContent("A/mu") + "appended mu text");
backupTest.getWc().setItemWorkingCopyRevision("A/D/G/rho", 2);
backupTest.getWc().setItemContent("A/D/G/rho",
backupTest.getWc().getItemContent("A/D/G/rho")
+ "new appended text for rho");
// check the status of the working copy of the backup test
backupTest.checkStatus();
}
/**
* Test basic SVNClient.mkdir with URL parameter functionality.
* @throws Throwable
*/
public void testBasicMkdirUrl() throws Throwable
{
// build the test setup.
OneTest thisTest = new OneTest();
// create Y and Y/Z directories in the repository
addExpectedCommitItem(null, thisTest.getUrl(), "Y", NodeKind.none,
CommitItemStateFlags.Add);
addExpectedCommitItem(null, thisTest.getUrl(), "Y/Z", NodeKind.none,
CommitItemStateFlags.Add);
client.mkdir(new String[]{thisTest.getUrl() + "/Y",
thisTest.getUrl() + "/Y/Z"}, "log_msg");
// add the new directories the expected working copy layout
thisTest.getWc().addItem("Y", null);
thisTest.getWc().setItemWorkingCopyRevision("Y", 2);
thisTest.getWc().addItem("Y/Z", null);
thisTest.getWc().setItemWorkingCopyRevision("Y/Z", 2);
// update the working copy
assertEquals("wrong revision from update",
client.update(thisTest.getWCPath(), null, true),
2);
// check the status of the working copy
thisTest.checkStatus();
}
/**
* Test the {@link SVNClientInterface.copy()} API.
* @since 1.5
*/
public void testCopy()
throws SubversionException, IOException
{
OneTest thisTest = new OneTest();
WC wc = thisTest.getWc();
final Revision firstRevision = Revision.getInstance(1);
final Revision pegRevision = null; // Defaults to Revision.HEAD.
// Copy files from A/B/E to A/B/F.
String[] srcPaths = { "alpha", "beta" };
CopySource[] sources = new CopySource[srcPaths.length];
for (int i = 0; i < srcPaths.length; i++)
{
String fileName = srcPaths[i];
sources[i] =
new CopySource(new File(thisTest.getWorkingCopy(),
"A/B/E/" + fileName).getPath(),
firstRevision, pegRevision);
wc.addItem("A/B/F/" + fileName,
wc.getItemContent("A/B/E/" + fileName));
wc.setItemWorkingCopyRevision("A/B/F/" + fileName, 2);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/B/F/" + fileName, NodeKind.file,
CommitItemStateFlags.Add |
CommitItemStateFlags.IsCopy);
}
client.copy(sources,
new File(thisTest.getWorkingCopy(), "A/B/F").getPath(),
null, true, false, null);
// Commit the changes, and check the state of the WC.
assertEquals("Unexpected WC revision number after commit",
client.commit(new String[] { thisTest.getWCPath() },
"Copy files", true),
2);
thisTest.checkStatus();
assertExpectedSuggestion(thisTest.getUrl() + "/A/B/E/alpha", "A/B/F/alpha", thisTest);
// Now test a WC to URL copy
CopySource wcSource[] = new CopySource[1];
wcSource[0] = new CopySource(new File(thisTest.getWorkingCopy(),
"A/B").getPath(), Revision.WORKING, Revision.WORKING);
client.commitMessageHandler(null);
client.copy(wcSource,
thisTest.getUrl() + "/parent/A/B",
"Copy WC to URL", true, true, null);
// update the WC to get new folder and confirm the copy
assertEquals("wrong revision number from update",
client.update(thisTest.getWCPath(), null, true),
3);
}
/**
* Test the {@link SVNClientInterface.move()} API.
* @since 1.5
*/
public void testMove()
throws SubversionException, IOException
{
OneTest thisTest = new OneTest();
WC wc = thisTest.getWc();
// Move files from A/B/E to A/B/F.
String[] srcPaths = { "alpha", "beta" };
for (int i = 0; i < srcPaths.length; i++)
{
String fileName = srcPaths[i];
srcPaths[i] = new File(thisTest.getWorkingCopy(),
"A/B/E/" + fileName).getPath();
wc.addItem("A/B/F/" + fileName,
wc.getItemContent("A/B/E/" + fileName));
wc.setItemWorkingCopyRevision("A/B/F/" + fileName, 2);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/B/F/" + fileName, NodeKind.file,
CommitItemStateFlags.Add |
CommitItemStateFlags.IsCopy);
wc.removeItem("A/B/E/" + fileName);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/B/E/" + fileName, NodeKind.file,
CommitItemStateFlags.Delete);
}
client.move(srcPaths,
new File(thisTest.getWorkingCopy(), "A/B/F").getPath(),
null, false, true, false, null);
// Commit the changes, and check the state of the WC.
assertEquals("Unexpected WC revision number after commit",
client.commit(new String[] { thisTest.getWCPath() },
"Move files", true), 2);
thisTest.checkStatus();
assertExpectedSuggestion(thisTest.getUrl() + "/A/B/E/alpha", "A/B/F/alpha", thisTest);
}
/**
* Assert that the first merge source suggested for
* <code>destPath</code> at {@link Revision#WORKING} and {@link
* Revision#HEAD} is equivalent to <code>expectedSrc</code>.
* @exception SubversionException If retrieval of the copy source fails.
* @since 1.5
*/
private void assertExpectedSuggestion(String expectedSrc,
String destPath, OneTest thisTest)
throws SubversionException
{
String wcPath = fileToSVNPath(new File(thisTest.getWCPath(),
destPath), false);
String[] suggestions = client.suggestMergeSources(wcPath,
Revision.WORKING);
assertNotNull(suggestions);
assertTrue(suggestions.length >= 1);
assertTrue("Unexpected copy source path, expected " +
expectedSrc + ", got " + suggestions[0],
expectedSrc.equals(suggestions[0]));
// Same test using URL
String url = thisTest.getUrl() + "/" + destPath;
suggestions = client.suggestMergeSources(url, Revision.HEAD);
assertNotNull(suggestions);
assertTrue(suggestions.length >= 1);
assertTrue("Unexpected copy source path, expected " +
expectedSrc + ", got " + suggestions[0],
expectedSrc.equals(suggestions[0]));
}
/**
* Tests that the passed start and end revision are contained
* within the array of revisions.
* @since 1.5
*/
private void assertExpectedMergeRange(long start, long end,
long[] revisions)
{
Arrays.sort(revisions);
for (int i = 0; i < revisions.length; i++) {
if (revisions[i] <= start) {
for (int j = i; j < revisions.length; j++)
{
if (end <= revisions[j])
return;
}
fail("End revision: " + end + " was not in range: " + revisions[0] +
" : " + revisions[revisions.length - 1]);
return;
}
}
fail("Start revision: " + start + " was not in range: " + revisions[0] +
" : " + revisions[revisions.length - 1]);
}
/**
* Test the basic SVNClient.update functionality with concurrent
* changes in the repository and the working copy.
* @throws Throwable
*/
public void testBasicMergingUpdate() throws Throwable
{
// build the first working copy
OneTest thisTest = new OneTest();
// append 10 lines to A/mu
File mu = new File(thisTest.getWorkingCopy(), "A/mu");
PrintWriter muWriter = new PrintWriter(new FileOutputStream(mu, true));
String muContent = thisTest.getWc().getItemContent("A/mu");
for (int i = 2; i < 11; i++)
{
muWriter.print("\nThis is line " + i + " in mu");
muContent = muContent + "\nThis is line " + i + " in mu";
}
muWriter.close();
thisTest.getWc().setItemWorkingCopyRevision("A/mu", 2);
thisTest.getWc().setItemContent("A/mu", muContent);
addExpectedCommitItem(thisTest.getWorkingCopy().getAbsolutePath(),
thisTest.getUrl(), "A/mu", NodeKind.file,
CommitItemStateFlags.TextMods);
// append 10 line to A/D/G/rho
File rho = new File(thisTest.getWorkingCopy(), "A/D/G/rho");
PrintWriter rhoWriter =
new PrintWriter(new FileOutputStream(rho, true));
String rhoContent = thisTest.getWc().getItemContent("A/D/G/rho");
for (int i = 2; i < 11; i++)
{
rhoWriter.print("\nThis is line " + i + " in rho");
rhoContent = rhoContent + "\nThis is line " + i + " in rho";
}
rhoWriter.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
assertEquals("wrong revision number from commit",
client.commit(new String[]{thisTest.getWCPath()},
"log msg",
true),
2);
// check the status of the first working copy
thisTest.checkStatus();
// create a backup copy of the working copy
OneTest backupTest = thisTest.copy(".backup");
// change the last line of A/mu in the first working copy
muWriter = new PrintWriter(new FileOutputStream(mu, true));
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
dir.mkdir();
// create dir/foo.c
File fileC = new File(dir, "foo.c");
new FileOutputStream(fileC).close();
// create dir/foo.o (should be ignored)
File fileO = new File(dir, "foo.o");
new FileOutputStream(fileO).close();
// import dir
addExpectedCommitItem(thisTest.getWCPath(),
null, "dir", NodeKind.none, CommitItemStateFlags.Add);
client.doImport(dir.getAbsolutePath(), thisTest.getUrl()+"/dir",
"log message for import", true);
// remove dir
removeDirOrFile(dir);
// udpate the working copy
assertEquals("wrong revision from update", 2,
client.update(thisTest.getWCPath(), null, true));
thisTest.getWc().addItem("dir", null);
thisTest.getWc().addItem("dir/foo.c", "");
// test the working copy status
thisTest.checkStatus();
}
/**
* Test the basic SVNClient.info functionality.
* @throws Throwable
*/
public void testBasicInfo() throws Throwable
{
// create the working copy
OneTest thisTest = new OneTest();
// get the item information and test it
Info info = client.info(thisTest.getWCPath()+"/A/mu");
assertEquals("wrong revision from info", 1,
info.getLastChangedRevision());
assertEquals("wrong schedule kind from info", ScheduleKind.normal,
info.getSchedule());
assertEquals("wrong node kind from info", NodeKind.file,
info.getNodeKind());
}
/**
* Test the basic SVNClient.logMessages functionality.
* @throws Throwable
*/
public void testBasicLogMessage() throws Throwable
{
// create the working copy
OneTest thisTest = new OneTest();
// get the commit message of the initial import and test it
LogMessage lm[] = client.logMessages(thisTest.getWCPath(), null,
null, false, true);
assertEquals("wrong number of objects", 1, lm.length);
assertEquals("wrong message", "Log Message", lm[0].getMessage());
assertEquals("wrong revision", 1, lm[0].getRevisionNumber());
assertEquals("wrong user", "jrandom", lm[0].getAuthor());
assertNotNull("changed paths set", lm[0].getChangedPaths());
ChangePath cp[] = lm[0].getChangedPaths();
assertEquals("wrong number of chang pathes", 20, cp.length);
assertEquals("wrong path", "/A", cp[0].getPath());
assertEquals("wrong copy source rev", -1, cp[0].getCopySrcRevision());
assertNull("wrong copy source path", cp[0].getCopySrcPath());
assertEquals("wrong action", 'A', cp[0].getAction());
assertEquals("wrong time with getTimeMicros()",
lm[0].getTimeMicros()/1000,
lm[0].getDate().getTime());
assertEquals("wrong time with getTimeMillis()",
lm[0].getTimeMillis(),
lm[0].getDate().getTime());
assertEquals("wrong date with getTimeMicros()",
lm[0].getDate(),
new java.util.Date(lm[0].getTimeMicros()/1000));
assertEquals("wrong date with getTimeMillis()",
lm[0].getDate(),
new java.util.Date(lm[0].getTimeMillis()));
// Ensure that targets get canonicalized
String non_canonical = thisTest.getUrl().toString() + "/";
LogMessage lm2[] = client.logMessages(non_canonical, null,
null, false, true);
}
/**
* Test the basic SVNClient.getVersionInfo functionality.
* @throws Throwable
* @since 1.2
*/
public void testBasicVersionInfo() throws Throwable
{
// create the working copy
OneTest thisTest = new OneTest();
assertEquals("wrong version info",
"1",
client.getVersionInfo(thisTest.getWCPath(), null, false));
}
/**
* Test the basic SVNClient locking functionality.
* @throws Throwable
* @since 1.2
*/
public void testBasicLocking() throws Throwable
{
// build the first working copy
OneTest thisTest = new OneTest();
client.propertySet(thisTest.getWCPath()+"/A/mu",
PropertyData.NEEDS_LOCK, "*", false);
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/mu",NodeKind.file,
CommitItemStateFlags.PropMods);
assertEquals("bad revision number on commit", 2,
client.commit(new String[] {thisTest.getWCPath()},
"message", true));
File f = new File(thisTest.getWCPath()+"/A/mu");
assertEquals("file should be read only now", false, f.canWrite());
client.lock(new String[] {thisTest.getWCPath()+"/A/mu"},
"comment", false);
assertEquals("file should be read write now", true, f.canWrite());
client.unlock(new String[]{thisTest.getWCPath()+"/A/mu"}, false);
assertEquals("file should be read only now", false, f.canWrite());
client.lock(new String[]{thisTest.getWCPath()+"/A/mu"},
"comment", false);
assertEquals("file should be read write now", true, f.canWrite());
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl(), "A/mu",NodeKind.file,
0);
assertEquals("rev number from commit", -1,
client.commit(new String[]{thisTest.getWCPath()},
"message", true));
assertEquals("file should be read write now", true, f.canWrite());
try
{
// Attempt to lock an invalid path
client.lock(new String[]{thisTest.getWCPath()+"/A/mu2"}, "comment",
false);
fail("missing exception");
}
catch (ClientException expected)
{
}
}
/**
* Test the basic SVNClient.info2 functionality.
* @throws Throwable
* @since 1.2
*/
public void testBasicInfo2() throws Throwable
{
// build the first working copy
OneTest thisTest = new OneTest();
final String failureMsg = "Incorrect number of info objects";
Info2[] infos = client.info2(thisTest.getWCPath(), null, null, false);
assertEquals(failureMsg, 1, infos.length);
infos = client.info2(thisTest.getWCPath(), null, null, true);
assertEquals(failureMsg, 21, infos.length);
for (int i = 0; i < infos.length; i++)
{
Info2 info = infos[i];
assertNull("Unexpected changelist present",
info.getChangelistName());
boolean isFile = info.getKind() == NodeKind.file;
assertTrue("Unexpected working file size " + info.getWorkingSize()
+ " for '" + info + '\'',
(isFile ? info.getWorkingSize() > -1 :
info.getWorkingSize() == -1));
// We shouldn't know the repository file size when only
// examining the WC.
assertEquals("Unexpected repos file size for '" + info + '\'',
-1, info.getReposSize());
// Examine depth
assertEquals("Unexpected depth for '" + info + "'",
(isFile ? Depth.unknown : Depth.infinity),
info.getDepth());
}
// Create wc with a depth of Depth.empty
String secondWC = thisTest.getWCPath() + ".empty";
removeDirOrFile(new File(secondWC));
client.checkout(thisTest.getUrl(), secondWC, null, null, Depth.empty,
false, true);
infos = client.info2(secondWC, null, null, false);
// Examine that depth is Depth.empty
assertEquals(Depth.empty, infos[0].getDepth());
}
/**
* Test basic changelist functionality.
* @throws Throwable
* @since 1.5
*/
public void testBasicChangelist() throws Throwable
{
// build the working copy
OneTest thisTest = new OneTest();
String changelistName = "changelist1";
String[] changelists = new String[] { changelistName };
MyChangelistCallback clCallback = new MyChangelistCallback();
String[] paths = new String[]
{fileToSVNPath(new File(thisTest.getWCPath(), "iota"), true)};
// Add a path to a changelist, and check to see if it got added
client.addToChangelist(paths, changelistName, Depth.infinity, null);
String[] cl = new String[1];
client.getChangelists(thisTest.getWCPath(), changelists,
Depth.infinity, clCallback);
cl[0] = (String) clCallback.get(paths[0]).get(0);
assertTrue(java.util.Arrays.equals(cl, changelists));
// Does status report this changelist?
Status[] status = client.status(paths[0], false, false, false, false,
false);
assertEquals(status[0].getChangelist(), changelistName);
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
int i = 0;
for (Iterator iter = revList.iterator(); iter.hasNext();) {
Long revision = (Long) iter.next();
revisions[i] = revision.longValue();
i++;
}
return revisions;
}
}
Callback callback = new Callback();
client.getMergeinfoLog(kind, pathOrUrl, pegRevision, mergeSourceUrl,
srcPegRevision, false, null, callback);
return callback.getRevisions();
}
/**
* Append the text <code>toAppend</code> to the WC file at
* <code>path</code>, and update the expected WC state
* accordingly.
*
* @param thisTest The test whose expected WC to tweak.
* @param path The working copy-relative path to change.
* @param toAppend The text to append to <code>path</code>.
* @param rev The expected revision number for thisTest's WC.
* @return The file created during the setup.
* @since 1.5
*/
private File appendText(OneTest thisTest, String path, String toAppend,
int rev)
throws FileNotFoundException
{
File f = new File(thisTest.getWorkingCopy(), path);
PrintWriter writer = new PrintWriter(new FileOutputStream(f, true));
writer.print(toAppend);
writer.close();
if (rev > 0)
{
WC wc = thisTest.getWc();
wc.setItemWorkingCopyRevision(path, rev);
wc.setItemContent(path, wc.getItemContent(path) + toAppend);
}
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(), path,
NodeKind.file, CommitItemStateFlags.TextMods);
return f;
}
/**
* Test the basic functionality of SVNClient.merge().
* @throws Throwable
* @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() },
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
* 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 =
"===================================================================" + 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;
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
};
client.notification2(notify);
// update the test to try to cancel an operation
try
{
client.update(thisTest.getWCPath(), null, true);
fail("missing exception for canceled operation");
}
catch (ClientException e)
{
// this is expected
}
}
public void testDataTransferProgressReport() throws Throwable
{
// ### FIXME: This isn't working over ra_local, because
// ### ra_local is not invoking the progress callback.
if (SVNTests.rootUrl.startsWith("file://"))
return;
// build the test setup
OneTest thisTest = new OneTest();
ProgressListener listener = new ProgressListener()
{
public void onProgress(ProgressEvent event)
{
// TODO: Examine the byte counts from "event".
throw new RuntimeException("Progress reported as expected");
}
};
client.setProgressListener(listener);
// Perform an update to exercise the progress notification.
try
{
client.update(thisTest.getWCPath(), null, true);
fail("No progress reported");
}
catch (RuntimeException progressReported)
{
}
}
/**
* Test the basic tree conflict functionality.
* @throws Throwable
*/
public void testTreeConflict() throws Throwable
{
// build the test setup. Used for the changes
OneTest thisTest = new OneTest();
WC wc = thisTest.getWc();
// build the backup test setup. That is the one that will be updated
OneTest tcTest = thisTest.copy(".tree-conflict");
// Move files from A/B/E to A/B/F.
String[] srcPaths = { "alpha" };
for (int i = 0; i < srcPaths.length; i++)
{
String fileName = srcPaths[i];
srcPaths[i] = new File(thisTest.getWorkingCopy(),
"A/B/E/" + fileName).getPath();
wc.addItem("A/B/F/" + fileName,
wc.getItemContent("A/B/E/" + fileName));
wc.setItemWorkingCopyRevision("A/B/F/" + fileName, 2);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/B/F/" + fileName, NodeKind.file,
CommitItemStateFlags.Add |
CommitItemStateFlags.IsCopy);
wc.removeItem("A/B/E/" + fileName);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/B/E/" + fileName, NodeKind.file,
CommitItemStateFlags.Delete);
}
client.move(srcPaths,
new File(thisTest.getWorkingCopy(), "A/B/F").getPath(),
null, false, true, false, null);
// Commit the changes, and check the state of the WC.
assertEquals("Unexpected WC revision number after commit",
client.commit(new String[] { thisTest.getWCPath() },
"Move files", true), 2);
thisTest.checkStatus();
// modify A/B/E/alpha in second working copy
File alpha = new File(tcTest.getWorkingCopy(), "A/B/E/alpha");
PrintWriter alphaWriter = new PrintWriter(new FileOutputStream(alpha, true));
alphaWriter.print("appended alpha text");
alphaWriter.close();
// update the tc test
assertEquals("wrong revision number from update",
client.update(tcTest.getWCPath(), null, true),
2);
// set the expected working copy layout for the tc test
tcTest.getWc().addItem("A/B/F/alpha",
tcTest.getWc().getItemContent("A/B/E/alpha"));
tcTest.getWc().setItemWorkingCopyRevision("A/B/F/alpha", 2);
// we expect the tree conflict to turn the existing item into
// a scheduled-add with history.
tcTest.getWc().setItemTextStatus("A/B/E/alpha", StatusKind.added);
tcTest.getWc().setItemTextStatus("A/B/F/alpha", StatusKind.normal);
// check the status of the working copy of the tc test
tcTest.checkStatus();
// 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);
ConflictDescriptor conflict = callback.getInfo().getConflictDescriptor();
assertNotNull("Conflict should not be null", conflict);
assertEquals(conflict.getSrcLeftVersion().getNodeKind(), NodeKind.file);
src/subversion/subversion/bindings/javahl/tests/org/tigris/subversion/javahl/BasicTests.java view on Meta::CPAN
assertEquals(conflict.getSrcRightVersion().getPegRevision(), 2L);
}
}
/**
* Test tolerance of unversioned obstructions when adding paths with
* {@link org.tigris.subversion.javahl.SVNClient#checkout()},
* {@link org.tigris.subversion.javahl.SVNClient#update()}, and
* {@link org.tigris.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, false);
// 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,
Depth.infinity, false, true);
// Check the WC status, the only status should be a text
// mod to lambda. All the other obstructing files were identical
Status[] secondWCStatus = client.status(secondWC, true, false,
false, false, false);
if (!(secondWCStatus.length == 1 &&
secondWCStatus[0].getPath().endsWith("A/B/lambda") &&
secondWCStatus[0].getTextStatus() == StatusKind.modified &&
secondWCStatus[0].getPropStatus() == StatusKind.none))
{
fail("Unexpected WC status after co with " +
"unversioned obstructions");
}
// Make a third WC to test obstruction tolerance of sw and up.
OneTest backupTest = thisTest.copy(".backup2");
// ----- TEST UPDATE -----
// r2: Add a file A/D/H/nu
file = new File(thisTest.getWorkingCopy(), "A/D/H/nu");
pw = new PrintWriter(new FileOutputStream(file));
pw.print("This is the file 'nu'.");
pw.close();
client.add(file.getAbsolutePath(), false);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/D/H/nu", NodeKind.file,
CommitItemStateFlags.TextMods +
CommitItemStateFlags.Add);
assertEquals("wrong revision number from commit",
client.commit(new String[] {thisTest.getWCPath()},
"log msg", true), 2);
thisTest.getWc().addItem("A/D/H/nu", "This is the file 'nu'.");
Status status = client.singleStatus(thisTest.getWCPath() +
"/A/D/H/nu",
false);
// Add an unversioned file A/D/H/nu to the backup WC
file = new File(backupTest.getWorkingCopy(), "A/D/H/nu");
pw = new PrintWriter(new FileOutputStream(file));
pw.print("This is the file 'nu'.");
pw.close();
// Attempt to update backup WC without "--force"
try
{
// obstructed update should fail
client.update(backupTest.getWCPath(), null, true);
fail("obstructed update should fail by default");
}
catch (ClientException expected)
{
}
// Attempt to update backup WC with "--force"
assertEquals("wrong revision from update",
client.update(backupTest.getWCPath(),
null, Depth.infinity, false, false, true),
2);
// ----- TEST SWITCH -----
// Add an unversioned file A/B/E/nu to the backup WC
// The file differs from A/D/H/nu
file = new File(backupTest.getWorkingCopy(), "A/B/E/nu");
pw = new PrintWriter(new FileOutputStream(file));
pw.print("This is yet another file 'nu'.");
pw.close();