You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/09/14 19:26:44 UTC
svn commit: r1808381 [22/25] - in /commons/proper/vfs/trunk/commons-vfs2/src:
main/java/org/apache/commons/vfs2/ main/java/org/apache/commons/vfs2/auth/
main/java/org/apache/commons/vfs2/cache/
main/java/org/apache/commons/vfs2/events/ main/java/org/ap...
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -86,8 +86,7 @@ import com.jcraft.jsch.TestIdentityRepos
* Starts and stops an embedded Apache SSHd (MINA) server.
* </p>
*/
-public class SftpProviderTestCase extends AbstractProviderTestConfig
-{
+public class SftpProviderTestCase extends AbstractProviderTestConfig {
/**
* The underlying filesystem
*/
@@ -96,17 +95,14 @@ public class SftpProviderTestCase extend
/**
* Implements FileSystemFactory because SSHd does not know about users and home directories.
*/
- static final class TestFileSystemFactory implements FileSystemFactory
- {
+ static final class TestFileSystemFactory implements FileSystemFactory {
/**
* Accepts only the known test user.
*/
@Override
- public FileSystemView createFileSystemView(final Session session) throws IOException
- {
+ public FileSystemView createFileSystemView(final Session session) throws IOException {
final String userName = session.getUsername();
- if (!DEFAULT_USER.equals(userName))
- {
+ if (!DEFAULT_USER.equals(userName)) {
return null;
}
return new TestFileSystemView(AbstractVfsTestCase.getTestDirectory(), userName);
@@ -116,34 +112,29 @@ public class SftpProviderTestCase extend
/**
* Implements FileSystemView because SSHd does not know about users and home directories.
*/
- static final class TestFileSystemView implements FileSystemView
- {
+ static final class TestFileSystemView implements FileSystemView {
private final String homeDirStr;
private final String userName;
// private boolean caseInsensitive;
- public TestFileSystemView(final String homeDirStr, final String userName)
- {
+ public TestFileSystemView(final String homeDirStr, final String userName) {
this.homeDirStr = new File(homeDirStr).getAbsolutePath();
this.userName = userName;
}
@Override
- public SshFile getFile(final SshFile baseDir, final String file)
- {
+ public SshFile getFile(final SshFile baseDir, final String file) {
return this.getFile(baseDir.getAbsolutePath(), file);
}
@Override
- public SshFile getFile(final String file)
- {
+ public SshFile getFile(final String file) {
return this.getFile(homeDirStr, file);
}
- protected SshFile getFile(final String dir, final String file)
- {
+ protected SshFile getFile(final String dir, final String file) {
final String home = removePrefix(NativeSshFile.normalizeSeparateChar(homeDirStr));
String userFileName = removePrefix(NativeSshFile.normalizeSeparateChar(file));
final File sshFile = userFileName.startsWith(home) ? new File(userFileName) : new File(home, userFileName);
@@ -151,11 +142,9 @@ public class SftpProviderTestCase extend
return new TestNativeSshFile(userFileName, sshFile, userName);
}
- private String removePrefix(final String s)
- {
+ private String removePrefix(final String s) {
final int index = s.indexOf('/');
- if (index < 1)
- {
+ if (index < 1) {
return s;
}
return s.substring(index);
@@ -163,13 +152,11 @@ public class SftpProviderTestCase extend
}
/**
- * Extends NativeSshFile because its constructor is protected and I do not want to create a whole NativeSshFile implementation for
- * testing.
+ * Extends NativeSshFile because its constructor is protected and I do not want to create a whole NativeSshFile
+ * implementation for testing.
*/
- static class TestNativeSshFile extends NativeSshFile
- {
- TestNativeSshFile(final String fileName, final File file, final String userName)
- {
+ static class TestNativeSshFile extends NativeSshFile {
+ TestNativeSshFile(final String fileName, final File file, final String userName) {
super(fileName, file, userName);
}
}
@@ -189,8 +176,7 @@ public class SftpProviderTestCase extend
/** True if we are testing the SFTP stream proxy */
private final boolean streamProxyMode;
- private static String getSystemTestUriOverride()
- {
+ private static String getSystemTestUriOverride() {
return System.getProperty(TEST_URI);
}
@@ -200,22 +186,19 @@ public class SftpProviderTestCase extend
* @throws FtpException
* @throws IOException
*/
- private static void setUpClass() throws FtpException, IOException, InterruptedException
- {
+ private static void setUpClass() throws FtpException, IOException, InterruptedException {
SocketPort = FreeSocketPortUtil.findFreeLocalPort();
// Use %40 for @ in a URL
ConnectionUri = String.format("sftp://%s@localhost:%d", DEFAULT_USER, SocketPort);
- if (Server != null)
- {
+ if (Server != null) {
return;
}
// System.setProperty("vfs.sftp.sshdir", getTestDirectory() + "/../vfs.sftp.sshdir");
final String tmpDir = System.getProperty("java.io.tmpdir");
Server = SshServer.setUpDefaultServer();
Server.setPort(SocketPort);
- if (SecurityUtils.isBouncyCastleRegistered())
- {
+ if (SecurityUtils.isBouncyCastleRegistered()) {
// A temporary file will hold the key
final File keyFile = File.createTempFile("key", ".pem", new File(tmpDir));
keyFile.deleteOnExit();
@@ -224,67 +207,54 @@ public class SftpProviderTestCase extend
final PEMGeneratorHostKeyProvider keyProvider = new PEMGeneratorHostKeyProvider(keyFile.getAbsolutePath());
Server.setKeyPairProvider(keyProvider);
- } else
- {
+ } else {
Server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(tmpDir + "/key.ser"));
}
final List<NamedFactory<Command>> list = new ArrayList<>(1);
- list.add(new NamedFactory<Command>()
- {
+ list.add(new NamedFactory<Command>() {
@Override
- public String getName()
- {
+ public String getName() {
return "sftp";
}
@Override
- public Command create()
- {
+ public Command create() {
return new MySftpSubsystem();
}
});
Server.setSubsystemFactories(list);
- Server.setPasswordAuthenticator(new PasswordAuthenticator()
- {
+ Server.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
- public boolean authenticate(final String username, final String password, final ServerSession session)
- {
+ public boolean authenticate(final String username, final String password, final ServerSession session) {
return username != null && username.equals(password);
}
});
- Server.setPublickeyAuthenticator(new PublickeyAuthenticator()
- {
+ Server.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
- public boolean authenticate(final String username, final PublicKey key, final ServerSession session)
- {
+ public boolean authenticate(final String username, final PublicKey key, final ServerSession session) {
// File f = new File("/Users/" + username + "/.ssh/authorized_keys");
return true;
}
});
- Server.setForwardingFilter(new ForwardingFilter()
- {
+ Server.setForwardingFilter(new ForwardingFilter() {
@Override
- public boolean canConnect(final InetSocketAddress address, final ServerSession session)
- {
+ public boolean canConnect(final InetSocketAddress address, final ServerSession session) {
return true;
}
@Override
- public boolean canForwardAgent(final ServerSession session)
- {
+ public boolean canForwardAgent(final ServerSession session) {
return true;
}
@Override
- public boolean canForwardX11(final ServerSession session)
- {
+ public boolean canForwardX11(final ServerSession session) {
return true;
}
@Override
- public boolean canListen(final InetSocketAddress address, final ServerSession session)
- {
+ public boolean canListen(final InetSocketAddress address, final ServerSession session) {
return true;
}
});
@@ -302,17 +272,14 @@ public class SftpProviderTestCase extend
// HACK End
}
-
static private class BaseProviderTestSuite extends ProviderTestSuite {
- public BaseProviderTestSuite(final ProviderTestConfig providerConfig) throws Exception
- {
+ public BaseProviderTestSuite(final ProviderTestConfig providerConfig) throws Exception {
super(providerConfig);
}
@Override
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
// Close all active sessions
// Note that it should be done by super.tearDown()
// while closing
@@ -327,8 +294,7 @@ public class SftpProviderTestCase extend
/**
* Creates the test suite for the ftp file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
// The test suite to be returned
final TestSuite suite = new TestSuite();
@@ -341,47 +307,38 @@ public class SftpProviderTestCase extend
suite.addTest(sftpSuite);
-
// --- VFS-440: stream proxy test suite
// We override the addBaseTests method so that only
// one test is run (we just test that the input/output are correctly forwarded, and
// hence if the reading test succeeds/fails the other will also succeed/fail)
final SftpProviderTestCase streamProxyTestCase = new SftpProviderTestCase(true);
- final ProviderTestSuite sftpStreamSuite = new BaseProviderTestSuite(streamProxyTestCase)
- {
+ final ProviderTestSuite sftpStreamSuite = new BaseProviderTestSuite(streamProxyTestCase) {
@Override
- protected void addBaseTests() throws Exception
- {
+ protected void addBaseTests() throws Exception {
// Just tries to read
addTests(ProviderReadTests.class);
}
};
suite.addTest(sftpStreamSuite);
-
// Decorate the test suite to set up the Sftp server
- final TestSetup setup = new TestSetup(suite)
- {
+ final TestSetup setup = new TestSetup(suite) {
@Override
- protected void setUp() throws Exception
- {
- if (getSystemTestUriOverride() == null)
- {
+ protected void setUp() throws Exception {
+ if (getSystemTestUriOverride() == null) {
setUpClass();
}
super.setUp();
}
@Override
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
// Close SFTP server if needed
tearDownClass();
super.tearDown();
}
};
-
return setup;
}
@@ -390,16 +347,13 @@ public class SftpProviderTestCase extend
*
* @throws InterruptedException
*/
- private static void tearDownClass() throws InterruptedException
- {
- if (Server != null)
- {
+ private static void tearDownClass() throws InterruptedException {
+ if (Server != null) {
Server.stop();
}
}
- public SftpProviderTestCase(final boolean streamProxyMode) throws IOException
- {
+ public SftpProviderTestCase(final boolean streamProxyMode) throws IOException {
this.streamProxyMode = streamProxyMode;
}
@@ -407,11 +361,9 @@ public class SftpProviderTestCase extend
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
String uri = getSystemTestUriOverride();
- if (uri == null)
- {
+ if (uri == null) {
uri = ConnectionUri;
}
@@ -421,8 +373,7 @@ public class SftpProviderTestCase extend
builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo());
builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());
- if (streamProxyMode)
- {
+ if (streamProxyMode) {
final FileSystemOptions proxyOptions = (FileSystemOptions) fileSystemOptions.clone();
final URI parsedURI = new URI(uri);
@@ -431,8 +382,7 @@ public class SftpProviderTestCase extend
builder.setProxyType(fileSystemOptions, SftpFileSystemConfigBuilder.PROXY_STREAM);
builder.setProxyUser(fileSystemOptions, userFields[0]);
- if (userFields.length > 1)
- {
+ if (userFields.length > 1) {
builder.setProxyPassword(fileSystemOptions, userFields[1]);
}
builder.setProxyHost(fileSystemOptions, parsedURI.getHost());
@@ -454,111 +404,91 @@ public class SftpProviderTestCase extend
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("sftp", new SftpFileProvider());
}
-
/**
- * The command factory for the SSH server:
- * Handles these commands
+ * The command factory for the SSH server: Handles these commands
* <p>
* <li><code>id -u</code> (permissions test)</li>
* <li><code>id -G</code> (permission tests)</li>
* <li><code>nc -q 0 localhost port</code> (Stream proxy tests)</li>
* </p>
*/
- private static class TestCommandFactory extends ScpCommandFactory
- {
+ private static class TestCommandFactory extends ScpCommandFactory {
public static final Pattern NETCAT_COMMAND = Pattern.compile("nc -q 0 localhost (\\d+)");
@Override
- public Command createCommand(final String command)
- {
- return new Command()
- {
+ public Command createCommand(final String command) {
+ return new Command() {
public ExitCallback callback = null;
public OutputStream out = null;
public OutputStream err = null;
public InputStream in = null;
@Override
- public void setInputStream(final InputStream in)
- {
+ public void setInputStream(final InputStream in) {
this.in = in;
}
@Override
- public void setOutputStream(final OutputStream out)
- {
+ public void setOutputStream(final OutputStream out) {
this.out = out;
}
@Override
- public void setErrorStream(final OutputStream err)
- {
+ public void setErrorStream(final OutputStream err) {
this.err = err;
}
@Override
- public void setExitCallback(final ExitCallback callback)
- {
+ public void setExitCallback(final ExitCallback callback) {
this.callback = callback;
}
@Override
- public void start(final Environment env) throws IOException
- {
+ public void start(final Environment env) throws IOException {
int code = 0;
- if (command.equals("id -G") || command.equals("id -u"))
- {
+ if (command.equals("id -G") || command.equals("id -u")) {
new PrintStream(out).println(0);
- } else if (NETCAT_COMMAND.matcher(command).matches())
- {
+ } else if (NETCAT_COMMAND.matcher(command).matches()) {
final Matcher matcher = NETCAT_COMMAND.matcher(command);
matcher.matches();
final int port = Integer.parseInt(matcher.group(1));
final Socket socket = new Socket((String) null, port);
- if (out != null)
- {
+ if (out != null) {
connect("from nc", socket.getInputStream(), out, null);
}
- if (in != null)
- {
+ if (in != null) {
connect("to nc", in, socket.getOutputStream(), callback);
}
return;
- } else
- {
- if (err != null)
- {
+ } else {
+ if (err != null) {
new PrintStream(err).format("Unknown command %s%n", command);
}
code = -1;
}
- if (out != null)
- {
+ if (out != null) {
out.flush();
}
- if (err != null)
- {
+ if (err != null) {
err.flush();
}
callback.onExit(code);
}
@Override
- public void destroy()
- {
+ public void destroy() {
}
};
}
@@ -566,45 +496,35 @@ public class SftpProviderTestCase extend
/**
* Creates a pipe thread that connects an input to an output
+ *
* @param name The name of the thread (for debugging purposes)
* @param in The input stream
* @param out The output stream
- * @param callback An object whose method {@linkplain ExitCallback#onExit(int)} will be
- * called when the pipe is broken. The integer argument is 0 if everything
- * went well.
- */
- private static void connect(final String name, final InputStream in, final OutputStream out, final ExitCallback callback)
- {
- final Thread thread = new Thread(new Runnable()
- {
+ * @param callback An object whose method {@linkplain ExitCallback#onExit(int)} will be called when the pipe is
+ * broken. The integer argument is 0 if everything went well.
+ */
+ private static void connect(final String name, final InputStream in, final OutputStream out,
+ final ExitCallback callback) {
+ final Thread thread = new Thread(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
int code = 0;
- try
- {
+ try {
final byte buffer[] = new byte[1024];
int len;
- while ((len = in.read(buffer, 0, buffer.length)) != -1)
- {
+ while ((len = in.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, len);
out.flush();
}
- }
- catch (final SshException ex)
- {
+ } catch (final SshException ex) {
// Nothing to do, this occurs when the connection
// is closed on the remote side
- }
- catch (final IOException ex)
- {
- if (!ex.getMessage().equals("Pipe closed"))
- {
+ } catch (final IOException ex) {
+ if (!ex.getMessage().equals("Pipe closed")) {
code = -1;
}
}
- if (callback != null)
- {
+ if (callback != null) {
callback.onExit(code);
}
}
@@ -613,9 +533,7 @@ public class SftpProviderTestCase extend
thread.start();
}
-
- private static class SftpAttrs
- {
+ private static class SftpAttrs {
int flags = 0;
private int uid;
long size = 0;
@@ -625,78 +543,66 @@ public class SftpProviderTestCase extend
private int mtime;
private String[] extended;
- private SftpAttrs(final Buffer buf)
- {
+ private SftpAttrs(final Buffer buf) {
int flags = 0;
flags = buf.getInt();
- if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0)
- {
+ if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
size = buf.getLong();
}
- if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_UIDGID) != 0)
- {
+ if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_UIDGID) != 0) {
uid = buf.getInt();
gid = buf.getInt();
}
- if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) != 0)
- {
+ if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) != 0) {
permissions = buf.getInt();
}
- if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0)
- {
+ if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
atime = buf.getInt();
}
- if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0)
- {
+ if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
mtime = buf.getInt();
}
}
}
- private static class MySftpSubsystem extends SftpSubsystem
- {
+ private static class MySftpSubsystem extends SftpSubsystem {
TreeMap<String, Integer> permissions = new TreeMap<>();
private int _version;
@Override
- protected void process(final Buffer buffer) throws IOException
- {
+ protected void process(final Buffer buffer) throws IOException {
final int rpos = buffer.rpos();
final int length = buffer.getInt();
final int type = buffer.getByte();
final int id = buffer.getInt();
- switch (type)
- {
- case SSH_FXP_SETSTAT:
- case SSH_FXP_FSETSTAT:
- {
- // Get the path
- final String path = buffer.getString();
- // Get the permission
- final SftpAttrs attrs = new SftpAttrs(buffer);
- permissions.put(path, attrs.permissions);
-// System.err.format("Setting [%s] permission to %o%n", path, attrs.permissions);
- break;
- }
-
- case SSH_FXP_REMOVE:
- {
- // Remove cached attributes
- final String path = buffer.getString();
- permissions.remove(path);
-// System.err.format("Removing [%s] permission cache%n", path);
- break;
- }
-
- case SSH_FXP_INIT:
- {
- // Just grab the version here
- this._version = id;
- break;
- }
+ switch (type) {
+ case SSH_FXP_SETSTAT:
+ case SSH_FXP_FSETSTAT: {
+ // Get the path
+ final String path = buffer.getString();
+ // Get the permission
+ final SftpAttrs attrs = new SftpAttrs(buffer);
+ permissions.put(path, attrs.permissions);
+ // System.err.format("Setting [%s] permission to %o%n", path, attrs.permissions);
+ break;
+ }
+
+ case SSH_FXP_REMOVE: {
+ // Remove cached attributes
+ final String path = buffer.getString();
+ permissions.remove(path);
+ // System.err.format("Removing [%s] permission cache%n", path);
+ break;
+ }
+
+ case SSH_FXP_INIT: {
+ // Just grab the version here
+ this._version = id;
+ break;
+ }
}
buffer.rpos(rpos);
@@ -705,45 +611,36 @@ public class SftpProviderTestCase extend
}
@Override
- protected void writeAttrs(final Buffer buffer, final SshFile file, final int flags) throws IOException
- {
+ protected void writeAttrs(final Buffer buffer, final SshFile file, final int flags) throws IOException {
if (!file.doesExist()) {
throw new FileNotFoundException(file.getAbsolutePath());
}
-
int p = 0;
final Integer cached = permissions.get(file.getAbsolutePath());
- if (cached != null)
- {
+ if (cached != null) {
// Use cached permissions
-// System.err.format("Using cached [%s] permission of %o%n", file.getAbsolutePath(), cached);
+ // System.err.format("Using cached [%s] permission of %o%n", file.getAbsolutePath(), cached);
p |= cached;
- } else
- {
+ } else {
// Use permissions from Java file
- if (file.isReadable())
- {
+ if (file.isReadable()) {
p |= S_IRUSR;
}
- if (file.isWritable())
- {
+ if (file.isWritable()) {
p |= S_IWUSR;
}
- if (file.isExecutable())
- {
+ if (file.isExecutable()) {
p |= S_IXUSR;
}
}
- if (_version >= 4)
- {
+ if (_version >= 4) {
final long size = file.getSize();
-// String username = session.getUsername();
+ // String username = session.getUsername();
final long lastModif = file.getLastModified();
- if (file.isFile())
- {
+ if (file.isFile()) {
buffer.putInt(SSH_FILEXFER_ATTR_PERMISSIONS);
buffer.putByte((byte) SSH_FILEXFER_TYPE_REGULAR);
buffer.putInt(p);
@@ -763,18 +660,17 @@ public class SftpProviderTestCase extend
p |= 0040000;
}
-
if (file.isFile()) {
- buffer.putInt(SSH_FILEXFER_ATTR_SIZE| SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_ACMODTIME);
+ buffer.putInt(SSH_FILEXFER_ATTR_SIZE | SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_ACMODTIME);
buffer.putLong(file.getSize());
buffer.putInt(p);
- buffer.putInt(file.getLastModified()/1000);
- buffer.putInt(file.getLastModified()/1000);
+ buffer.putInt(file.getLastModified() / 1000);
+ buffer.putInt(file.getLastModified() / 1000);
} else if (file.isDirectory()) {
buffer.putInt(SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_ACMODTIME);
buffer.putInt(p);
- buffer.putInt(file.getLastModified()/1000);
- buffer.putInt(file.getLastModified()/1000);
+ buffer.putInt(file.getLastModified() / 1000);
+ buffer.putInt(file.getLastModified() / 1000);
} else {
buffer.putInt(0);
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/LargeTarTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/LargeTarTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/LargeTarTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/LargeTarTestCase.java Thu Sep 14 19:26:39 2017
@@ -45,172 +45,152 @@ import org.junit.Test;
//@SuppressWarnings("nls")
public class LargeTarTestCase {
- private final static String baseDir = "target/test-classes/test-data/";
+ private final static String baseDir = "target/test-classes/test-data/";
- private DefaultFileSystemManager manager;
- private final static String largeFilePath = baseDir;
- private final static String largeFileName = "largefile";
-
-
- @Before
-public void setUp() throws Exception {
- manager = new DefaultFileSystemManager();
-
- manager.setFilesCache(new SoftRefFilesCache());
- manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
-
- manager.addProvider("file", new DefaultLocalFileProvider());
- manager.addProvider("tgz", new TarFileProvider());
- manager.addProvider("tar", new TarFileProvider());
-
- new File(baseDir).mkdir(); // if test is run standalone
- createLargeFile(largeFilePath, largeFileName);
- }
-
- @Test
- public void testLargeFile() throws Exception {
- final File realFile = new File(largeFilePath + largeFileName + ".tar.gz");
-
- final FileObject file = manager.resolveFile("tgz:file://" + realFile.getCanonicalPath() + "!/");
-
- assertNotNull(file);
- final List<FileObject> files = Arrays.asList(file.getChildren());
-
- assertNotNull(files);
- assertEquals(1, files.size());
- final FileObject f = files.get(0);
-
- assertTrue("Expected file not found: " + largeFileName + ".txt",
- f.getName().getBaseName().equals(largeFileName + ".txt"));
- }
-
-/*
- public void testFileCheck() throws Exception {
- String[] expectedFiles = {
- "plugins.tsv",
- "languages.tsv",
- "browser_type.tsv",
- "timezones.tsv",
- "color_depth.tsv",
- "resolution.tsv",
- "connection_type.tsv",
- "search_engines.tsv",
- "javascript_version.tsv",
- "operating_systems.tsv",
- "country.tsv",
- "browser.tsv"
- };
-
- fileCheck(expectedFiles, "tar:file://c:/temp/data/data/data-small.tar");
- } */
-
- protected void fileCheck(final String[] expectedFiles, final String tarFile) throws Exception {
- assertNotNull(manager);
- final FileObject file = manager.resolveFile(tarFile);
-
- assertNotNull(file);
- final List<FileObject> files = Arrays.asList(file.getChildren());
-
- assertNotNull(files);
- for (final String expectedFile : expectedFiles)
- {
- assertTrue("Expected file not found: " + expectedFile, fileExists(expectedFile, files));
- }
- }
-
- /**
- * Search for the expected file in a given list, without using the full path.
- *
- * @param expectedFile the expected file.
- * @param files a list of files to search.
- * @return {@code true} if {@code expectedFile} is in {@code files}.
- */
- protected boolean fileExists(final String expectedFile, final List<FileObject> files)
- {
- for (final FileObject file : files)
- {
- if (file.getName().getBaseName().equals(expectedFile))
- {
+ private DefaultFileSystemManager manager;
+ private final static String largeFilePath = baseDir;
+ private final static String largeFileName = "largefile";
+
+ @Before
+ public void setUp() throws Exception {
+ manager = new DefaultFileSystemManager();
+
+ manager.setFilesCache(new SoftRefFilesCache());
+ manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
+
+ manager.addProvider("file", new DefaultLocalFileProvider());
+ manager.addProvider("tgz", new TarFileProvider());
+ manager.addProvider("tar", new TarFileProvider());
+
+ new File(baseDir).mkdir(); // if test is run standalone
+ createLargeFile(largeFilePath, largeFileName);
+ }
+
+ @Test
+ public void testLargeFile() throws Exception {
+ final File realFile = new File(largeFilePath + largeFileName + ".tar.gz");
+
+ final FileObject file = manager.resolveFile("tgz:file://" + realFile.getCanonicalPath() + "!/");
+
+ assertNotNull(file);
+ final List<FileObject> files = Arrays.asList(file.getChildren());
+
+ assertNotNull(files);
+ assertEquals(1, files.size());
+ final FileObject f = files.get(0);
+
+ assertTrue("Expected file not found: " + largeFileName + ".txt",
+ f.getName().getBaseName().equals(largeFileName + ".txt"));
+ }
+
+ /*
+ * public void testFileCheck() throws Exception { String[] expectedFiles = { "plugins.tsv", "languages.tsv",
+ * "browser_type.tsv", "timezones.tsv", "color_depth.tsv", "resolution.tsv", "connection_type.tsv",
+ * "search_engines.tsv", "javascript_version.tsv", "operating_systems.tsv", "country.tsv", "browser.tsv" };
+ *
+ * fileCheck(expectedFiles, "tar:file://c:/temp/data/data/data-small.tar"); }
+ */
+
+ protected void fileCheck(final String[] expectedFiles, final String tarFile) throws Exception {
+ assertNotNull(manager);
+ final FileObject file = manager.resolveFile(tarFile);
+
+ assertNotNull(file);
+ final List<FileObject> files = Arrays.asList(file.getChildren());
+
+ assertNotNull(files);
+ for (final String expectedFile : expectedFiles) {
+ assertTrue("Expected file not found: " + expectedFile, fileExists(expectedFile, files));
+ }
+ }
+
+ /**
+ * Search for the expected file in a given list, without using the full path.
+ *
+ * @param expectedFile the expected file.
+ * @param files a list of files to search.
+ * @return {@code true} if {@code expectedFile} is in {@code files}.
+ */
+ protected boolean fileExists(final String expectedFile, final List<FileObject> files) {
+ for (final FileObject file : files) {
+ if (file.getName().getBaseName().equals(expectedFile)) {
return true;
}
}
return false;
}
- protected boolean endsWith(final String testString, final String[] testList)
- {
- for (final String string : testList)
- {
- if (testString.endsWith(string))
- {
+ protected boolean endsWith(final String testString, final String[] testList) {
+ for (final String string : testList) {
+ if (testString.endsWith(string)) {
return true;
}
}
return false;
}
- //@SuppressWarnings("unused")
- protected void createLargeFile(final String path, final String name) throws Exception {
- final long _1K = 1024;
- final long _1M = 1024 * _1K;
-// long _256M = 256 * _1M;
-// long _512M = 512 * _1M;
- final long _1G = 1024 * _1M;
-
- // File size of 3 GB
- final long fileSize = 3 * _1G;
-
- final File tarGzFile = new File(path + name + ".tar.gz");
-
- if(!tarGzFile.exists()) {
- System.out.println("This test is a bit slow. It needs to write 3GB of data as a compressed file (approx. 3MB) to your hard drive");
-
- final PipedOutputStream outTarFileStream = new PipedOutputStream();
- final PipedInputStream inTarFileStream = new PipedInputStream(outTarFileStream);
-
- final Thread source = new Thread(){
-
- @Override
- public void run() {
- final byte ba_1k[] = new byte[(int) _1K];
- for(int i=0; i < ba_1k.length; i++){
- ba_1k[i]='a';
- }
- try {
- final TarArchiveOutputStream outTarStream =
- (TarArchiveOutputStream)new ArchiveStreamFactory()
- .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);
- // Create archive contents
- final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
- tarArchiveEntry.setSize(fileSize);
-
- outTarStream.putArchiveEntry(tarArchiveEntry);
- for(long i = 0; i < fileSize; i+= ba_1k.length) {
- outTarStream.write(ba_1k);
+ // @SuppressWarnings("unused")
+ protected void createLargeFile(final String path, final String name) throws Exception {
+ final long _1K = 1024;
+ final long _1M = 1024 * _1K;
+ // long _256M = 256 * _1M;
+ // long _512M = 512 * _1M;
+ final long _1G = 1024 * _1M;
+
+ // File size of 3 GB
+ final long fileSize = 3 * _1G;
+
+ final File tarGzFile = new File(path + name + ".tar.gz");
+
+ if (!tarGzFile.exists()) {
+ System.out.println(
+ "This test is a bit slow. It needs to write 3GB of data as a compressed file (approx. 3MB) to your hard drive");
+
+ final PipedOutputStream outTarFileStream = new PipedOutputStream();
+ final PipedInputStream inTarFileStream = new PipedInputStream(outTarFileStream);
+
+ final Thread source = new Thread() {
+
+ @Override
+ public void run() {
+ final byte ba_1k[] = new byte[(int) _1K];
+ for (int i = 0; i < ba_1k.length; i++) {
+ ba_1k[i] = 'a';
+ }
+ try {
+ final TarArchiveOutputStream outTarStream = (TarArchiveOutputStream) new ArchiveStreamFactory()
+ .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);
+ // Create archive contents
+ final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
+ tarArchiveEntry.setSize(fileSize);
+
+ outTarStream.putArchiveEntry(tarArchiveEntry);
+ for (long i = 0; i < fileSize; i += ba_1k.length) {
+ outTarStream.write(ba_1k);
+ }
+ outTarStream.closeArchiveEntry();
+ outTarStream.close();
+ outTarFileStream.close();
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
}
- outTarStream.closeArchiveEntry();
- outTarStream.close();
- outTarFileStream.close();
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
- };
- source.start();
+ };
+ source.start();
- // Create compressed archive
- final OutputStream outGzipFileStream = new FileOutputStream(path + name + ".tar.gz");
+ // Create compressed archive
+ final OutputStream outGzipFileStream = new FileOutputStream(path + name + ".tar.gz");
- final GzipCompressorOutputStream outGzipStream = (GzipCompressorOutputStream)new CompressorStreamFactory()
- .createCompressorOutputStream(CompressorStreamFactory.GZIP, outGzipFileStream);
+ final GzipCompressorOutputStream outGzipStream = (GzipCompressorOutputStream) new CompressorStreamFactory()
+ .createCompressorOutputStream(CompressorStreamFactory.GZIP, outGzipFileStream);
- IOUtils.copy(inTarFileStream, outGzipStream);
- inTarFileStream.close();
+ IOUtils.copy(inTarFileStream, outGzipStream);
+ inTarFileStream.close();
- outGzipStream.close();
- outGzipFileStream.close();
+ outGzipStream.close();
+ outGzipFileStream.close();
+ }
}
- }
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java Thu Sep 14 19:26:39 2017
@@ -32,14 +32,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system, using a tar file nested inside another tar file.
*/
-public class NestedTarTestCase
- extends AbstractProviderTestConfig
-{
+public class NestedTarTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for nested tar files.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new NestedTarTestCase(), true);
}
@@ -47,9 +44,7 @@ public class NestedTarTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("tar", new TarFileProvider());
manager.addExtensionMap("tar", "tar");
manager.addMimeTypeMap("application/x-tar", "tar");
@@ -59,11 +54,11 @@ public class NestedTarTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
// We test with non-empty FS options to make sure they are propagated
final FileSystemOptions opts = new FileSystemOptions();
- DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, new StaticUserAuthenticator("domain", null, null));
+ DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
+ new StaticUserAuthenticator("domain", null, null));
// Locate the base Tar file
final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tar").getAbsolutePath();
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTbz2TestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTbz2TestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTbz2TestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTbz2TestCase.java Thu Sep 14 19:26:39 2017
@@ -29,14 +29,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system, using a tar file nested inside another tar file.
*/
-public class NestedTbz2TestCase
- extends AbstractProviderTestConfig
-{
+public class NestedTbz2TestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for nested tar files.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new NestedTbz2TestCase(), true);
}
@@ -44,9 +41,7 @@ public class NestedTbz2TestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("tbz2", new TarFileProvider());
manager.addExtensionMap("tbz2", "tbz2");
manager.addProvider("tar", new TarFileProvider());
@@ -56,8 +51,7 @@ public class NestedTbz2TestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
// Locate the base Tar file
final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tbz2").getAbsolutePath();
final String uri = "tbz2:file:" + tarFilePath + "!/test.tbz2";
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTgzTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTgzTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTgzTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTgzTestCase.java Thu Sep 14 19:26:39 2017
@@ -29,14 +29,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system, using a tar file nested inside another tar file.
*/
-public class NestedTgzTestCase
- extends AbstractProviderTestConfig
-{
+public class NestedTgzTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for nested tar files.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new NestedTgzTestCase(), true);
}
@@ -44,9 +41,7 @@ public class NestedTgzTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("tgz", new TarFileProvider());
manager.addExtensionMap("tgz", "tgz");
manager.addProvider("tar", new TarFileProvider());
@@ -56,8 +51,7 @@ public class NestedTgzTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
// Locate the base Tar file
final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tgz").getAbsolutePath();
final String uri = "tgz:file:" + tarFilePath + "!/test.tgz";
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TarProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TarProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TarProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TarProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,14 +31,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system.
*/
-public class TarProviderTestCase
- extends AbstractProviderTestConfig
-{
+public class TarProviderTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for the tar file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new TarProviderTestCase(), true);
}
@@ -46,8 +43,7 @@ public class TarProviderTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("tar", new TarFileProvider());
manager.addMimeTypeMap("application/x-tar", "tar");
}
@@ -56,8 +52,7 @@ public class TarProviderTestCase
* Returns the base folder for read tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File tarFile = AbstractVfsTestCase.getTestResource("test.tar");
final String uri = "tar:file:" + tarFile.getAbsolutePath() + "!/";
return manager.resolveFile(uri);
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/Tbz2ProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/Tbz2ProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/Tbz2ProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/Tbz2ProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,14 +31,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system.
*/
-public class Tbz2ProviderTestCase
- extends AbstractProviderTestConfig
-{
+public class Tbz2ProviderTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for the tar file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new Tbz2ProviderTestCase(), true);
}
@@ -46,8 +43,7 @@ public class Tbz2ProviderTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("tbz2", new TarFileProvider());
manager.addProvider("tar", new TarFileProvider());
}
@@ -56,8 +52,7 @@ public class Tbz2ProviderTestCase
* Returns the base folder for read tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File tarFile = AbstractVfsTestCase.getTestResource("test.tbz2");
final String uri = "tbz2:file:" + tarFile.getAbsolutePath() + "!/";
return manager.resolveFile(uri);
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TgzProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TgzProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TgzProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/TgzProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,14 +31,11 @@ import junit.framework.Test;
/**
* Tests for the Tar file system.
*/
-public class TgzProviderTestCase
- extends AbstractProviderTestConfig
-{
+public class TgzProviderTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for the tar file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new TgzProviderTestCase(), true);
}
@@ -46,8 +43,7 @@ public class TgzProviderTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
// manager.addProvider("tgz", new TgzFileProvider());
manager.addProvider("tgz", new TarFileProvider());
manager.addProvider("tar", new TarFileProvider());
@@ -57,8 +53,7 @@ public class TgzProviderTestCase
* Returns the base folder for read tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File tarFile = AbstractVfsTestCase.getTestResource("test.tgz");
final String uri = "tgz:file:" + tarFile.getAbsolutePath() + "!/";
return manager.resolveFile(uri);
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/temp/test/TemporaryProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/temp/test/TemporaryProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/temp/test/TemporaryProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/temp/test/TemporaryProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,14 +31,11 @@ import junit.framework.Test;
/**
* Test cases for the tmp: file provider.
*/
-public class TemporaryProviderTestCase
- extends AbstractProviderTestConfig
-{
+public class TemporaryProviderTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for the tmp file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new TemporaryProviderTestCase());
}
@@ -46,9 +43,7 @@ public class TemporaryProviderTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
manager.addProvider("tmp", new TemporaryFileProvider(baseDir));
}
@@ -57,8 +52,7 @@ public class TemporaryProviderTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
return manager.resolveFile("tmp:/");
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/GenericFileNameTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/GenericFileNameTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/GenericFileNameTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/GenericFileNameTestCase.java Thu Sep 14 19:26:39 2017
@@ -24,14 +24,11 @@ import org.apache.commons.vfs2.provider.
/**
* Some GenericFileName test cases.
*/
-public class GenericFileNameTestCase
- extends AbstractVfsTestCase
-{
+public class GenericFileNameTestCase extends AbstractVfsTestCase {
/**
* Tests parsing a URI into its parts.
*/
- public void testParseUri() throws Exception
- {
+ public void testParseUri() throws Exception {
final URLFileNameParser urlParser = new URLFileNameParser(21);
// Simple name
GenericFileName name = (GenericFileName) urlParser.parseUri(null, null, "ftp://hostname/file");
@@ -104,8 +101,7 @@ public class GenericFileNameTestCase
/**
* Tests error handling in URI parser.
*/
- public void testBadlyFormedUri() throws Exception
- {
+ public void testBadlyFormedUri() throws Exception {
// Does not start with ftp://
testBadlyFormedUri("ftp:", "vfs.provider/missing-double-slashes.error");
testBadlyFormedUri("ftp:/", "vfs.provider/missing-double-slashes.error");
@@ -129,15 +125,11 @@ public class GenericFileNameTestCase
/**
* Tests that parsing a URI fails with the expected error.
*/
- private void testBadlyFormedUri(final String uri, final String errorMsg)
- {
- try
- {
+ private void testBadlyFormedUri(final String uri, final String errorMsg) {
+ try {
new URLFileNameParser(80).parseUri(null, null, uri);
fail();
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
assertSameMessage(errorMsg, uri, e);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionProviderConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionProviderConfig.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionProviderConfig.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionProviderConfig.java Thu Sep 14 19:26:39 2017
@@ -24,16 +24,12 @@ import org.apache.commons.vfs2.impl.Defa
import org.apache.commons.vfs2.test.ProviderTestConfig;
/**
- * A provider config that wraps another provider, to run the tests via
- * junctions.
+ * A provider config that wraps another provider, to run the tests via junctions.
*/
-public class JunctionProviderConfig
- implements ProviderTestConfig
-{
+public class JunctionProviderConfig implements ProviderTestConfig {
private final ProviderTestConfig config;
- public JunctionProviderConfig(final ProviderTestConfig config)
- {
+ public JunctionProviderConfig(final ProviderTestConfig config) {
this.config = config;
}
@@ -46,8 +42,7 @@ public class JunctionProviderConfig
}
@Override
- public FilesCache getFilesCache()
- {
+ public FilesCache getFilesCache() {
return config.getFilesCache();
}
@@ -55,8 +50,7 @@ public class JunctionProviderConfig
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
config.prepare(manager);
}
@@ -64,8 +58,7 @@ public class JunctionProviderConfig
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final FileObject baseFolder = config.getBaseTestFolder(manager);
// Create an empty file system, then link in the base folder
@@ -77,8 +70,7 @@ public class JunctionProviderConfig
}
@Override
- public boolean isFileSystemRootAccessible()
- {
+ public boolean isFileSystemRootAccessible() {
return true;
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionTests.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionTests.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/JunctionTests.java Thu Sep 14 19:26:39 2017
@@ -27,11 +27,8 @@ import org.apache.commons.vfs2.test.Abst
/**
* Additional junction test cases.
*/
-public class JunctionTests
- extends AbstractProviderTestCase
-{
- private FileObject getBaseDir() throws FileSystemException
- {
+public class JunctionTests extends AbstractProviderTestCase {
+ private FileObject getBaseDir() throws FileSystemException {
final File file = AbstractVfsTestCase.getTestDirectoryFile();
assertTrue(file.exists());
return getManager().toFileObject(file);
@@ -40,31 +37,24 @@ public class JunctionTests
/**
* Checks nested junctions are not supported.
*/
- public void testNestedJunction() throws Exception
- {
+ public void testNestedJunction() throws Exception {
final FileSystem fs = getManager().createVirtualFileSystem("vfs:").getFileSystem();
final FileObject baseDir = getBaseDir();
fs.addJunction("/a", baseDir);
// Nested
- try
- {
+ try {
fs.addJunction("/a/b", baseDir);
fail();
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a/b", e);
}
// At same point
- try
- {
+ try {
fs.addJunction("/a", baseDir);
fail();
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a", e);
}
}
@@ -72,8 +62,7 @@ public class JunctionTests
/**
* Checks ancestors are created when a junction is created.
*/
- public void testAncestors() throws Exception
- {
+ public void testAncestors() throws Exception {
final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem();
final FileObject baseDir = getBaseDir();
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/VirtualProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/VirtualProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/VirtualProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/test/VirtualProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -29,11 +29,8 @@ import org.apache.commons.vfs2.test.Prov
/**
* Test cases for the virtual file system provider.
*/
-public class VirtualProviderTestCase
- extends AbstractProviderTestConfig
-{
- public static Test suite() throws Exception
- {
+public class VirtualProviderTestCase extends AbstractProviderTestConfig {
+ public static Test suite() throws Exception {
final ProviderTestSuite testSuite = new ProviderTestSuite(new VirtualProviderTestCase());
testSuite.addTests(JunctionTests.class);
return testSuite;
@@ -43,8 +40,7 @@ public class VirtualProviderTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
final FileObject baseFile = manager.toFileObject(baseDir);
return manager.createVirtualFileSystem(baseFile);
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlHttpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlHttpProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlHttpProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlHttpProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,21 +31,16 @@ import org.apache.commons.vfs2.test.Prov
/**
* Test cases for the generic provider.
*/
-public class UrlHttpProviderTestCase
- extends AbstractProviderTestConfig
-{
- public static Test suite() throws Exception
- {
+public class UrlHttpProviderTestCase extends AbstractProviderTestConfig {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new UrlHttpProviderTestCase());
}
/**
- * Prepares the file system manager. This implementation does nothing.
+ * Prepares the file system manager. This implementation does nothing.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("http", new UrlFileProvider());
}
@@ -53,9 +48,7 @@ public class UrlHttpProviderTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager)
- throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
return manager.resolveFile(baseDir.toURI().toURL().toExternalForm());
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java Thu Sep 14 19:26:39 2017
@@ -34,8 +34,7 @@ import org.apache.commons.vfs2.util.NHtt
* Test cases for HTTP with the default provider.
*
*/
-public class UrlProviderHttpTestCase extends AbstractProviderTestConfig
-{
+public class UrlProviderHttpTestCase extends AbstractProviderTestConfig {
private static NHttpServer Server;
private static int SocketPort;
@@ -47,8 +46,7 @@ public class UrlProviderHttpTestCase ext
*/
private static String ConnectionUri;
- private static String getSystemTestUriOverride()
- {
+ private static String getSystemTestUriOverride() {
return System.getProperty(TEST_URI);
}
@@ -57,32 +55,25 @@ public class UrlProviderHttpTestCase ext
*
* @throws Exception
*/
- private static void setUpClass() throws Exception
- {
+ private static void setUpClass() throws Exception {
Server = new NHttpServer();
- if (!Server.run(SocketPort, new File(getTestDirectory()), 5000))
- {
+ if (!Server.run(SocketPort, new File(getTestDirectory()), 5000)) {
throw new IllegalStateException("The embedded HTTP server has not completed startup, increase wait time");
}
}
- public static Test suite() throws Exception
- {
- return new ProviderTestSuite(new UrlProviderHttpTestCase())
- {
+ public static Test suite() throws Exception {
+ return new ProviderTestSuite(new UrlProviderHttpTestCase()) {
@Override
- protected void setUp() throws Exception
- {
- if (getSystemTestUriOverride() == null)
- {
+ protected void setUp() throws Exception {
+ if (getSystemTestUriOverride() == null) {
setUpClass();
}
super.setUp();
}
@Override
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
tearDownClass();
super.tearDown();
}
@@ -94,16 +85,13 @@ public class UrlProviderHttpTestCase ext
*
* @throws IOException
*/
- private static void tearDownClass() throws IOException
- {
- if (Server != null)
- {
+ private static void tearDownClass() throws IOException {
+ if (Server != null) {
Server.stop();
}
}
- public UrlProviderHttpTestCase() throws IOException
- {
+ public UrlProviderHttpTestCase() throws IOException {
SocketPort = FreeSocketPortUtil.findFreeLocalPort();
// Use %40 for @ in a URL
ConnectionUri = "http://localhost:" + SocketPort;
@@ -113,11 +101,9 @@ public class UrlProviderHttpTestCase ext
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
String uri = getSystemTestUriOverride();
- if (uri == null)
- {
+ if (uri == null) {
uri = ConnectionUri;
}
return manager.resolveFile(uri);
@@ -127,8 +113,7 @@ public class UrlProviderHttpTestCase ext
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("http", new UrlFileProvider());
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,21 +31,16 @@ import org.apache.commons.vfs2.test.Prov
/**
* Test cases for the generic provider.
*/
-public class UrlProviderTestCase
- extends AbstractProviderTestConfig
-{
- public static Test suite() throws Exception
- {
+public class UrlProviderTestCase extends AbstractProviderTestConfig {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new UrlProviderTestCase());
}
/**
- * Prepares the file system manager. This implementation does nothing.
+ * Prepares the file system manager. This implementation does nothing.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("file", new UrlFileProvider());
}
@@ -53,9 +48,7 @@ public class UrlProviderTestCase
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager)
- throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
return manager.resolveFile(baseDir.toURI().toURL().toExternalForm());
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java Thu Sep 14 19:26:39 2017
@@ -52,14 +52,12 @@ import org.mortbay.jetty.webapp.WebAppCo
*
* @since 2.1
*/
-class JackrabbitMain
-{
+class JackrabbitMain {
/**
* @param args
*/
- public static void main(final String[] args) throws Exception
- {
+ public static void main(final String[] args) throws Exception {
new JackrabbitMain(args).run();
}
@@ -78,9 +76,7 @@ class JackrabbitMain
private FileAppender jackrabbitAppender;
private FileAppender jettyAppender;
-
- public JackrabbitMain(final String[] args) throws ParseException
- {
+ public JackrabbitMain(final String[] args) throws ParseException {
options.addOption("?", "help", false, "print this message");
options.addOption("n", "notice", false, "print copyright notices");
options.addOption("l", "license", false, "print license information");
@@ -97,46 +93,37 @@ class JackrabbitMain
command = new GnuParser().parse(options, args);
}
- private void copyToOutput(final String resource) throws IOException
- {
+ private void copyToOutput(final String resource) throws IOException {
final InputStream stream = JackrabbitMain.class.getResourceAsStream(resource);
- try
- {
+ try {
IOUtils.copy(stream, System.out);
- } finally
- {
+ } finally {
stream.close();
}
}
- private void message(final String message)
- {
- if (!command.hasOption("quiet"))
- {
+ private void message(final String message) {
+ if (!command.hasOption("quiet")) {
System.out.println(message);
}
}
- private void prepareAccessLog(final File log)
- {
+ private void prepareAccessLog(final File log) {
final NCSARequestLog ncsa = new NCSARequestLog(new File(log, "access.log.yyyy_mm_dd").getPath());
ncsa.setFilenameDateFormat("yyyy-MM-dd");
accessLog.setRequestLog(ncsa);
}
- private void prepareConnector()
- {
+ private void prepareConnector() {
final String port = command.getOptionValue("port", "8080");
connector.setPort(Integer.parseInt(port));
final String host = command.getOptionValue("host");
- if (host != null)
- {
+ if (host != null) {
connector.setHost(host);
}
}
- private void prepareServerLog(final File log) throws IOException
- {
+ private void prepareServerLog(final File log) throws IOException {
final Layout layout = new PatternLayout("%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m%n");
final Logger jackrabbitLog = Logger.getRootLogger();
@@ -153,18 +140,13 @@ class JackrabbitMain
System.setProperty("derby.stream.error.file", new File(log, "derby.log").getPath());
}
- private void prepareShutdown()
- {
- Runtime.getRuntime().addShutdownHook(new Thread()
- {
+ private void prepareShutdown() {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
shutdown();
- } catch (final Exception e)
- {
+ } catch (final Exception e) {
e.printStackTrace();
}
}
@@ -172,8 +154,7 @@ class JackrabbitMain
});
}
- private void prepareWebapp(final File file, final File repository, final File tmp)
- {
+ private void prepareWebapp(final File file, final File repository, final File tmp) {
webapp.setContextPath("/");
webapp.setWar(file.getPath());
webapp.setClassLoader(JackrabbitMain.class.getClassLoader());
@@ -189,50 +170,40 @@ class JackrabbitMain
servlet.setInitOrder(1);
servlet.setInitParameter("repository.home", repository.getAbsolutePath());
final String conf = command.getOptionValue("conf");
- if (conf != null)
- {
+ if (conf != null) {
servlet.setInitParameter("repository.config", conf);
}
webapp.addServlet(servlet, "/repository.properties");
}
/** Try to load a resource with various classloaders. */
- private URL getResource(final String name)
- {
+ private URL getResource(final String name) {
URL res = Thread.currentThread().getContextClassLoader().getResource(name);
- if (res == null)
- {
+ if (res == null) {
res = getClass().getResource(name);
}
return res; // might be null
}
- public void run() throws Exception
- {
+ public void run() throws Exception {
String defaultFile = "jackrabbit-standalone.jar";
final URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
- if (location != null && "file".equals(location.getProtocol()))
- {
+ if (location != null && "file".equals(location.getProtocol())) {
final File file = new File(location.getPath());
- if (file.isFile())
- {
+ if (file.isFile()) {
defaultFile = location.getPath();
}
}
final File file = new File(command.getOptionValue("file", defaultFile));
- if (command.hasOption("help"))
- {
+ if (command.hasOption("help")) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar " + file.getName(), options, true);
- } else if (command.hasOption("notice"))
- {
+ } else if (command.hasOption("notice")) {
copyToOutput("/META-INF/NOTICE.txt");
- } else if (command.hasOption("license"))
- {
+ } else if (command.hasOption("license")) {
copyToOutput("/META-INF/LICENSE.txt");
- } else
- {
+ } else {
message("Welcome to Apache Jackrabbit!");
message("-------------------------------");
@@ -257,26 +228,22 @@ class JackrabbitMain
server.addConnector(connector);
prepareShutdown();
- try
- {
+ try {
server.start();
String host = connector.getHost();
- if (host == null)
- {
+ if (host == null) {
host = "localhost";
}
message("Apache Jackrabbit is now running at " + "http://" + host + ":" + connector.getPort() + "/");
- } catch (final Throwable t)
- {
+ } catch (final Throwable t) {
System.err.println("Unable to start the server: " + t.getMessage());
System.exit(1);
}
}
}
- public void shutdown() throws Exception, InterruptedException
- {
+ public void shutdown() throws Exception, InterruptedException {
message("Shutting down the server...");
server.setGracefulShutdown(5);
server.stop();