view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/tests/org/apache/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);
}
}
/**
* Test SVNClient.getVersionExtended().
* @throws Throwable
*/
public void testVersionExtendedQuiet() throws Throwable
{
try
{
VersionExtended vx = client.getVersionExtended(false);
String result = vx.getBuildDate();
if (result == null || result.trim().length() == 0)
throw new Exception("Build date empty");
result = vx.getBuildTime();
if (result == null || result.trim().length() == 0)
throw new Exception("Build time empty");
result = vx.getBuildHost();
if (result == null || result.trim().length() == 0)
throw new Exception("Build host empty");
result = vx.getCopyright();
if (result == null || result.trim().length() == 0)
throw new Exception("Copyright empty");
}
catch (Exception e)
{
fail("VersionExtended should always be available unless the " +
"native libraries failed to initialize: " + e);
}
}
/**
* Test SVNClient.getVersionExtended().
* @throws Throwable
*/
public void testVersionExtendedVerbose() throws Throwable
{
try
{
VersionExtended vx = client.getVersionExtended(true);
String result = vx.getRuntimeHost();
if (result == null || result.trim().length() == 0)
throw new Exception("Runtime host empty");
// OS name is allowed to be null, but not empty
result = vx.getRuntimeOSName();
if (result != null && result.trim().length() == 0)
throw new Exception("Runtime OS name empty");
java.util.Iterator<VersionExtended.LinkedLib> ikl;
ikl = vx.getLinkedLibs();
if (ikl.hasNext())
{
VersionExtended.LinkedLib lib = ikl.next();
result = lib.getName();
if (result == null || result.trim().length() == 0)
throw new Exception("Linked lib name empty");
result = lib.getCompiledVersion();
if (result == null || result.trim().length() == 0)
throw new Exception("Linked lib compiled version empty");
// Runtime version is allowed to be null, but not empty
result = lib.getRuntimeVersion();
if (result != null && result.trim().length() == 0)
throw new Exception("Linked lib runtime version empty");
}
java.util.Iterator<VersionExtended.LoadedLib> ill;
ill = vx.getLoadedLibs();
if (ill.hasNext())
{
VersionExtended.LoadedLib lib = ill.next();
result = lib.getName();
if (result == null || result.trim().length() == 0)
throw new Exception("Loaded lib name empty");
// Version is allowed to be null, but not empty
result = lib.getVersion();
if (result != null && result.trim().length() == 0)
throw new Exception("Loaded lib version empty");
}
}
catch (Exception e)
{
fail("VersionExtended should always be available unless the " +
"native libraries failed to initialize: " + e);
}
}
/**
* Test the JNIError class functionality
* @throws Throwable
*/
public void testJNIError() throws Throwable
{
// build the test setup.
OneTest thisTest = new OneTest();
// Create a client, dispose it, then try to use it later
ISVNClient tempclient = new SVNClient();
tempclient.dispose();
// create Y and Y/Z directories in the repository
addExpectedCommitItem(null, thisTest.getUrl().toString(), "Y", NodeKind.none,
CommitItemStateFlags.Add);
Set<String> urls = new HashSet<String>(1);
urls.add(thisTest.getUrl() + "/Y");
try
{
tempclient.mkdir(urls, false, null, new ConstMsg("log_msg"), null);
}
catch(JNIError e)
{
return; // Test passes!
}
fail("A JNIError should have been thrown here.");
}
/**
* 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);
Set<String> paths = info.getPaths();
assertEquals(2, paths.size());
List<RevisionRange> trunkRange = info.getRevisionRange("/trunk");
assertEquals(4, trunkRange.size());
assertEquals("1-300", trunkRange.get(0).toString());
assertEquals("305", trunkRange.get(1).toString());
assertEquals("307", trunkRange.get(2).toString());
assertEquals("400-405", trunkRange.get(3).toString());
List<RevisionRange> branchRange =
info.getRevisionRange("/branches/branch");
assertEquals(1, branchRange.size());
}
/**
* 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");
MyStatusCallback statusCallback = new MyStatusCallback();
client.status(fileToSVNPath(fileC, false), Depth.unknown, false, true,
false, false, null, statusCallback);
if (statusCallback.getStatusArray().length > 0)
fail("File foo.c should not return a status.");
}
/**
* Test the "out of date" info from {@link
* org.apache.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
// | |__tau r4 - modify text
// |
// |__H
// |__chi r10-11 replaced with file
// |__psi r13-14 replaced with dir
// |__omega
// |__nu r8 - added file
File file, dir;
PrintWriter pw;
Status status;
MyStatusCallback statusCallback;
long rev; // Resulting rev from co or update
long expectedRev = 2; // Keeps track of the latest rev committed
// ----- r2: modify file A/D/G/rho --------------------------
file = new File(thisTest.getWorkingCopy(), "A/D/G/rho");
pw = new PrintWriter(new FileOutputStream(file, true));
pw.print("modification to rho");
pw.close();
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
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().toString(), "Y", NodeKind.none,
CommitItemStateFlags.Add);
addExpectedCommitItem(null, thisTest.getUrl().toString(), "Y/Z", NodeKind.none,
CommitItemStateFlags.Add);
Set<String> urls = new HashSet<String>(2);
urls.add(thisTest.getUrl() + "/Y");
urls.add(thisTest.getUrl() + "/Y/Z");
client.mkdir(urls, false, null, new ConstMsg("log_msg"), null);
// 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",
update(thisTest), 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" };
List<CopySource> sources = new ArrayList<CopySource>(srcPaths.length);
for (String fileName : srcPaths)
{
sources.add(
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().toString(),
"A/B/F/" + fileName, NodeKind.file,
CommitItemStateFlags.Add |
CommitItemStateFlags.IsCopy);
}
client.copy(sources,
new File(thisTest.getWorkingCopy(), "A/B/F").getPath(),
true, false, false, null, null, null);
// Commit the changes, and check the state of the WC.
checkCommitRevision(thisTest,
"Unexpected WC revision number after commit", 2,
thisTest.getWCPathSet(), "Copy files",
Depth.infinity, false, false, null, null);
thisTest.checkStatus();
assertExpectedSuggestion(thisTest.getUrl() + "/A/B/E/alpha", "A/B/F/alpha", thisTest);
// Now test a WC to URL copy
List<CopySource> wcSource = new ArrayList<CopySource>(1);
wcSource.add(new CopySource(new File(thisTest.getWorkingCopy(),
"A/B").getPath(), Revision.WORKING,
Revision.WORKING));
client.copy(wcSource, thisTest.getUrl() + "/parent/A/B",
true, true, false, null,
new ConstMsg("Copy WC to URL"), null);
// update the WC to get new folder and confirm the copy
assertEquals("wrong revision number from update",
update(thisTest), 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.
Set<String> relPaths = new HashSet<String>(2);
relPaths.add("alpha");
relPaths.add("beta");
Set<String> srcPaths = new HashSet<String>(2);
for (String fileName : relPaths)
{
srcPaths.add(new File(thisTest.getWorkingCopy(),
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
assertEquals(statusPath + "/F/alpha",
statusList[0].getMovedToAbspath());
assertEquals(statusPath + "/F/beta",
statusList[1].getMovedToAbspath());
assertEquals(statusPath + "/E/alpha",
statusList[2].getMovedFromAbspath());
assertEquals(statusPath + "/E/beta",
statusList[3].getMovedFromAbspath());
// Commit the changes, and check the state of the WC.
checkCommitRevision(thisTest,
"Unexpected WC revision number after commit", 2,
thisTest.getWCPathSet(), "Move files",
Depth.infinity, false, false, null, null);
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);
Set<String> suggestions = client.suggestMergeSources(wcPath,
Revision.WORKING);
assertNotNull(suggestions);
assertTrue(suggestions.size() >= 1);
assertTrue("Copy source path not found in suggestions: " +
expectedSrc,
suggestions.contains(expectedSrc));
// Same test using URL
String url = thisTest.getUrl() + "/" + destPath;
suggestions = client.suggestMergeSources(url, Revision.HEAD);
assertNotNull(suggestions);
assertTrue(suggestions.size() >= 1);
assertTrue("Copy source path not found in suggestions: " +
expectedSrc,
suggestions.contains(expectedSrc));
}
/**
* 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().toString(), "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().toString(), "A/D/G/rho",
NodeKind.file, CommitItemStateFlags.TextMods);
// commit the changes
checkCommitRevision(thisTest, "wrong revision number from commit", 2,
thisTest.getWCPathSet(), "log msg", Depth.infinity,
false, false, null, null);
// 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));
muContent = thisTest.getWc().getItemContent("A/mu");
muWriter.print(" Appended to line 10 of mu");
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
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",
Depth.infinity, false, false, null,
new ConstMsg("log message for import"), null);
// remove dir
removeDirOrFile(dir);
// udpate the working copy
assertEquals("wrong revision from update",
update(thisTest), 2);
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 = collectInfos(thisTest.getWCPath()+"/A/mu", null, null,
Depth.empty, null)[0];
assertEquals("wrong revision from info", 1,
info.getLastChangedRev());
assertEquals("wrong schedule kind from info",
Info.ScheduleKind.normal, info.getSchedule());
assertEquals("wrong node kind from info", NodeKind.file,
info.getKind());
}
/**
* 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
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
ranges.add(new RevisionRange(null, null));
LogMessage lm[] = collectLogMessages(thisTest.getWCPath(), null,
ranges, false, true, false, 0);
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());
Set<ChangePath> cp = lm[0].getChangedPaths();
assertEquals("wrong number of chang pathes", 20, cp.size());
ChangePath changedApath = cp.toArray(new ChangePath[1])[0];
assertNotNull("wrong path", changedApath);
assertEquals("wrong copy source rev", -1,
changedApath.getCopySrcRevision());
assertNull("wrong copy source path", changedApath.getCopySrcPath());
assertEquals("wrong action", ChangePath.Action.add,
changedApath.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[] = collectLogMessages(non_canonical, null,
ranges, false, true, false, 0);
}
/**
* 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();
Set<String> muPathSet = new HashSet<String>(1);
muPathSet.add(thisTest.getWCPath()+"/A/mu");
setprop(thisTest.getWCPath()+"/A/mu", Property.NEEDS_LOCK, "*");
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl().toString(), "A/mu",NodeKind.file,
CommitItemStateFlags.PropMods);
checkCommitRevision(thisTest, "bad revision number on commit", 2,
thisTest.getWCPathSet(), "message", Depth.infinity,
false, false, null, null);
File f = new File(thisTest.getWCPath()+"/A/mu");
assertEquals("file should be read only now", false, f.canWrite());
client.lock(muPathSet, "comment", false);
assertEquals("file should be read write now", true, f.canWrite());
client.unlock(muPathSet, false);
assertEquals("file should be read only now", false, f.canWrite());
client.lock(muPathSet, "comment", false);
assertEquals("file should be read write now", true, f.canWrite());
addExpectedCommitItem(thisTest.getWCPath(),
thisTest.getUrl().toString(), "A/mu",
NodeKind.file, 0);
checkCommitRevision(thisTest, "rev number from commit", -1,
thisTest.getWCPathSet(), "message", Depth.infinity,
false, false, null, null);
assertEquals("file should be read write now", true, f.canWrite());
try
{
// Attempt to lock an invalid path
client.lock(thisTest.getWCPathSet("/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";
Info[] infos = collectInfos(thisTest.getWCPath(), null, null,
Depth.empty, null);
assertEquals(failureMsg, 1, infos.length);
infos = collectInfos(thisTest.getWCPath(), null, null, Depth.infinity,
null);
assertEquals(failureMsg, 21, infos.length);
for (Info info : infos)
{
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().toString(), secondWC, null, null,
Depth.empty, false, true);
infos = collectInfos(secondWC, null, null, Depth.empty, null);
// 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";
Collection<String> changelists = new ArrayList<String>();
changelists.add(changelistName);
MyChangelistCallback clCallback = new MyChangelistCallback();
String path = fileToSVNPath(new File(thisTest.getWCPath(), "iota"),
true);
Set<String> paths = new HashSet<String>(1);
paths.add(path);
// Add a path to a changelist, and check to see if it got added
client.addToChangelist(paths, changelistName, Depth.infinity, null);
client.getChangelists(thisTest.getWCPath(), changelists,
Depth.infinity, clCallback);
Collection<String> cl = clCallback.get(path);
assertTrue(changelists.equals(cl));
// Does status report this changelist?
MyStatusCallback statusCallback = new MyStatusCallback();
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
/**
* 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,
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
MyStatusCallback statusCallback = new MyStatusCallback();
client.status(secondWC, Depth.unknown, false, false, false, false,
null, statusCallback);
Status[] secondWCStatus = statusCallback.getStatusArray();
if (!(secondWCStatus.length == 1 &&
secondWCStatus[0].getPath().endsWith("A/B/lambda") &&
secondWCStatus[0].getTextStatus() == Status.Kind.modified &&
secondWCStatus[0].getPropStatus() == Status.Kind.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(), Depth.empty, false, false, false);
addExpectedCommitItem(thisTest.getWCPath(), thisTest.getUrl(),
"A/D/H/nu", NodeKind.file,
CommitItemStateFlags.TextMods +
CommitItemStateFlags.Add);
assertEquals("wrong revision number from commit",
commit(thisTest, "log msg"), 2);
thisTest.getWc().addItem("A/D/H/nu", "This is the file 'nu'.");
statusCallback = new MyStatusCallback();
client.status(thisTest.getWCPath() + "/A/D/H/nu", Depth.immediates,
false, true, false, false, null, statusCallback);
Status status = statusCallback.getStatusArray()[0];
// 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
update(backupTest);
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.getWCPathSet(),
null, Depth.infinity, false, false,
true)[0],
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'.");
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
{
if (status != null)
statuses.add(status);
}
public Status[] getStatusArray()
{
return statuses.toArray(new Status[statuses.size()]);
}
}
private class ConstMsg implements CommitMessageCallback
{
private String message;
ConstMsg(String message)
{
this.message = message;
}
public String getLogMessage(Set<CommitItem> items)
{
return message;
}
}
private Map<String, byte[]> collectProperties(String path,
Revision revision,
Revision pegRevision, Depth depth,
Collection<String> changelists)
throws ClientException
{
final Map<String, Map<String, byte[]>> propMap =
new HashMap<String, Map<String, byte[]>>();
client.properties(path, revision, revision, depth, changelists,
new ProplistCallback () {
public void singlePath(String path, Map<String, byte[]> props)
{ propMap.put(path, props); }
});
return propMap.get(path);
}
private DirEntry[] collectDirEntries(String url, Revision revision,
Revision pegRevision, Depth depth,
int direntFields, boolean fetchLocks)
throws ClientException
{
class MyListCallback implements ListCallback
{
private List<DirEntry> dirents = new ArrayList<DirEntry>();
public void doEntry(DirEntry dirent, Lock lock)
{
// All of this is meant to retain backward compatibility with
// the old svn_client_ls-style API. For further information
// about what is going on here, see the comments in
// libsvn_client/list.c:store_dirent().
if (dirent.getPath().length() == 0)
{
if (dirent.getNodeKind() == NodeKind.file)
{
String absPath = dirent.getAbsPath();
int lastSeparator = absPath.lastIndexOf('/');
String path = absPath.substring(lastSeparator,
absPath.length());
dirent.setPath(path);
}
else
{
// It's the requested directory, which we don't want
// to add.
return;
}
}
dirents.add(dirent);
}
public DirEntry[] getDirEntryArray()
{
return dirents.toArray(new DirEntry[dirents.size()]);
}
}
MyListCallback callback = new MyListCallback();
client.list(url, revision, pegRevision, depth, direntFields,
fetchLocks, callback);
return callback.getDirEntryArray();
}
private Info[] collectInfos(String pathOrUrl, Revision revision,
Revision pegRevision, Depth depth,
Collection<String> changelists)
throws ClientException
{
final List<Info> infos = new ArrayList<Info>();
client.info2(pathOrUrl, revision, pegRevision, depth, changelists,
new InfoCallback () {
public void singleInfo(Info info)
{ infos.add(info); }
});
return infos.toArray(new Info[infos.size()]);
}
private LogMessage[] collectLogMessages(String path, Revision pegRevision,
List<RevisionRange> revisionRanges,
boolean stopOnCopy,
boolean discoverPath,
boolean includeMergedRevisions,
long limit)
throws ClientException
{
class MyLogMessageCallback implements LogMessageCallback
{
private List<LogMessage> messages = new ArrayList<LogMessage>();
public void singleMessage(Set<ChangePath> changedPaths,
long revision,
Map<String, byte[]> revprops,
boolean hasChildren)
{
String author, message;
try {
author = new String(revprops.get("svn:author"), "UTF8");
src/subversion/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java view on Meta::CPAN
}
/**
* @return Returns the date changed.
*/
public Date getChanged()
{
return changed;
}
/**
* @return Returns the source line content.
*/
public String getLine()
{
return line;
}
/**
* @return Returns the revision.
*/
public long getRevision()
{
return revision;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuffer sb = new StringBuffer();
if (revision > 0)
{
pad(sb, Long.toString(revision), 6);
sb.append(' ');
}
else
{
sb.append(" - ");
}
if (author != null)
{
pad(sb, author, 10);
sb.append(" ");
}
else
{
sb.append(" - ");
}
sb.append(line);
return sb.toString();
}
/**
* Left pad the input string to a given length, to simulate
* printf()-style output. This method appends the output to the
* class sb member.
* @param sb StringBuffer to append to
* @param val the input string
* @param len the minimum length to pad to
*/
private void pad(StringBuffer sb, String val, int len)
{
int padding = len - val.length();
for (int i = 0; i < padding; i++)
{
sb.append(' ');
}
sb.append(val);
}
}
}
/** A helper which calls update with a bunch of default args. */
private long update(OneTest thisTest)
throws ClientException
{
return client.update(thisTest.getWCPathSet(), null,
Depth.unknown, false, false, false, false)[0];
}
/** A helper which calls update with a bunch of default args. */
private long update(OneTest thisTest, String subpath)
throws ClientException
{
return client.update(thisTest.getWCPathSet(subpath), null,
Depth.unknown, false, false, false, false)[0];
}
private void setprop(String path, String name, String value)
throws ClientException
{
Set<String> paths = new HashSet<String>();
paths.add(path);
client.propertySetLocal(paths, name,
value != null ? value.getBytes() : null,
Depth.empty, null, false);
}
private void setprop(String path, String name, byte[] value)
throws ClientException
{
Set<String> paths = new HashSet<String>();
paths.add(path);
client.propertySetLocal(paths, name, value, Depth.empty,
null, false);
}
private long commit(OneTest thisTest, String msg)
throws ClientException
{
MyCommitCallback commitCallback = new MyCommitCallback();
client.commit(thisTest.getWCPathSet(), Depth.infinity,
false, false, null, null, new ConstMsg(msg),
commitCallback);
return commitCallback.getRevision();
}
}