You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mc...@apache.org on 2014/04/18 23:00:43 UTC
svn commit: r1588563 [12/16] - in /ant/core/trunk: ./ manual/ manual/Types/
src/etc/testcases/taskdefs/ src/etc/testcases/taskdefs/optional/
src/etc/testcases/taskdefs/optional/antlr/
src/etc/testcases/taskdefs/optional/depend/ src/etc/testcases/taskde...
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java Fri Apr 18 21:00:38 2014
@@ -17,6 +17,11 @@
*/
package org.apache.tools.ant.taskdefs.optional.net;
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -28,69 +33,87 @@ import java.util.Vector;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.RetryHandler;
import org.apache.tools.ant.util.Retryable;
import org.apache.tools.ant.util.regexp.RegexpMatcher;
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
-
-public class FTPTest extends BuildFileTest{
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+//FIXME these tests are more integration than unit tests and report errors badly
+public class FTPTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
// keep track of what operating systems are supported here.
private boolean supportsSymlinks = Os.isFamily("unix");
private FTPClient ftp;
- private boolean connectionSucceeded = true;
- private boolean loginSuceeded = true;
+
+ private boolean loginSuceeded = false;
+
+ private String loginFailureMessage;
+
private String tmpDir = null;
private String remoteTmpDir = null;
private String ftpFileSep = null;
private myFTP myFTPTask = new myFTP();
- public FTPTest(String name) {
- super(name);
- }
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml");
- getProject().executeTarget("setup");
- tmpDir = getProject().getProperty("tmp.dir");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml");
+ Project project = buildRule.getProject();
+ project.executeTarget("setup");
+ tmpDir = project.getProperty("tmp.dir");
ftp = new FTPClient();
- ftpFileSep = getProject().getProperty("ftp.filesep");
+ ftpFileSep = project.getProperty("ftp.filesep");
myFTPTask.setSeparator(ftpFileSep);
- myFTPTask.setProject(getProject());
+ myFTPTask.setProject(project);
remoteTmpDir = myFTPTask.resolveFile(tmpDir);
- String remoteHost = getProject().getProperty("ftp.host");
- int port = Integer.parseInt(getProject().getProperty("ftp.port"));
- String remoteUser = getProject().getProperty("ftp.user");
- String password = getProject().getProperty("ftp.password");
+ String remoteHost = project.getProperty("ftp.host");
+ int port = Integer.parseInt(project.getProperty("ftp.port"));
+ String remoteUser = project.getProperty("ftp.user");
+ String password = project.getProperty("ftp.password");
+ boolean connectionSucceeded = false;
try {
ftp.connect(remoteHost, port);
+ connectionSucceeded = true;
} catch (Exception ex) {
- connectionSucceeded = false;
- loginSuceeded = false;
- System.out.println("could not connect to host " + remoteHost + " on port " + port);
+ loginFailureMessage = "could not connect to host " + remoteHost + " on port " + port;
}
if (connectionSucceeded) {
try {
ftp.login(remoteUser, password);
+ loginSuceeded = true;
} catch (IOException ioe) {
- loginSuceeded = false;
- System.out.println("could not log on to " + remoteHost + " as user " + remoteUser);
+ loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser;
}
}
}
+ @After
public void tearDown() {
try {
- ftp.disconnect();
+ if (ftp!= null) {
+ ftp.disconnect();
+ }
} catch (IOException ioe) {
// do nothing
}
- getProject().executeTarget("cleanup");
+ buildRule.getProject().executeTarget("cleanup");
}
+
private boolean changeRemoteDir(String remoteDir) {
boolean result = true;
try {
@@ -102,104 +125,102 @@ public class FTPTest extends BuildFileTe
}
return result;
}
+
+ @Test
public void test1() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha"});
- ds.scan();
- compareFiles(ds, new String[] {} ,new String[] {"alpha"});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha"});
+ ds.scan();
+ compareFiles(ds, new String[] {} ,new String[] {"alpha"});
}
+ @Test
public void test2() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+ @Test
public void test3() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta",
- "alpha/beta/gamma"});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta",
+ "alpha/beta/gamma"});
}
+ @Test
public void testFullPathMatchesCaseSensitive() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
- ds.scan();
- compareFiles(ds, new String[] {}, new String[] {});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
+ ds.scan();
+ compareFiles(ds, new String[] {}, new String[] {});
}
+ @Test
public void testFullPathMatchesCaseInsensitive() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setCaseSensitive(false);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setCaseSensitive(false);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {});
}
+ @Test
public void test2ButCaseInsensitive() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"ALPHA/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"ALPHA/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+
+ @Test
public void test2bisButCaseInsensitive() {
- if (loginSuceeded) {
- if (changeRemoteDir(remoteTmpDir)) {
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/BETA/gamma/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha/beta/gamma"});
- }
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/BETA/gamma/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha/beta/gamma"});
}
+
+ @Test
public void testGetWithSelector() {
- expectLogContaining("ftp-get-with-selector",
- "selectors are not supported in remote filesets");
- FileSet fsDestination = (FileSet) getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(getProject());
+ buildRule.executeTarget("ftp-get-with-selector");
+ assertContains("selectors are not supported in remote filesets", buildRule.getLog());
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
dsDestination.scan();
String [] sortedDestinationDirectories = dsDestination.getIncludedDirectories();
String [] sortedDestinationFiles = dsDestination.getIncludedFiles();
@@ -211,58 +232,46 @@ public class FTPTest extends BuildFileTe
sortedDestinationFiles[counter] =
sortedDestinationFiles[counter].replace(File.separatorChar, '/');
}
- FileSet fsSource = (FileSet) getProject().getReference("fileset-source-without-selector");
- DirectoryScanner dsSource = fsSource.getDirectoryScanner(getProject());
+ FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector");
+ DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject());
dsSource.scan();
compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories);
}
+
+ @Test
public void testGetFollowSymlinksTrue() {
- if (!supportsSymlinks) {
- return;
- }
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("ftp-get-directory-symbolic-link");
- FileSet fsDestination = (FileSet) getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(getProject());
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link");
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
dsDestination.scan();
compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+
+ @Test
public void testGetFollowSymlinksFalse() {
- if (!supportsSymlinks) {
- return;
- }
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("ftp-get-directory-no-symbolic-link");
- FileSet fsDestination = (FileSet) getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(getProject());
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link");
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
dsDestination.scan();
compareFiles(dsDestination, new String[] {},
new String[] {});
}
+
+ @Test
public void testAllowSymlinks() {
- if (!supportsSymlinks) {
- return;
- }
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("symlink-setup");
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-setup");
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/"});
ds.setFollowSymlinks(true);
ds.scan();
@@ -270,76 +279,62 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha/beta/gamma"});
}
+ @Test
public void testProhibitSymlinks() {
- if (!supportsSymlinks) {
- return;
- }
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("symlink-setup");
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-setup");
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/"});
ds.setFollowSymlinks(false);
ds.scan();
compareFiles(ds, new String[] {}, new String[] {});
}
+
+ @Test
public void testFileSymlink() {
- if (!supportsSymlinks) {
- return;
- }
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("symlink-file-setup");
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-file-setup");
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/"});
ds.setFollowSymlinks(true);
ds.scan();
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {"alpha/beta/gamma"});
}
+
// father and child pattern test
+ @Test
public void testOrderOfIncludePatternsIrrelevant() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
String [] expectedFiles = {"alpha/beta/beta.xml",
"alpha/beta/gamma/gamma.xml"};
String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" };
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"});
ds.scan();
compareFiles(ds, expectedFiles, expectedDirectories);
// redo the test, but the 2 include patterns are inverted
ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"});
ds.scan();
compareFiles(ds, expectedFiles, expectedDirectories);
}
+ @Test
public void testPatternsDifferInCaseScanningSensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
ds.scan();
compareFiles(ds, new String[] {"alpha/beta/beta.xml",
@@ -347,15 +342,12 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+ @Test
public void testPatternsDifferInCaseScanningInsensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
ds.setCaseSensitive(false);
ds.scan();
@@ -364,15 +356,12 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+ @Test
public void testFullpathDiffersInCaseScanningSensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {
"alpha/beta/gamma/gamma.xml",
"alpha/beta/gamma/GAMMA.XML"
@@ -382,15 +371,12 @@ public class FTPTest extends BuildFileTe
new String[] {});
}
+ @Test
public void testFullpathDiffersInCaseScanningInsensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {
"alpha/beta/gamma/gamma.xml",
"alpha/beta/gamma/GAMMA.XML"
@@ -401,15 +387,12 @@ public class FTPTest extends BuildFileTe
new String[] {});
}
+ @Test
public void testParentDiffersInCaseScanningSensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
ds.scan();
compareFiles(ds, new String[] {"alpha/beta/beta.xml",
@@ -417,15 +400,12 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+ @Test
public void testParentDiffersInCaseScanningInsensitive() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
ds.setCaseSensitive(false);
ds.scan();
@@ -434,15 +414,12 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
+ @Test
public void testExcludeOneFile() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {
"**/*.xml"
});
@@ -453,15 +430,13 @@ public class FTPTest extends BuildFileTe
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {});
}
+
+ @Test
public void testExcludeHasPrecedence() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {
"alpha/**"
});
@@ -473,15 +448,13 @@ public class FTPTest extends BuildFileTe
new String[] {});
}
+
+ @Test
public void testAlternateIncludeExclude() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {
"alpha/**",
"alpha/beta/gamma/**"
@@ -494,15 +467,13 @@ public class FTPTest extends BuildFileTe
new String[] {"alpha"});
}
+
+ @Test
public void testAlternateExcludeInclude() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setExcludes(new String[] {
"alpha/**",
"alpha/beta/gamma/**"
@@ -515,29 +486,25 @@ public class FTPTest extends BuildFileTe
new String[] {});
}
+
/**
* Test inspired by Bug#1415.
*/
+ @Test
public void testChildrenOfExcludedDirectory() {
- if (!loginSuceeded) {
- return;
- }
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- getProject().executeTarget("children-of-excluded-dir-setup");
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("children-of-excluded-dir-setup");
FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setExcludes(new String[] {"alpha/**"});
ds.scan();
compareFiles(ds, new String[] {"delta/delta.xml"},
new String[] {"delta"});
ds = myFTPTask.newScanner(ftp);
- if (!changeRemoteDir(remoteTmpDir)) {
- return;
- }
- ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
ds.setExcludes(new String[] {"alpha"});
ds.scan();
compareFiles(ds, new String[] {"alpha/beta/beta.xml",
@@ -636,11 +603,12 @@ public class FTPTest extends BuildFileTe
* configuration is an ftp server on localhost which formats
* timestamps as GMT.
*/
+ @Test
public void testTimezonePut() {
CountLogListener log = new CountLogListener("(\\d+) files? sent");
- getProject().executeTarget("timed.test.setup");
- getProject().addBuildListener(log);
- getProject().executeTarget("timed.test.put.older");
+ buildRule.getProject().executeTarget("timed.test.setup");
+ buildRule.getProject().addBuildListener(log);
+ buildRule.getProject().executeTarget("timed.test.put.older");
assertEquals(1, log.getCount());
}
@@ -650,11 +618,12 @@ public class FTPTest extends BuildFileTe
* configuration is an ftp server on localhost which formats
* timestamps as GMT.
*/
+ @Test
public void testTimezoneGet() {
CountLogListener log = new CountLogListener("(\\d+) files? retrieved");
- getProject().executeTarget("timed.test.setup");
- getProject().addBuildListener(log);
- getProject().executeTarget("timed.test.get.older");
+ buildRule.getProject().executeTarget("timed.test.setup");
+ buildRule.getProject().addBuildListener(log);
+ buildRule.getProject().executeTarget("timed.test.get.older");
assertEquals(3, log.getCount());
}
@@ -663,6 +632,7 @@ public class FTPTest extends BuildFileTe
* Tests that the presence of one of the server config params forces
* the system type to Unix if not specified.
*/
+ @Test
public void testConfiguration1() {
int[] expectedCounts = {
1,1,0,1,0,0,0
@@ -674,6 +644,7 @@ public class FTPTest extends BuildFileTe
/**
* Tests the systemTypeKey attribute.
*/
+ @Test
public void testConfiguration2() {
int[] expectedCounts = {
1,0,0,1,1,0,0
@@ -685,6 +656,7 @@ public class FTPTest extends BuildFileTe
/**
* Tests the systemTypeKey attribute with UNIX specified.
*/
+ @Test
public void testConfiguration3() {
int[] expectedCounts = {
1,0,1,0,0,1,0
@@ -693,6 +665,7 @@ public class FTPTest extends BuildFileTe
}
+ @Test
public void testConfigurationLang() {
int[] expectedCounts = {
1,1,0,0,0,0,1
@@ -709,6 +682,7 @@ public class FTPTest extends BuildFileTe
/**
* Tests the systemTypeKey attribute.
*/
+ @Test
public void testConfigurationNone() {
int[] expectedCounts = {
0,0,0,0,0,0,0
@@ -722,7 +696,7 @@ public class FTPTest extends BuildFileTe
"custom configuration",
"custom config: system key = default (UNIX)",
"custom config: system key = UNIX",
- "custom config: server time zone ID = " + getProject().getProperty("ftp.server.timezone"),
+ "custom config: server time zone ID = " + buildRule.getProject().getProperty("ftp.server.timezone"),
"custom config: system key = WINDOWS",
"custom config: default date format = yyyy/MM/dd HH:mm",
"custom config: server language code = de"
@@ -733,8 +707,8 @@ public class FTPTest extends BuildFileTe
counter.addLogMessageToSearch(messages[i]);
}
- getProject().addBuildListener(counter);
- getProject().executeTarget(target);
+ buildRule.getProject().addBuildListener(counter);
+ buildRule.getProject().executeTarget(target);
for (int i=0; i < messages.length; i++) {
assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
}
@@ -745,9 +719,11 @@ public class FTPTest extends BuildFileTe
/**
* this test is inspired by a user reporting that deletions of directories with the ftp task do not work
*/
+ @Test
public void testFTPDelete() {
- getProject().executeTarget("ftp-delete");
+ buildRule.getProject().executeTarget("ftp-delete");
}
+
private void compareFiles(DirectoryScanner ds, String[] expectedFiles,
String[] expectedDirectories) {
String includedFiles[] = ds.getIncludedFiles();
@@ -832,43 +808,51 @@ public class FTPTest extends BuildFileTe
}
}
public void testGetWithSelectorRetryable1() {
- getProject().addTaskDefinition("ftp", oneFailureFTP.class);
+ buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class);
try {
- getProject().executeTarget("ftp-get-with-selector-retryable");
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Two retries expected, failed after one.");
}
}
+
+ @Test
public void testGetWithSelectorRetryable2() {
- getProject().addTaskDefinition("ftp", twoFailureFTP.class);
+ buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class);
try {
- getProject().executeTarget("ftp-get-with-selector-retryable");
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Two retries expected, failed after two.");
}
}
+ @Test
public void testGetWithSelectorRetryable3() {
- getProject().addTaskDefinition("ftp", threeFailureFTP.class);
+ buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class);
try {
- getProject().executeTarget("ftp-get-with-selector-retryable");
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
fail("Two retries expected, continued after two.");
} catch (BuildException bx) {
}
}
+
+ @Test
public void testGetWithSelectorRetryableRandom() {
- getProject().addTaskDefinition("ftp", randomFailureFTP.class);
+ buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class);
try {
- getProject().setProperty("ftp.retries", "forever");
- getProject().executeTarget("ftp-get-with-selector-retryable");
+ buildRule.getProject().setProperty("ftp.retries", "forever");
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Retry forever specified, but failed.");
}
}
+ @Test
public void testInitialCommand() {
performCommandTest("test-initial-command", new int[] { 1,0 });
}
+
+ @Test
public void testSiteAction() {
performCommandTest("test-site-action", new int[] { 1,0 });
}
@@ -884,8 +868,8 @@ public class FTPTest extends BuildFileTe
counter.addLogMessageToSearch(messages[i]);
}
- getProject().addBuildListener(counter);
- getProject().executeTarget(target);
+ buildRule.getProject().addBuildListener(counter);
+ buildRule.getProject().executeTarget(target);
for (int i=0; i < messages.length; i++) {
assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java Fri Apr 18 21:00:38 2014
@@ -17,36 +17,44 @@
*/
package org.apache.tools.ant.taskdefs.optional.script;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.io.File;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
/**
* Tests the examples of the <scriptdef> task.
*
* @since Ant 1.6
*/
-public class ScriptDefTest extends BuildFileTest {
+public class ScriptDefTest {
- public ScriptDefTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
}
+ @Test
public void testSimple() {
- executeTarget("simple");
+ buildRule.executeTarget("simple");
// get the fileset and its basedir
- Project p = getProject();
+ Project p = buildRule.getProject();
FileSet fileset = (FileSet) p.getReference("testfileset");
File baseDir = fileset.getDir(p);
- String log = getLog();
+ String log = buildRule.getLog();
assertTrue("Expecting attribute value printed",
log.indexOf("Attribute attr1 = test") != -1);
@@ -54,25 +62,34 @@ public class ScriptDefTest extends Build
log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
}
+ @Test
public void testNoLang() {
- expectBuildExceptionContaining("nolang",
- "Absence of language attribute not detected",
- "requires a language attribute");
+ try {
+ buildRule.executeTarget("nolang");
+ fail("Absence of language attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("requires a language attribute", ex.getMessage());
+ }
}
+ @Test
public void testNoName() {
- expectBuildExceptionContaining("noname",
- "Absence of name attribute not detected",
- "scriptdef requires a name attribute");
+ try {
+ buildRule.executeTarget("noname");
+ fail("Absence of name attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage());
+ }
}
+ @Test
public void testNestedByClassName() {
- executeTarget("nestedbyclassname");
+ buildRule.executeTarget("nestedbyclassname");
// get the fileset and its basedir
- Project p = getProject();
+ Project p = buildRule.getProject();
FileSet fileset = (FileSet) p.getReference("testfileset");
File baseDir = fileset.getDir(p);
- String log = getLog();
+ String log = buildRule.getLog();
assertTrue("Expecting attribute value to be printed",
log.indexOf("Attribute attr1 = test") != -1);
@@ -80,35 +97,47 @@ public class ScriptDefTest extends Build
log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
}
+ @Test
public void testNoElement() {
- expectOutput("noelement", "Attribute attr1 = test");
+ buildRule.executeTarget("noelement");
+ assertEquals("Attribute attr1 = test", buildRule.getOutput().trim());
}
+ @Test
public void testException() {
- expectBuildExceptionContaining("exception",
- "Should have thrown an exception in the script",
- "TypeError");
+ try {
+ buildRule.executeTarget("exception");
+ fail("Should have thrown an exception in the script");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("TypeError", ex.getMessage());
+ }
}
+ @Test
public void testDoubleDef() {
- executeTarget("doubledef");
- String log = getLog();
+ buildRule.executeTarget("doubledef");
+ String log = buildRule.getLog();
assertTrue("Task1 did not execute",
log.indexOf("Task1") != -1);
assertTrue("Task2 did not execute",
log.indexOf("Task2") != -1);
}
+ @Test
public void testDoubleAttribute() {
- expectBuildExceptionContaining("doubleAttributeDef",
- "Should have detected duplicate attribute definition",
- "attr1 attribute more than once");
+ try {
+ buildRule.executeTarget("doubleAttributeDef");
+ fail("Should have detected duplicate attirbute definition");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("attr1 attribute more than once", ex.getMessage());
+ }
}
+ @Test
public void testProperty() {
- executeTarget("property");
+ buildRule.executeTarget("property");
// get the fileset and its basedir
- String log = getLog();
+ String log = buildRule.getLog();
assertTrue("Expecting property in attribute value replaced",
log.indexOf("Attribute value = test") != -1);
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java Fri Apr 18 21:00:38 2014
@@ -19,17 +19,25 @@ package org.apache.tools.ant.taskdefs.op
import java.io.File;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Testcase to ensure that command line generation and required attributes are
* correct.
*
*/
-public class SOSTest extends BuildFileTest {
+public class SOSTest {
private Commandline commandline;
@@ -46,33 +54,19 @@ public class SOSTest extends BuildFileTe
private static final String SOS_HOME = "/home/user/.sos";
private static final String VERSION = "007";
- /**
- * Constructor for the SOSTest object
- *
- * @param s Test name
- */
- public SOSTest(String s) {
- super(s);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ private Project project;
- /**
- * The JUnit setup method
- *
- * @throws Exception
- */
- protected void setUp()
- throws Exception {
+ @Before
+ public void setUp() {
project = new Project();
+ project.init();
project.setBasedir(".");
}
- /**
- * The teardown method for JUnit
- *
- * @throws Exception
- */
- protected void tearDown()
- throws Exception {
+ @After
+ public void tearDown() {
File file = new File(project.getBaseDir(), LOCAL_PATH);
if (file.exists()) {
file.delete();
@@ -80,6 +74,7 @@ public class SOSTest extends BuildFileTe
}
/** Test SOSGetFile flags & commandline generation */
+ @Test
public void testGetFileFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file",
SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name",
@@ -110,6 +105,7 @@ public class SOSTest extends BuildFileTe
}
/** Test SOSGetProject flags & commandline generation */
+ @Test
public void testGetProjectFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive",
"-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
@@ -137,8 +133,9 @@ public class SOSTest extends BuildFileTe
}
/** Tests SOSGet required attributes. */
+ @Test
public void testGetExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!");
expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!");
expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!");
@@ -146,6 +143,7 @@ public class SOSTest extends BuildFileTe
}
/** Test CheckInFile option flags */
+ @Test
public void testCheckinFileFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file",
SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
@@ -176,6 +174,7 @@ public class SOSTest extends BuildFileTe
}
/** Test CheckInProject option flags */
+ @Test
public void testCheckinProjectFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject",
"-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
@@ -203,8 +202,9 @@ public class SOSTest extends BuildFileTe
}
/** Test SOSCheckIn required attributes. */
+ @Test
public void testCheckinExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!");
expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!");
expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!");
@@ -212,6 +212,7 @@ public class SOSTest extends BuildFileTe
}
/** Test CheckOutFile option flags */
+ @Test
public void testCheckoutFileFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file",
SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
@@ -241,6 +242,7 @@ public class SOSTest extends BuildFileTe
}
/** Test CheckOutProject option flags */
+ @Test
public void testCheckoutProjectFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject",
"-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
@@ -267,8 +269,9 @@ public class SOSTest extends BuildFileTe
}
/** Test SOSCheckout required attributes. */
+ @Test
public void testCheckoutExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!");
expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!");
expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!");
@@ -276,6 +279,7 @@ public class SOSTest extends BuildFileTe
}
/** Test Label option flags */
+ @Test
public void testLabelFlags() {
String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server",
SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database",
@@ -301,8 +305,9 @@ public class SOSTest extends BuildFileTe
}
/** Test SOSLabel required attributes. */
+ @Test
public void testLabelExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!");
expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!");
expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!");
@@ -310,6 +315,16 @@ public class SOSTest extends BuildFileTe
expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!");
}
+ private void expectSpecificBuildException(String target, String errorMessage,
+ String exceptionMessage) {
+ try {
+ buildRule.executeTarget(target);
+ fail(errorMessage);
+ } catch(BuildException ex) {
+ assertEquals(exceptionMessage, ex.getMessage());
+ }
+ }
+
/**
* Iterate through the generated command line comparing it to reference
* one.
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java Fri Apr 18 21:00:38 2014
@@ -30,25 +30,19 @@ import org.apache.tools.ant.Project;
*/
public class SplashScreenTest {
- public static void main(String[] args) {
+ public static void main(String[] args) throws InterruptedException {
Project p = new Project();
SplashTask t = new SplashTask();
t.setProject(p);
t.execute();
// give it some time to display
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- } // end of try-catch
+ Thread.sleep(2000);
p.fireBuildFinished(null);
System.err.println("finished");
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- } // end of try-catch
+ Thread.sleep(2000);
System.err.println("exiting");
System.exit(0);
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java Fri Apr 18 21:00:38 2014
@@ -18,18 +18,26 @@
package org.apache.tools.ant.taskdefs.optional.ssh;
-import junit.framework.TestCase;
-
-import java.io.*;
-import java.util.List;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.FilesMatch;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.selectors.FilenameSelector;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* This is a unit test for the Scp task in Ant. It must be
@@ -47,7 +55,7 @@ import org.apache.tools.ant.types.select
* supports RSA and DSA keys. If it is not present
* this task setTrust() to true. (optional)
*/
-public class ScpTest extends TestCase {
+public class ScpTest {
private File tempDir;
private String sshHostUri = System.getProperty("scp.host");
@@ -56,24 +64,26 @@ public class ScpTest extends TestCase {
private List cleanUpList = new ArrayList();
- public ScpTest(String testname) {
- super(testname);
+ public ScpTest() {
if (System.getProperty("scp.tmp") != null) {
tempDir = new File(System.getProperty("scp.tmp"));
}
}
- protected void setUp() {
+ @Before
+ public void setUp() {
cleanUpList.clear();
}
- protected void tearDown() {
+ @After
+ public void tearDown() {
for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) {
File file = (File) i.next();
file.delete();
}
}
+ @Test
public void testSingleFileUploadAndDownload() throws IOException {
assertNotNull("system property scp.tmp must be set", tempDir);
File uploadFile = createTemporaryFile();
@@ -86,9 +96,8 @@ public class ScpTest extends TestCase {
File testFile = new File( tempDir.getPath() + File.separator +
"download-testSingleFileUploadAndDownload.test" );
- addCleanup( testFile );
- assertTrue( "Assert that the testFile does not exist.",
- !testFile.exists() );
+ addCleanup(testFile );
+ assertFalse("Assert that the testFile does not exist.", testFile.exists());
// download
scpTask = createTask();
@@ -100,6 +109,7 @@ public class ScpTest extends TestCase {
compareFiles( uploadFile, testFile );
}
+ @Test
public void testMultiUploadAndDownload() throws IOException {
assertNotNull("system property scp.tmp must be set", tempDir);
List uploadList = new ArrayList();
@@ -137,6 +147,7 @@ public class ScpTest extends TestCase {
}
}
+ @Test
public void testRemoteToDir() throws IOException {
Scp scpTask = createTask();
@@ -149,6 +160,7 @@ public class ScpTest extends TestCase {
catch (BuildException e)
{
// expected
+ //TODO we should be asserting a value in here
}
// And this one should work
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java Fri Apr 18 21:00:38 2014
@@ -29,11 +29,21 @@
package org.apache.tools.ant.taskdefs.optional.unix;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.taskdefs.condition.Os;
-import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.SymbolicLinkUtils;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
@@ -46,249 +56,240 @@ import java.io.File;
*
*/
-public class SymlinkTest extends BuildFileTest {
+public class SymlinkTest {
- private Project p;
- private boolean supportsSymlinks = Os.isFamily("unix");
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- public SymlinkTest(String name) {
- super(name);
- }
+ private boolean supportsSymlinks = Os.isFamily("unix");
+ @Before
public void setUp() {
- if (supportsSymlinks) {
- configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
- executeTarget("setUp");
- }
+ Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks);
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
+ buildRule.executeTarget("setUp");
}
-
+ @Test
public void testSingle() {
- if (supportsSymlinks) {
- executeTarget("test-single");
- p = getProject();
- assertNotNull("Failed to create file",
+ buildRule.executeTarget("test-single");
+ Project p = buildRule.getProject();
+ assertNotNull("Failed to create file",
p.getProperty("test.single.file.created"));
- assertNotNull("Failed to create link",
+ assertNotNull("Failed to create link",
p.getProperty("test.single.link.created"));
- }
}
+ @Test
public void testDelete() {
- if (supportsSymlinks) {
- executeTarget("test-delete");
- p = getProject();
- String linkDeleted = p.getProperty("test.delete.link.still.there");
- assertNotNull("Actual file deleted by symlink",
- p.getProperty("test.delete.file.still.there"));
- if (linkDeleted != null) {
- fail(linkDeleted);
- }
+ buildRule.executeTarget("test-delete");
+ Project p = buildRule.getProject();
+ String linkDeleted = p.getProperty("test.delete.link.still.there");
+ assertNotNull("Actual file deleted by symlink",
+ p.getProperty("test.delete.file.still.there"));
+ if (linkDeleted != null) {
+ fail(linkDeleted);
}
}
+ @Test
public void testRecord() {
- if (supportsSymlinks) {
- executeTarget("test-record");
- p = getProject();
-
- assertNotNull("Failed to create dir1",
- p.getProperty("test.record.dir1.created"));
+ buildRule.executeTarget("test-record");
+ Project p = buildRule.getProject();
- assertNotNull("Failed to create dir2",
- p.getProperty("test.record.dir2.created"));
+ assertNotNull("Failed to create dir1",
+ p.getProperty("test.record.dir1.created"));
- assertNotNull("Failed to create file1",
- p.getProperty("test.record.file1.created"));
+ assertNotNull("Failed to create dir2",
+ p.getProperty("test.record.dir2.created"));
- assertNotNull("Failed to create file2",
- p.getProperty("test.record.file2.created"));
+ assertNotNull("Failed to create file1",
+ p.getProperty("test.record.file1.created"));
- assertNotNull("Failed to create fileA",
- p.getProperty("test.record.fileA.created"));
+ assertNotNull("Failed to create file2",
+ p.getProperty("test.record.file2.created"));
- assertNotNull("Failed to create fileB",
- p.getProperty("test.record.fileB.created"));
+ assertNotNull("Failed to create fileA",
+ p.getProperty("test.record.fileA.created"));
- assertNotNull("Failed to create fileC",
- p.getProperty("test.record.fileC.created"));
+ assertNotNull("Failed to create fileB",
+ p.getProperty("test.record.fileB.created"));
- assertNotNull("Failed to create link1",
- p.getProperty("test.record.link1.created"));
+ assertNotNull("Failed to create fileC",
+ p.getProperty("test.record.fileC.created"));
- assertNotNull("Failed to create link2",
- p.getProperty("test.record.link2.created"));
+ assertNotNull("Failed to create link1",
+ p.getProperty("test.record.link1.created"));
- assertNotNull("Failed to create link3",
- p.getProperty("test.record.link3.created"));
+ assertNotNull("Failed to create link2",
+ p.getProperty("test.record.link2.created"));
- assertNotNull("Failed to create dirlink",
- p.getProperty("test.record.dirlink.created"));
+ assertNotNull("Failed to create link3",
+ p.getProperty("test.record.link3.created"));
- assertNotNull("Failed to create dirlink2",
- p.getProperty("test.record.dirlink2.created"));
+ assertNotNull("Failed to create dirlink",
+ p.getProperty("test.record.dirlink.created"));
- assertNotNull("Couldn't record links in dir1",
- p.getProperty("test.record.dir1.recorded"));
+ assertNotNull("Failed to create dirlink2",
+ p.getProperty("test.record.dirlink2.created"));
- assertNotNull("Couldn't record links in dir2",
- p.getProperty("test.record.dir2.recorded"));
+ assertNotNull("Couldn't record links in dir1",
+ p.getProperty("test.record.dir1.recorded"));
- String dir3rec = p.getProperty("test.record.dir3.recorded");
+ assertNotNull("Couldn't record links in dir2",
+ p.getProperty("test.record.dir2.recorded"));
- if (dir3rec != null) {
- fail(dir3rec);
- }
+ String dir3rec = p.getProperty("test.record.dir3.recorded");
+ if (dir3rec != null) {
+ fail(dir3rec);
}
+
}
+ @Test
public void testRecreate() {
- if (supportsSymlinks) {
- executeTarget("test-recreate");
- p = getProject();
- String link1Rem = p.getProperty("test.recreate.link1.not.removed");
- String link2Rem = p.getProperty("test.recreate.link2.not.removed");
- String link3Rem = p.getProperty("test.recreate.link3.not.removed");
- String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
- if (link1Rem != null) {
- fail(link1Rem);
- }
- if (link2Rem != null) {
- fail(link2Rem);
- }
- if (link3Rem != null) {
- fail(link3Rem);
- }
- if (dirlinkRem != null) {
- fail(dirlinkRem);
- }
- assertNotNull("Failed to recreate link1",
- p.getProperty("test.recreate.link1.recreated"));
- assertNotNull("Failed to recreate link2",
- p.getProperty("test.recreate.link2.recreated"));
- assertNotNull("Failed to recreate link3",
- p.getProperty("test.recreate.link3.recreated"));
- assertNotNull("Failed to recreate dirlink",
- p.getProperty("test.recreate.dirlink.recreated"));
-
- String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");
-
- if (doubleRecreate != null) {
- fail(doubleRecreate);
- }
+ buildRule.executeTarget("test-recreate");
+ Project p = buildRule.getProject();
+ String link1Rem = p.getProperty("test.recreate.link1.not.removed");
+ String link2Rem = p.getProperty("test.recreate.link2.not.removed");
+ String link3Rem = p.getProperty("test.recreate.link3.not.removed");
+ String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
+ if (link1Rem != null) {
+ fail(link1Rem);
+ }
+ if (link2Rem != null) {
+ fail(link2Rem);
+ }
+ if (link3Rem != null) {
+ fail(link3Rem);
+ }
+ if (dirlinkRem != null) {
+ fail(dirlinkRem);
+ }
+ assertNotNull("Failed to recreate link1",
+ p.getProperty("test.recreate.link1.recreated"));
+ assertNotNull("Failed to recreate link2",
+ p.getProperty("test.recreate.link2.recreated"));
+ assertNotNull("Failed to recreate link3",
+ p.getProperty("test.recreate.link3.recreated"));
+ assertNotNull("Failed to recreate dirlink",
+ p.getProperty("test.recreate.dirlink.recreated"));
- assertNotNull("Failed to alter dirlink3",
- p.getProperty("test.recreate.dirlink3.was.altered"));
+ String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");
+ if (doubleRecreate != null) {
+ fail(doubleRecreate);
}
+
+ assertNotNull("Failed to alter dirlink3",
+ p.getProperty("test.recreate.dirlink3.was.altered"));
}
+ @Test
public void testSymbolicLinkUtilsMethods() throws Exception {
- if (supportsSymlinks) {
- executeTarget("test-fileutils");
- SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils();
-
- java.io.File f = new File(getOutputDir(), "file1");
- assertTrue(f.exists());
- assertFalse(f.isDirectory());
- assertTrue(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(getOutputDir(), "dir1");
- assertTrue(f.exists());
- assertTrue(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(getOutputDir(), "file2");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(getOutputDir(), "dir2");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
-
- f = new File(getOutputDir(), "file.there");
- assertTrue(f.exists());
- assertFalse(f.isDirectory());
- assertTrue(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(getOutputDir(), "dir.there");
- assertTrue(f.exists());
- assertTrue(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- // it is not possible to find out that symbolic links pointing
- // to inexistent files or directories are symbolic links
- // it used to be possible to detect this on Mac
- // this is not true under Snow Leopard and JDK 1.5
- // Removing special handling of MacOS until someone shouts
- // Antoine
- f = new File(getOutputDir(), "file.notthere");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
- assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
- assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(getOutputDir(), "dir.notthere");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
- assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
- assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
- }
+ buildRule.executeTarget("test-fileutils");
+ SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils();
+
+ java.io.File f = new File(buildRule.getOutputDir(), "file1");
+ assertTrue(f.exists());
+ assertFalse(f.isDirectory());
+ assertTrue(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir1");
+ assertTrue(f.exists());
+ assertTrue(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "file2");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir2");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+
+ f = new File(buildRule.getOutputDir(), "file.there");
+ assertTrue(f.exists());
+ assertFalse(f.isDirectory());
+ assertTrue(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir.there");
+ assertTrue(f.exists());
+ assertTrue(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ // it is not possible to find out that symbolic links pointing
+ // to inexistent files or directories are symbolic links
+ // it used to be possible to detect this on Mac
+ // this is not true under Snow Leopard and JDK 1.5
+ // Removing special handling of MacOS until someone shouts
+ // Antoine
+ f = new File(buildRule.getOutputDir(), "file.notthere");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
+ assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
+ assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir.notthere");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
+ assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
+ assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
}
+ @After
public void tearDown() {
- if (supportsSymlinks) {
- executeTarget("tearDown");
- }
+ buildRule.executeTarget("tearDown");
}
}