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 [23/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/webdav/test/JcrUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JcrUtils.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/JcrUtils.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JcrUtils.java Thu Sep 14 19:26:39 2017
@@ -33,8 +33,7 @@ import javax.jcr.Value;
*
* @since 2.1
*/
-class JcrUtils
-{
+class JcrUtils {
private static final String NodeType_NT_RESOURCE = "nt:resource";
@@ -53,58 +52,50 @@ class JcrUtils
private static final String Property_JCR_DATA = "jcr:data";
/**
- * Returns the named child of the given node, creating it as an nt:folder node if it does not already exist. The caller is expected to
- * take care of saving or discarding any transient changes.
+ * Returns the named child of the given node, creating it as an nt:folder node if it does not already exist. The
+ * caller is expected to take care of saving or discarding any transient changes.
* <p>
- * Note that the type of the returned node is <em>not</em> guaranteed to match nt:folder in case the node already existed. The caller
- * can use an explicit {@link Node#isNodeType(String)} check if needed, or simply use a data-first approach and not worry about the node
- * type until a constraint violation is encountered.
+ * Note that the type of the returned node is <em>not</em> guaranteed to match nt:folder in case the node already
+ * existed. The caller can use an explicit {@link Node#isNodeType(String)} check if needed, or simply use a
+ * data-first approach and not worry about the node type until a constraint violation is encountered.
*
- * @param parent
- * parent node
- * @param name
- * name of the child node
+ * @param parent parent node
+ * @param name name of the child node
* @return the child node
- * @throws RepositoryException
- * if the child node can not be accessed or created
+ * @throws RepositoryException if the child node can not be accessed or created
*/
- public static Node getOrAddFolder(final Node parent, final String name) throws RepositoryException
- {
+ public static Node getOrAddFolder(final Node parent, final String name) throws RepositoryException {
return getOrAddNode(parent, name, NodeType_NT_FOLDER);
}
/**
- * Returns the named child of the given node, creating the child if it does not already exist. If the child node gets added, then it is
- * created with the given node type. The caller is expected to take care of saving or discarding any transient changes.
+ * Returns the named child of the given node, creating the child if it does not already exist. If the child node
+ * gets added, then it is created with the given node type. The caller is expected to take care of saving or
+ * discarding any transient changes.
*
* @see Node#getNode(String)
* @see Node#addNode(String, String)
* @see Node#isNodeType(String)
- * @param parent
- * parent node
- * @param name
- * name of the child node
- * @param type
- * type of the child node, ignored if the child already exists
+ * @param parent parent node
+ * @param name name of the child node
+ * @param type type of the child node, ignored if the child already exists
* @return the child node
- * @throws RepositoryException
- * if the child node can not be accessed or created
+ * @throws RepositoryException if the child node can not be accessed or created
*/
- public static Node getOrAddNode(final Node parent, final String name, final String type) throws RepositoryException
- {
- if (parent.hasNode(name))
- {
+ public static Node getOrAddNode(final Node parent, final String name, final String type)
+ throws RepositoryException {
+ if (parent.hasNode(name)) {
return parent.getNode(name);
}
return parent.addNode(name, type);
}
/**
- * Creates or updates the named child of the given node. If the child does not already exist, then it is created using the nt:file node
- * type. This file child node is returned from this method.
+ * Creates or updates the named child of the given node. If the child does not already exist, then it is created
+ * using the nt:file node type. This file child node is returned from this method.
* <p>
- * If the file node does not already contain a jcr:content child, then one is created using the nt:resource node type. The following
- * properties are set on the jcr:content node:
+ * If the file node does not already contain a jcr:content child, then one is created using the nt:resource node
+ * type. The following properties are set on the jcr:content node:
* <dl>
* <dt>jcr:mimeType</dt>
* <dd>media type</dd>
@@ -116,35 +107,31 @@ class JcrUtils
* <dd>binary content</dd>
* </dl>
* <p>
- * Note that the types of the returned node or the jcr:content child are <em>not</em> guaranteed to match nt:file and nt:resource in
- * case the nodes already existed. The caller can use an explicit {@link Node#isNodeType(String)} check if needed, or simply use a
- * data-first approach and not worry about the node type until a constraint violation is encountered.
+ * Note that the types of the returned node or the jcr:content child are <em>not</em> guaranteed to match nt:file
+ * and nt:resource in case the nodes already existed. The caller can use an explicit {@link Node#isNodeType(String)}
+ * check if needed, or simply use a data-first approach and not worry about the node type until a constraint
+ * violation is encountered.
* <p>
* The given binary content stream is closed by this method.
*
- * @param parent
- * parent node
- * @param name
- * name of the file
- * @param mime
- * media type of the file
- * @param data
- * binary content of the file
+ * @param parent parent node
+ * @param name name of the file
+ * @param mime media type of the file
+ * @param data binary content of the file
* @return the child node
- * @throws RepositoryException
- * if the child node can not be created or updated
+ * @throws RepositoryException if the child node can not be created or updated
*/
- public static Node putFile(final Node parent, final String name, final String mime, final InputStream data) throws RepositoryException
- {
+ public static Node putFile(final Node parent, final String name, final String mime, final InputStream data)
+ throws RepositoryException {
return putFile(parent, name, mime, data, Calendar.getInstance());
}
/**
- * Creates or updates the named child of the given node. If the child does not already exist, then it is created using the nt:file node
- * type. This file child node is returned from this method.
+ * Creates or updates the named child of the given node. If the child does not already exist, then it is created
+ * using the nt:file node type. This file child node is returned from this method.
* <p>
- * If the file node does not already contain a jcr:content child, then one is created using the nt:resource node type. The following
- * properties are set on the jcr:content node:
+ * If the file node does not already contain a jcr:content child, then one is created using the nt:resource node
+ * type. The following properties are set on the jcr:content node:
* <dl>
* <dt>jcr:mimeType</dt>
* <dd>media type</dd>
@@ -156,45 +143,35 @@ class JcrUtils
* <dd>binary content</dd>
* </dl>
* <p>
- * Note that the types of the returned node or the jcr:content child are <em>not</em> guaranteed to match nt:file and nt:resource in
- * case the nodes already existed. The caller can use an explicit {@link Node#isNodeType(String)} check if needed, or simply use a
- * data-first approach and not worry about the node type until a constraint violation is encountered.
+ * Note that the types of the returned node or the jcr:content child are <em>not</em> guaranteed to match nt:file
+ * and nt:resource in case the nodes already existed. The caller can use an explicit {@link Node#isNodeType(String)}
+ * check if needed, or simply use a data-first approach and not worry about the node type until a constraint
+ * violation is encountered.
* <p>
* The given binary content stream is closed by this method.
*
- * @param parent
- * parent node
- * @param name
- * name of the file
- * @param mime
- * media type of the file
- * @param data
- * binary content of the file
- * @param date
- * date of last modification
+ * @param parent parent node
+ * @param name name of the file
+ * @param mime media type of the file
+ * @param data binary content of the file
+ * @param date date of last modification
* @return the child node
- * @throws RepositoryException
- * if the child node can not be created or updated
+ * @throws RepositoryException if the child node can not be created or updated
*/
- public static Node putFile(final Node parent, final String name, final String mime, final InputStream data, final Calendar date)
- throws RepositoryException
- {
+ public static Node putFile(final Node parent, final String name, final String mime, final InputStream data,
+ final Calendar date) throws RepositoryException {
final Value binary = parent.getSession().getValueFactory().createValue(data);
- try
- {
+ try {
final Node file = getOrAddNode(parent, name, NodeType_NT_FILE);
final Node content = getOrAddNode(file, Node_JCR_CONTENT, NodeType_NT_RESOURCE);
content.setProperty(Property_JCR_MIMETYPE, mime);
final String[] parameters = mime.split(";");
- for (int i = 1; i < parameters.length; i++)
- {
+ for (int i = 1; i < parameters.length; i++) {
final int equals = parameters[i].indexOf('=');
- if (equals != -1)
- {
+ if (equals != -1) {
final String parameter = parameters[i].substring(0, equals);
- if ("charset".equalsIgnoreCase(parameter.trim()))
- {
+ if ("charset".equalsIgnoreCase(parameter.trim())) {
content.setProperty(Property_JCR_ENCODING, parameters[i].substring(equals + 1).trim());
}
}
@@ -203,8 +180,7 @@ class JcrUtils
content.setProperty(Property_JCR_LAST_MODIFIED, date);
content.setProperty(Property_JCR_DATA, binary);
return file;
- } finally
- {
+ } finally {
// JCR 2.0 API:
// binary.dispose();
}
@@ -213,7 +189,6 @@ class JcrUtils
/**
* Private constructor to prevent instantiation of this class.
*/
- private JcrUtils()
- {
+ private JcrUtils() {
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.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/WebdavProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -52,8 +52,7 @@ import org.apache.log4j.Logger;
* Test cases for the WebDAV provider.
*
*/
-public class WebdavProviderTestCase extends AbstractProviderTestConfig
-{
+public class WebdavProviderTestCase extends AbstractProviderTestConfig {
private static final char[] PASSWORD = new char[0];
private static final String USER_ID = "admin";
@@ -73,21 +72,18 @@ public class WebdavProviderTestCase exte
private static boolean DEBUG = Boolean.getBoolean("WebdavProviderTestCase.Debug");
- static File createTempDirectory() throws IOException
- {
+ static File createTempDirectory() throws IOException {
// create base folder
final File base = new File("./target/test").getCanonicalFile();
base.mkdirs();
final File tempFile = File.createTempFile("WebdavProviderTestCase_", ".tmp", base);
- if (!tempFile.delete())
- {
+ if (!tempFile.delete()) {
throw new IOException("Could not delete temp file: " + tempFile.getAbsolutePath());
}
- if (!tempFile.mkdir())
- {
+ if (!tempFile.mkdir()) {
throw new IOException("Could not create temp directory: " + tempFile.getAbsolutePath());
}
@@ -98,52 +94,42 @@ public class WebdavProviderTestCase exte
return tempFile;
}
- private static void dump(final File repoDirectory) throws Exception
- {
+ private static void dump(final File repoDirectory) throws Exception {
final TransientRepository repository = getTransientRepository(repoDirectory);
- try
- {
+ try {
final Session session = getSession(repository);
message("Root node dump:");
dump(session.getRootNode());
session.logout();
- } finally
- {
+ } finally {
repository.shutdown();
}
}
/** Recursively outputs the contents of the given node. */
- private static void dump(final Node node) throws RepositoryException
- {
+ private static void dump(final Node node) throws RepositoryException {
// First output the node path
message(node.getPath());
// Skip the virtual (and large!) jcr:system subtree
- if (node.getName().equals("jcr:system"))
- {
+ if (node.getName().equals("jcr:system")) {
return;
}
- if (node.getName().equals("jcr:content"))
- {
+ if (node.getName().equals("jcr:content")) {
return;
}
// Then output the properties
final PropertyIterator properties = node.getProperties();
- while (properties.hasNext())
- {
+ while (properties.hasNext()) {
final Property property = properties.nextProperty();
- if (property.getDefinition().isMultiple())
- {
+ if (property.getDefinition().isMultiple()) {
// A multi-valued property, print all values
final Value[] values = property.getValues();
- for (final Value value : values)
- {
+ for (final Value value : values) {
message(property.getPath() + " = " + value.getString());
}
- } else
- {
+ } else {
// A single-valued property
message(property.getPath() + " = " + property.getString());
}
@@ -151,63 +137,50 @@ public class WebdavProviderTestCase exte
// Finally output all the child nodes recursively
final NodeIterator nodes = node.getNodes();
- while (nodes.hasNext())
- {
+ while (nodes.hasNext()) {
dump(nodes.nextNode());
}
}
- private static Session getSession(final TransientRepository repository) throws RepositoryException
- {
+ private static Session getSession(final TransientRepository repository) throws RepositoryException {
return repository.login(new SimpleCredentials(USER_ID, PASSWORD));
}
- private static String getSystemTestUriOverride()
- {
+ private static String getSystemTestUriOverride() {
return System.getProperty(TEST_URI);
}
- private static TransientRepository getTransientRepository(final File repoDirectory) throws IOException
- {
+ private static TransientRepository getTransientRepository(final File repoDirectory) throws IOException {
// Jackrabbit 1.6:
// TransientRepository repository = new TransientRepository(repoDirectory);
// Jackrabbit 1.5.2:
return new TransientRepository(new File(repoDirectory, "repository.xml").toString(), repoDirectory.toString());
}
- private static void importFiles(final File repoDirectory, final File sourceDir) throws Exception
- {
+ private static void importFiles(final File repoDirectory, final File sourceDir) throws Exception {
final TransientRepository repository = getTransientRepository(repoDirectory);
- try
- {
+ try {
final Session session = getSession(repository);
importFiles(session.getRootNode(), sourceDir);
session.save();
session.logout();
- } finally
- {
+ } finally {
repository.shutdown();
}
}
- private static void importFiles(final Node parent, final File sourceDir) throws RepositoryException, IOException
- {
+ private static void importFiles(final Node parent, final File sourceDir) throws RepositoryException, IOException {
final File[] files = sourceDir.listFiles();
- for (final File file : files)
- {
- if (file.isFile())
- {
+ for (final File file : files) {
+ if (file.isFile()) {
final InputStream data = new FileInputStream(file);
- try
- {
+ try {
message("Importing file " + file);
JcrUtils.putFile(parent, file.getName(), "application/octet-stream", data);
- } finally
- {
+ } finally {
data.close();
}
- } else if (file.isDirectory())
- {
+ } else if (file.isDirectory()) {
message("Importing folder " + file);
final Node folder = JcrUtils.getOrAddFolder(parent, file.getName());
importFiles(folder, file);
@@ -215,18 +188,14 @@ public class WebdavProviderTestCase exte
}
}
- private static void message(final IOException e)
- {
- if (DEBUG)
- {
+ private static void message(final IOException e) {
+ if (DEBUG) {
e.printStackTrace();
}
}
- private static void message(final String string)
- {
- if (DEBUG)
- {
+ private static void message(final String string) {
+ if (DEBUG) {
System.out.println(string);
}
}
@@ -236,8 +205,7 @@ public class WebdavProviderTestCase exte
*
* @throws Exception
*/
- private static void setUpClass() throws Exception
- {
+ private static void setUpClass() throws Exception {
// Create temp dir for repo
RepoDirectory = createTempDirectory();
message("Created temp directory " + RepoDirectory);
@@ -255,39 +223,32 @@ public class WebdavProviderTestCase exte
* @param repoDirectory
* @throws Exception
*/
- private static void startJackrabbit(final File repoDirectory) throws Exception
- {
+ private static void startJackrabbit(final File repoDirectory) throws Exception {
boolean quiet = false;
- if (!DEBUG)
- {
+ if (!DEBUG) {
Logger.getLogger("org.apache.jackrabbit").setLevel(Level.WARN);
Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.ERROR);
Logger.getLogger("org.apache.commons.vfs2").setLevel(Level.WARN);
Logger.getLogger("org.mortbay").setLevel(Level.WARN);
quiet = true;
}
- JrMain = new JackrabbitMain(new String[]
- { "--port", Integer.toString(SocketPort), "--repo", repoDirectory.toString(), quiet ? "--quiet" : "" });
+ JrMain = new JackrabbitMain(new String[] { "--port", Integer.toString(SocketPort), "--repo",
+ repoDirectory.toString(), quiet ? "--quiet" : "" });
JrMain.run();
}
- public static Test suite() throws Exception
- {
- return new ProviderTestSuite(new WebdavProviderTestCase())
- {
+ public static Test suite() throws Exception {
+ return new ProviderTestSuite(new WebdavProviderTestCase()) {
@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();
}
@@ -295,48 +256,37 @@ public class WebdavProviderTestCase exte
}
/**
- * Tears down resources for this test case.
- * <ol>
- * <li>Shuts down the embedded Jackrabbit</li>
- * <li>Extra clean up for org.apache.commons.httpclient.MultiThreadedHttpConnectionManager</li>
- * <li>Remove temporary repository directory.</li>
- * </ol>
- * Stops the embedded Apache WebDAV Server.
+ * Tears down resources for this test case. <ol> <li>Shuts down the embedded Jackrabbit</li> <li>Extra clean up for
+ * org.apache.commons.httpclient.MultiThreadedHttpConnectionManager</li> <li>Remove temporary repository
+ * directory.</li> </ol> Stops the embedded Apache WebDAV Server.
*
- * @throws Exception
- * @throws
+ * @throws Exception @throws
*/
- private static void tearDownClass() throws Exception
- {
+ private static void tearDownClass() throws Exception {
// Main JR shutdown
JrMain.shutdown();
// WARN logged because one thread is still there, so clean up explicitly.
MultiThreadedHttpConnectionManager.shutdownAll();
- if (DEBUG)
- {
+ if (DEBUG) {
message("Skipping cleanup of " + RepoDirectory);
return;
}
// Remove repo dir
- try
- {
+ try {
message("Deleting temp directory " + RepoDirectory);
FileUtils.deleteDirectory(RepoDirectory);
- } catch (final IOException e)
- {
+ } catch (final IOException e) {
message(e);
- if (RepoDirectory.exists())
- {
+ if (RepoDirectory.exists()) {
message("Directory will be deleted on VM exit " + RepoDirectory);
RepoDirectory.deleteOnExit();
}
}
}
- public WebdavProviderTestCase() throws IOException
- {
+ public WebdavProviderTestCase() throws IOException {
SocketPort = FreeSocketPortUtil.findFreeLocalPort();
message("FreeSocketPortUtil.findFreeLocalPort() = " + SocketPort);
// Use %40 for @ in a URL
@@ -348,11 +298,9 @@ public class WebdavProviderTestCase exte
* 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;
}
final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) manager
@@ -363,8 +311,7 @@ public class WebdavProviderTestCase exte
}
@Override
- public boolean isFileSystemRootAccessible()
- {
+ public boolean isFileSystemRootAccessible() {
return false;
}
@@ -372,8 +319,7 @@ public class WebdavProviderTestCase exte
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("webdav", new WebdavFileProvider());
manager.addProvider("tmp", new TemporaryFileProvider());
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.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/WebdavProviderTestSuite.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java Thu Sep 14 19:26:39 2017
@@ -36,33 +36,24 @@ import org.apache.commons.vfs2.test.UrlT
/**
* The suite of tests for a file system.
*/
-public class WebdavProviderTestSuite extends ProviderTestSuite
-{
+public class WebdavProviderTestSuite extends ProviderTestSuite {
/**
* Adds the tests for a file system to this suite.
*/
- public WebdavProviderTestSuite(final ProviderTestConfig providerConfig) throws Exception
- {
+ public WebdavProviderTestSuite(final ProviderTestConfig providerConfig) throws Exception {
this(providerConfig, "", false, false);
}
/**
* Adds the tests for a file system to this suite. Provider has an empty directory.
*/
- public WebdavProviderTestSuite(final ProviderTestConfig providerConfig,
- final boolean addEmptyDir) throws Exception
- {
+ public WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final boolean addEmptyDir)
+ throws Exception {
this(providerConfig, "", false, addEmptyDir);
}
-
-
- protected WebdavProviderTestSuite(final ProviderTestConfig providerConfig,
- final String prefix,
- final boolean nested,
- final boolean addEmptyDir)
- throws Exception
- {
+ protected WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix,
+ final boolean nested, final boolean addEmptyDir) throws Exception {
super(providerConfig, prefix, nested, addEmptyDir);
}
@@ -70,8 +61,7 @@ public class WebdavProviderTestSuite ext
* Adds base tests - excludes the nested test cases.
*/
@Override
- protected void addBaseTests() throws Exception
- {
+ protected void addBaseTests() throws Exception {
addTests(ProviderCacheStrategyTests.class);
addTests(UriTests.class);
addTests(NamingTests.class);
@@ -87,6 +77,6 @@ public class WebdavProviderTestSuite ext
addTests(UrlTests.class);
addTests(UrlStructureTests.class);
// The class loader test requires the classes be uploaded to the webdav repo.
- //addTests(VfsClassLoaderTests.class);
+ // addTests(VfsClassLoaderTests.class);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavVersioningTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavVersioningTests.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/WebdavVersioningTests.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavVersioningTests.java Thu Sep 14 19:26:39 2017
@@ -32,16 +32,14 @@ import org.apache.jackrabbit.webdav.vers
/**
* Test to verify Webdav Versioning support
*/
-public class WebdavVersioningTests extends AbstractProviderTestCase
-{
+public class WebdavVersioningTests extends AbstractProviderTestCase {
/**
*/
- public void testVersioning() throws Exception
- {
+ public void testVersioning() throws Exception {
final FileObject scratchFolder = createScratchFolder();
final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
- final WebdavFileSystemConfigBuilder builder =
- (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
+ final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager()
+ .getFileSystemConfigBuilder("webdav");
builder.setVersioning(opts, true);
final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
@@ -58,10 +56,9 @@ public class WebdavVersioningTests exten
assertTrue(file.isReadable());
assertTrue(file.isWriteable());
Map<?, ?> map = file.getContent().getAttributes();
- final String name = ((URLFileName)file.getName()).getUserName();
+ final String name = ((URLFileName) file.getName()).getUserName();
assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
- if (name != null)
- {
+ if (name != null) {
assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
}
assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
@@ -70,32 +67,28 @@ public class WebdavVersioningTests exten
final String content = "Here is some sample content for the file. Blah Blah Blah.";
final OutputStream os = file.getContent().getOutputStream();
- try
- {
+ try {
os.write(content.getBytes("utf-8"));
- }
- finally
- {
+ } finally {
os.close();
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
- if (name != null)
- {
+ if (name != null) {
assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
}
assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
builder.setVersioning(opts, false);
}
+
/**
*/
- public void testVersioningWithCreator() throws Exception
- {
+ public void testVersioningWithCreator() throws Exception {
final FileObject scratchFolder = createScratchFolder();
final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
- final WebdavFileSystemConfigBuilder builder =
- (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
+ final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager()
+ .getFileSystemConfigBuilder("webdav");
builder.setVersioning(opts, true);
builder.setCreatorName(opts, "testUser");
final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
@@ -113,11 +106,10 @@ public class WebdavVersioningTests exten
assertTrue(file.isReadable());
assertTrue(file.isWriteable());
Map<?, ?> map = file.getContent().getAttributes();
- final String name = ((URLFileName)file.getName()).getUserName();
+ final String name = ((URLFileName) file.getName()).getUserName();
assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
- assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
- if (name != null)
- {
+ assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()), "testUser");
+ if (name != null) {
assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
}
@@ -127,20 +119,16 @@ public class WebdavVersioningTests exten
final String content = "Here is some sample content for the file. Blah Blah Blah.";
final OutputStream os = file.getContent().getOutputStream();
- try
- {
+ try {
os.write(content.getBytes("utf-8"));
- }
- finally
- {
+ } finally {
os.close();
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
- assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
- if (name != null)
- {
+ assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()), "testUser");
+ if (name != null) {
assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
}
@@ -148,11 +136,11 @@ public class WebdavVersioningTests exten
builder.setVersioning(opts, false);
builder.setCreatorName(opts, null);
}
- /**
+
+ /**
* Sets up a scratch folder for the test to use.
*/
- protected FileObject createScratchFolder() throws Exception
- {
+ protected FileObject createScratchFolder() throws Exception {
final FileObject scratchFolder = getWriteFolder();
// Make sure the test folder is empty
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/NestedZipTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/NestedZipTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/NestedZipTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/NestedZipTestCase.java Thu Sep 14 19:26:39 2017
@@ -29,14 +29,11 @@ import junit.framework.Test;
/**
* Tests for the Zip file system, using a zip file nested inside another zip file.
*/
-public class NestedZipTestCase
- extends AbstractProviderTestConfig
-{
+public class NestedZipTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for nested zip files.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new NestedZipTestCase(), true);
}
@@ -44,9 +41,7 @@ public class NestedZipTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("zip", new ZipFileProvider());
manager.addExtensionMap("zip", "zip");
manager.addMimeTypeMap("application/zip", "zip");
@@ -56,8 +51,7 @@ public class NestedZipTestCase
* 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 Zip file
final String zipFilePath = AbstractVfsTestCase.getTestResource("nested.zip").getAbsolutePath();
final String uri = "zip:file:" + zipFilePath + "!/test.zip";
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ZipProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ZipProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ZipProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ZipProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -31,14 +31,11 @@ import junit.framework.Test;
/**
* Tests for the Zip file system.
*/
-public class ZipProviderTestCase
- extends AbstractProviderTestConfig
-{
+public class ZipProviderTestCase extends AbstractProviderTestConfig {
/**
* Creates the test suite for the zip file system.
*/
- public static Test suite() throws Exception
- {
+ public static Test suite() throws Exception {
return new ProviderTestSuite(new ZipProviderTestCase(), true);
}
@@ -46,8 +43,7 @@ public class ZipProviderTestCase
* Prepares the file system manager.
*/
@Override
- public void prepare(final DefaultFileSystemManager manager) throws Exception
- {
+ public void prepare(final DefaultFileSystemManager manager) throws Exception {
manager.addProvider("zip", new ZipFileProvider());
manager.addExtensionMap("zip", "zip");
manager.addMimeTypeMap("application/zip", "zip");
@@ -57,8 +53,7 @@ public class ZipProviderTestCase
* 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 zipFile = AbstractVfsTestCase.getTestResource("test.zip");
final String uri = "zip:file:" + zipFile.getAbsolutePath() + "!/";
return manager.resolveFile(uri);
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java Thu Sep 14 19:26:39 2017
@@ -39,15 +39,11 @@ import org.apache.commons.vfs2.provider.
import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;
/**
- * File system test cases, which verifies the structure and naming
- * functionality.
+ * File system test cases, which verifies the structure and naming functionality.
* <p>
- * Works from a base folder, and assumes a particular structure under
- * that base folder.
+ * Works from a base folder, and assumes a particular structure under that base folder.
*/
-public abstract class AbstractProviderTestCase
- extends AbstractVfsTestCase
-{
+public abstract class AbstractProviderTestCase extends AbstractVfsTestCase {
private FileObject baseFolder;
private FileObject readFolder;
private FileObject writeFolder;
@@ -65,20 +61,15 @@ public abstract class AbstractProviderTe
/**
* Sets the test method.
*/
- public void setMethod(final Method method)
- {
+ public void setMethod(final Method method) {
this.method = method;
}
/**
* Configures this test.
*/
- public void setConfig(final DefaultFileSystemManager manager,
- final ProviderTestConfig providerConfig,
- final FileObject baseFolder,
- final FileObject readFolder,
- final FileObject writeFolder)
- {
+ public void setConfig(final DefaultFileSystemManager manager, final ProviderTestConfig providerConfig,
+ final FileObject baseFolder, final FileObject readFolder, final FileObject writeFolder) {
this.manager = manager;
this.providerConfig = providerConfig;
this.baseFolder = baseFolder;
@@ -89,149 +80,124 @@ public abstract class AbstractProviderTe
/**
* Returns the file system manager used by this test.
*/
- protected DefaultFileSystemManager getManager()
- {
+ protected DefaultFileSystemManager getManager() {
return manager;
}
/**
* creates a new uninitialized file system manager
+ *
* @throws Exception
*/
- protected DefaultFileSystemManager createManager() throws Exception
- {
+ protected DefaultFileSystemManager createManager() throws Exception {
final DefaultFileSystemManager fs = getProviderConfig().getDefaultFileSystemManager();
fs.setFilesCache(getProviderConfig().getFilesCache());
getProviderConfig().prepare(fs);
- if (!fs.hasProvider("file"))
- {
+ if (!fs.hasProvider("file")) {
fs.addProvider("file", new DefaultLocalFileProvider());
}
return fs;
}
/**
- * some provider config do some post-initialization in getBaseTestFolder.
- * This is a hack to allow access to this code for {@code createManager}
+ * some provider config do some post-initialization in getBaseTestFolder. This is a hack to allow access to this
+ * code for {@code createManager}
*/
- public FileObject getBaseTestFolder(final FileSystemManager fs) throws Exception
- {
+ public FileObject getBaseTestFolder(final FileSystemManager fs) throws Exception {
return providerConfig.getBaseTestFolder(fs);
}
- protected FileSystem getFileSystem()
- {
+ protected FileSystem getFileSystem() {
return getReadFolder().getFileSystem();
}
/**
- * Returns the base test folder. This is the parent of both the read
- * test and write test folders.
+ * Returns the base test folder. This is the parent of both the read test and write test folders.
*/
- public FileObject getBaseFolder()
- {
+ public FileObject getBaseFolder() {
return baseFolder;
}
/**
* get the provider configuration
*/
- public ProviderTestConfig getProviderConfig()
- {
+ public ProviderTestConfig getProviderConfig() {
return providerConfig;
}
/**
* Returns the read test folder.
*/
- protected FileObject getReadFolder()
- {
+ protected FileObject getReadFolder() {
return readFolder;
}
/**
* Returns the write test folder.
*/
- protected FileObject getWriteFolder()
- {
+ protected FileObject getWriteFolder() {
return writeFolder;
}
/**
* Sets the write test folder.
+ *
* @param folder
*/
- protected void setWriteFolder(final FileObject folder)
- {
+ protected void setWriteFolder(final FileObject folder) {
writeFolder = folder;
}
/**
- * Returns the capabilities required by the tests of this test case. The
- * tests are not run if the provider being tested does not support all
- * the required capabilities. Return null or an empty array to always
- * run the tests.
+ * Returns the capabilities required by the tests of this test case. The tests are not run if the provider being
+ * tested does not support all the required capabilities. Return null or an empty array to always run the tests.
* <p>
* This implementation returns null.
*/
- protected Capability[] getRequiredCaps()
- {
+ protected Capability[] getRequiredCaps() {
return null;
}
/**
- * Runs the test. This implementation short-circuits the test if the
- * provider being tested does not have the capabilities required by this
- * test.
+ * Runs the test. This implementation short-circuits the test if the provider being tested does not have the
+ * capabilities required by this test.
* <p>
* TODO - Handle negative caps as well - ie, only run a test if the provider does not have certain caps.<br>
* TODO - Figure out how to remove the test from the TestResult if the test is skipped.
*/
@Override
- protected void runTest() throws Throwable
- {
+ protected void runTest() throws Throwable {
// Check the capabilities
final Capability[] caps = getRequiredCaps();
- if (caps != null)
- {
- for (final Capability cap2 : caps)
- {
+ if (caps != null) {
+ for (final Capability cap2 : caps) {
final Capability cap = cap2;
final FileSystem fs = readFolder.getFileSystem();
- if (!fs.hasCapability(cap))
- {
-// String name = fs.getClass().getName();
-// int index = name.lastIndexOf('.');
-// String fsName = (index > 0) ? name.substring(index + 1) : name;
-// System.out.println("skipping " + getName() + " because " +
-// fsName + " does not have capability " + cap);
+ if (!fs.hasCapability(cap)) {
+ // String name = fs.getClass().getName();
+ // int index = name.lastIndexOf('.');
+ // String fsName = (index > 0) ? name.substring(index + 1) : name;
+ // System.out.println("skipping " + getName() + " because " +
+ // fsName + " does not have capability " + cap);
return;
}
}
}
// Provider has all the capabilities - execute the test
- if (method != null)
- {
- try
- {
+ if (method != null) {
+ try {
method.invoke(this, (Object[]) null);
- }
- catch (final InvocationTargetException e)
- {
+ } catch (final InvocationTargetException e) {
throw e.getTargetException();
}
- }
- else
- {
+ } else {
super.runTest();
}
- if (((AbstractFileSystem) readFolder.getFileSystem()).isOpen())
- {
+ if (((AbstractFileSystem) readFolder.getFileSystem()).isOpen()) {
String name = "unknown";
- if (method != null)
- {
+ if (method != null) {
name = method.getName();
}
@@ -240,15 +206,11 @@ public abstract class AbstractProviderTe
}
/**
- * Asserts that the content of a file is the same as expected. Checks the
- * length reported by getContentLength() is correct, then reads the content
- * as a byte stream and compares the result with the expected content.
- * Assumes files are encoded using UTF-8.
- */
- protected void assertSameURLContent(final String expected,
- final URLConnection connection)
- throws Exception
- {
+ * Asserts that the content of a file is the same as expected. Checks the length reported by getContentLength() is
+ * correct, then reads the content as a byte stream and compares the result with the expected content. Assumes files
+ * are encoded using UTF-8.
+ */
+ protected void assertSameURLContent(final String expected, final URLConnection connection) throws Exception {
// Get file content as a binary stream
final byte[] expectedBin = expected.getBytes("utf-8");
@@ -258,19 +220,15 @@ public abstract class AbstractProviderTe
// Read content into byte array
final InputStream instr = connection.getInputStream();
final ByteArrayOutputStream outstr;
- try
- {
+ try {
outstr = new ByteArrayOutputStream();
final byte[] buffer = new byte[256];
int nread = 0;
- while (nread >= 0)
- {
+ while (nread >= 0) {
outstr.write(buffer, 0, nread);
nread = instr.read(buffer);
}
- }
- finally
- {
+ } finally {
instr.close();
}
@@ -279,15 +237,11 @@ public abstract class AbstractProviderTe
}
/**
- * Asserts that the content of a file is the same as expected. Checks the
- * length reported by getSize() is correct, then reads the content as
- * a byte stream and compares the result with the expected content.
- * Assumes files are encoded using UTF-8.
- */
- protected void assertSameContent(final String expected,
- final FileObject file)
- throws Exception
- {
+ * Asserts that the content of a file is the same as expected. Checks the length reported by getSize() is correct,
+ * then reads the content as a byte stream and compares the result with the expected content. Assumes files are
+ * encoded using UTF-8.
+ */
+ protected void assertSameContent(final String expected, final FileObject file) throws Exception {
// Check the file exists, and is a file
assertTrue(file.exists());
assertSame(FileType.FILE, file.getType());
@@ -303,19 +257,15 @@ public abstract class AbstractProviderTe
// Read content into byte array
final InputStream instr = content.getInputStream();
final ByteArrayOutputStream outstr;
- try
- {
+ try {
outstr = new ByteArrayOutputStream(expectedBin.length);
final byte[] buffer = new byte[256];
int nread = 0;
- while (nread >= 0)
- {
+ while (nread >= 0) {
outstr.write(buffer, 0, nread);
nread = instr.read(buffer);
}
- }
- finally
- {
+ } finally {
instr.close();
}
@@ -325,10 +275,10 @@ public abstract class AbstractProviderTe
/**
* Builds the expected structure of the read tests folder.
+ *
* @throws FileSystemException (possibly)
*/
- protected FileInfo buildExpectedStructure() throws FileSystemException
- {
+ protected FileInfo buildExpectedStructure() throws FileSystemException {
// Build the expected structure
final FileInfo base = new FileInfo(getReadFolder().getName().getBaseName(), FileType.FOLDER);
base.addFile("file1.txt", FILE1_CONTENT);
@@ -339,17 +289,16 @@ public abstract class AbstractProviderTe
// as we do not know if the current file provider we need to
// ask it to normalize the name
// todo: move this into the FileInfo class to do it generally?
- /* webdav-bug?: didnt manage to get the "?" correctly through webdavlib
- FileSystemManager fsm = getReadFolder().getFileSystem().getFileSystemManager();
- FileName fn = fsm.resolveName(getReadFolder().getName(), "file%3ftest.txt");
- String baseName = fn.getBaseName();
- base.addFile(baseName, FILE1_CONTENT);
- */
+ /*
+ * webdav-bug?: didnt manage to get the "?" correctly through webdavlib FileSystemManager fsm =
+ * getReadFolder().getFileSystem().getFileSystemManager(); FileName fn =
+ * fsm.resolveName(getReadFolder().getName(), "file%3ftest.txt"); String baseName = fn.getBaseName();
+ * base.addFile(baseName, FILE1_CONTENT);
+ */
base.addFile("file space.txt", FILE1_CONTENT);
base.addFile("empty.txt", "");
- if (addEmptyDir)
- {
+ if (addEmptyDir) {
base.addFolder("emptydir");
}
@@ -381,25 +330,20 @@ public abstract class AbstractProviderTe
return base;
}
- protected void addEmptyDir(final boolean addEmptyDir)
- {
+ protected void addEmptyDir(final boolean addEmptyDir) {
this.addEmptyDir = addEmptyDir;
}
- protected static Test notConfigured(final Class<?> testClass)
- {
+ protected static Test notConfigured(final Class<?> testClass) {
return warning(testClass + " is not configured for tests, skipping");
}
- private static Test warning(final String message)
- {
- return new TestCase("warning")
- {
+ private static Test warning(final String message) {
+ return new TestCase("warning") {
@Override
- protected void runTest()
- {
- System.out.println(message);
- }
- };
- }
+ protected void runTest() {
+ System.out.println(message);
+ }
+ };
+ }
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestConfig.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestConfig.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestConfig.java Thu Sep 14 19:26:39 2017
@@ -23,9 +23,7 @@ import org.apache.commons.vfs2.impl.Defa
/**
* A partial {@link org.apache.commons.vfs2.test.ProviderTestConfig} implementation.
*/
-public abstract class AbstractProviderTestConfig extends AbstractProviderTestCase
- implements ProviderTestConfig
-{
+public abstract class AbstractProviderTestConfig extends AbstractProviderTestCase implements ProviderTestConfig {
private FilesCache cache = null;
/**
@@ -37,19 +35,15 @@ public abstract class AbstractProviderTe
}
/**
- * 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 {
}
@Override
- public FilesCache getFilesCache()
- {
- if (cache == null)
- {
+ public FilesCache getFilesCache() {
+ if (cache == null) {
// cache = new DefaultFilesCache();
cache = new SoftRefFilesCache();
}
@@ -58,8 +52,7 @@ public abstract class AbstractProviderTe
}
@Override
- public boolean isFileSystemRootAccessible()
- {
+ public boolean isFileSystemRootAccessible() {
return true;
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java Thu Sep 14 19:26:39 2017
@@ -43,9 +43,7 @@ import org.apache.commons.vfs2.provider.
/**
* The suite of tests for a file system.
*/
-public abstract class AbstractTestSuite
- extends TestSetup
-{
+public abstract class AbstractTestSuite extends TestSetup {
private final ProviderTestConfig providerConfig;
private final String prefix;
private TestSuite testSuite;
@@ -63,71 +61,56 @@ public abstract class AbstractTestSuite
/**
* Adds the tests for a file system to this suite.
*/
- public AbstractTestSuite(final ProviderTestConfig providerConfig) throws Exception
- {
+ public AbstractTestSuite(final ProviderTestConfig providerConfig) throws Exception {
this(providerConfig, "", false, false);
}
- protected AbstractTestSuite(final ProviderTestConfig providerConfig,
- final String prefix,
- final boolean nested) throws Exception
- {
+ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested)
+ throws Exception {
this(providerConfig, prefix, nested, false);
}
-
- protected AbstractTestSuite(final ProviderTestConfig providerConfig,
- final String prefix,
- final boolean nested,
- final boolean addEmptyDir)
- throws Exception
- {
+ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested,
+ final boolean addEmptyDir) throws Exception {
super(new TestSuite());
testSuite = (TestSuite) fTest;
this.providerConfig = providerConfig;
this.prefix = prefix;
this.addEmptyDir = addEmptyDir;
addBaseTests();
- if (!nested)
- {
+ if (!nested) {
// Add nested tests
// TODO - move nested jar and zip tests here
// TODO - enable this again
- //testSuite.addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true ));
+ // testSuite.addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true
+ // ));
}
}
/**
* Adds base tests - excludes the nested test cases.
*/
- protected void addBaseTests() throws Exception
- {
+ protected void addBaseTests() throws Exception {
}
/**
- * Adds the tests from a class to this suite. The supplied class must be
- * a subclass of {@link AbstractProviderTestCase} and have a public a
- * no-args constructor. This method creates an instance of the supplied
- * class for each public 'testNnnn' method provided by the class.
+ * Adds the tests from a class to this suite. The supplied class must be a subclass of
+ * {@link AbstractProviderTestCase} and have a public a no-args constructor. This method creates an instance of the
+ * supplied class for each public 'testNnnn' method provided by the class.
*/
- public void addTests(final Class<?> testClass) throws Exception
- {
+ public void addTests(final Class<?> testClass) throws Exception {
// Verify the class
- if (!AbstractProviderTestCase.class.isAssignableFrom(testClass))
- {
- throw new Exception("Test class " + testClass.getName() + " is not assignable to " + AbstractProviderTestCase.class.getName());
+ if (!AbstractProviderTestCase.class.isAssignableFrom(testClass)) {
+ throw new Exception("Test class " + testClass.getName() + " is not assignable to "
+ + AbstractProviderTestCase.class.getName());
}
// Locate the test methods
final Method[] methods = testClass.getMethods();
- for (final Method method2 : methods)
- {
+ for (final Method method2 : methods) {
final Method method = method2;
- if (!method.getName().startsWith("test")
- || Modifier.isStatic(method.getModifiers())
- || method.getReturnType() != Void.TYPE
- || method.getParameterTypes().length != 0)
- {
+ if (!method.getName().startsWith("test") || Modifier.isStatic(method.getModifiers())
+ || method.getReturnType() != Void.TYPE || method.getParameterTypes().length != 0) {
continue;
}
@@ -155,8 +138,7 @@ public abstract class AbstractTestSuite
}
@Override
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
startThreadSnapshot = createThreadSnapshot();
// Locate the temp directory, and clean it up
@@ -174,8 +156,7 @@ public abstract class AbstractTestSuite
providerConfig.prepare(manager);
- if (!manager.hasProvider("file"))
- {
+ if (!manager.hasProvider("file")) {
manager.addProvider("file", new DefaultLocalFileProvider());
}
@@ -192,11 +173,9 @@ public abstract class AbstractTestSuite
// Configure the tests
final Enumeration<Test> tests = testSuite.tests();
- while (tests.hasMoreElements())
- {
+ while (tests.hasMoreElements()) {
final Test test = tests.nextElement();
- if (test instanceof AbstractProviderTestCase)
- {
+ if (test instanceof AbstractProviderTestCase) {
final AbstractProviderTestCase providerTestCase = (AbstractProviderTestCase) test;
providerTestCase.setConfig(manager, providerConfig, baseFolder, readFolder, writeFolder);
}
@@ -204,8 +183,7 @@ public abstract class AbstractTestSuite
}
@Override
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
readFolder.close();
writeFolder.close();
baseFolder.close();
@@ -232,25 +210,16 @@ public abstract class AbstractTestSuite
checkTempDir("Temp dir not empty after test");
}
- private void validateThreadSnapshot()
- {
+ private void validateThreadSnapshot() {
endThreadSnapshot = createThreadSnapshot();
final Thread[] diffThreadSnapshot = diffThreadSnapshot(startThreadSnapshot, endThreadSnapshot);
- if (diffThreadSnapshot.length > 0)
- {
+ if (diffThreadSnapshot.length > 0) {
final String message = dumpThreadSnapshot(diffThreadSnapshot);
/*
- if (providerConfig.checkCleanThreadState())
- {
- // close the manager to do a "not thread safe" release of all resources
- // and allow the vm to shutdown
- manager.close();
- fail(message);
- }
- else
- {
- */
+ * if (providerConfig.checkCleanThreadState()) { // close the manager to do a "not thread safe" release of
+ * all resources // and allow the vm to shutdown manager.close(); fail(message); } else {
+ */
System.out.println(message);
// }
}
@@ -260,74 +229,56 @@ public abstract class AbstractTestSuite
/**
* Asserts that the temp dir is empty or gone.
*/
- private void checkTempDir(final String assertMsg)
- {
- if (tempDir.exists())
- {
- assertTrue(assertMsg + " (" + tempDir.getAbsolutePath() + ")", tempDir.isDirectory() && tempDir.list().length == 0);
+ private void checkTempDir(final String assertMsg) {
+ if (tempDir.exists()) {
+ assertTrue(assertMsg + " (" + tempDir.getAbsolutePath() + ")",
+ tempDir.isDirectory() && tempDir.list().length == 0);
}
}
- private String dumpThreadSnapshot(final Thread[] threadSnapshot)
- {
+ private String dumpThreadSnapshot(final Thread[] threadSnapshot) {
final StringBuffer sb = new StringBuffer(256);
sb.append("created threads still running:\n");
Field threadTargetField = null;
- try
- {
+ try {
threadTargetField = Thread.class.getDeclaredField("target");
threadTargetField.setAccessible(true);
- }
- catch (final NoSuchFieldException e)
- {
+ } catch (final NoSuchFieldException e) {
// ignored
}
- for (int iter = 0; iter < threadSnapshot.length; iter++)
- {
+ for (int iter = 0; iter < threadSnapshot.length; iter++) {
final Thread thread = threadSnapshot[iter];
- if (thread == null || !thread.isAlive())
- {
+ if (thread == null || !thread.isAlive()) {
continue;
}
sb.append("#");
sb.append(iter + 1);
sb.append(": ");
- sb.append(thread.getThreadGroup() != null ?
- thread.getThreadGroup().getName() : "(null)");
+ sb.append(thread.getThreadGroup() != null ? thread.getThreadGroup().getName() : "(null)");
sb.append("\t");
sb.append(thread.getName());
sb.append("\t");
sb.append(thread.getState());
sb.append("\t");
- if (thread.isDaemon())
- {
+ if (thread.isDaemon()) {
sb.append("daemon");
- }
- else
- {
+ } else {
sb.append("not_a_daemon");
}
- if (threadTargetField != null)
- {
+ if (threadTargetField != null) {
sb.append("\t");
- try
- {
+ try {
final Object threadTarget = threadTargetField.get(thread);
- if (threadTarget != null)
- {
+ if (threadTarget != null) {
sb.append(threadTarget.getClass());
- }
- else
- {
+ } else {
sb.append("null");
}
- }
- catch (final IllegalAccessException e)
- {
+ } catch (final IllegalAccessException e) {
sb.append("unknown class");
}
}
@@ -338,16 +289,12 @@ public abstract class AbstractTestSuite
return sb.toString();
}
- private Thread[] diffThreadSnapshot(final Thread[] startThreadSnapshot, final Thread[] endThreadSnapshot)
- {
+ private Thread[] diffThreadSnapshot(final Thread[] startThreadSnapshot, final Thread[] endThreadSnapshot) {
final List<Thread> diff = new ArrayList<>(10);
- nextEnd: for (int iterEnd = 0; iterEnd < endThreadSnapshot.length; iterEnd++)
- {
- for (int iterStart = 0; iterStart < startThreadSnapshot.length; iterStart++)
- {
- if (startThreadSnapshot[iterStart] == endThreadSnapshot[iterEnd])
- {
+ nextEnd: for (int iterEnd = 0; iterEnd < endThreadSnapshot.length; iterEnd++) {
+ for (int iterStart = 0; iterStart < startThreadSnapshot.length; iterStart++) {
+ if (startThreadSnapshot[iterStart] == endThreadSnapshot[iterEnd]) {
continue nextEnd;
}
}
@@ -360,11 +307,9 @@ public abstract class AbstractTestSuite
return ret;
}
- private Thread[] createThreadSnapshot()
- {
+ private Thread[] createThreadSnapshot() {
ThreadGroup tg = Thread.currentThread().getThreadGroup();
- while (tg.getParent() != null)
- {
+ while (tg.getParent() != null) {
tg = tg.getParent();
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/CacheTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/CacheTestSuite.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/CacheTestSuite.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/CacheTestSuite.java Thu Sep 14 19:26:39 2017
@@ -16,23 +16,16 @@
*/
package org.apache.commons.vfs2.test;
-
/**
* The suite of tests for a file cache.
*/
-public class CacheTestSuite
- extends AbstractTestSuite
-{
- public CacheTestSuite(final ProviderTestConfig providerConfig) throws Exception
- {
+public class CacheTestSuite extends AbstractTestSuite {
+ public CacheTestSuite(final ProviderTestConfig providerConfig) throws Exception {
this(providerConfig, "", false);
}
- protected CacheTestSuite(final ProviderTestConfig providerConfig,
- final String prefix,
- final boolean nested)
- throws Exception
- {
+ protected CacheTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested)
+ throws Exception {
super(providerConfig, prefix, nested);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/ContentTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/ContentTests.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/ContentTests.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/ContentTests.java Thu Sep 14 19:26:39 2017
@@ -28,14 +28,11 @@ import org.apache.commons.vfs2.NameScope
/**
* Test cases for reading file content.
*/
-public class ContentTests
- extends AbstractProviderTestCase
-{
+public class ContentTests extends AbstractProviderTestCase {
/**
* Asserts that every expected file exists, and has the expected content.
*/
- public void testAllContent() throws Exception
- {
+ public void testAllContent() throws Exception {
final FileInfo expectedFileInfo = buildExpectedStructure();
final FileObject actualFolder = getReadFolder();
@@ -45,20 +42,14 @@ public class ContentTests
/**
* Asserts every file in a folder exists and has the expected content.
*/
- private void assertSameContent(final FileInfo expected,
- final FileObject folder) throws Exception
- {
- for (final FileInfo fileInfo : expected.children.values())
- {
+ private void assertSameContent(final FileInfo expected, final FileObject folder) throws Exception {
+ for (final FileInfo fileInfo : expected.children.values()) {
final FileObject child = folder.resolveFile(fileInfo.baseName, NameScope.CHILD);
assertTrue(child.getName().toString(), child.exists());
- if (fileInfo.type == FileType.FILE)
- {
+ if (fileInfo.type == FileType.FILE) {
assertSameContent(fileInfo.content, child);
- }
- else
- {
+ } else {
assertSameContent(fileInfo, child);
}
}
@@ -67,8 +58,7 @@ public class ContentTests
/**
* Tests existence determination.
*/
- public void testExists() throws Exception
- {
+ public void testExists() throws Exception {
// Test a file
FileObject file = getReadFolder().resolveFile("file1.txt");
assertTrue("file exists", file.exists());
@@ -82,14 +72,12 @@ public class ContentTests
// Test an unknown file
file = getReadFolder().resolveFile("unknown-child");
assertTrue("unknown file does not exist", !file.exists());
- assertTrue("unknown file does not exist",
- file.getType() == FileType.IMAGINARY);
+ assertTrue("unknown file does not exist", file.getType() == FileType.IMAGINARY);
// Test an unknown file in an unknown folder
file = getReadFolder().resolveFile("unknown-folder/unknown-child");
assertTrue("unknown file does not exist", !file.exists());
- assertTrue("unknown file does not exist",
- file.getType() == FileType.IMAGINARY);
+ assertTrue("unknown file does not exist", file.getType() == FileType.IMAGINARY);
}
/**
@@ -102,10 +90,8 @@ public class ContentTests
/**
* Tests root of file system exists.
*/
- public void testRootURI() throws FileSystemException
- {
- if (!this.getProviderConfig().isFileSystemRootAccessible())
- {
+ public void testRootURI() throws FileSystemException {
+ if (!this.getProviderConfig().isFileSystemRootAccessible()) {
return;
}
final FileSystem fileSystem = getFileSystem();
@@ -116,17 +102,14 @@ public class ContentTests
/**
* Tests root of file system exists.
*/
- public void testRootAPI() throws FileSystemException
- {
- if (!this.getProviderConfig().isFileSystemRootAccessible())
- {
+ public void testRootAPI() throws FileSystemException {
+ if (!this.getProviderConfig().isFileSystemRootAccessible()) {
return;
}
testRoot(getFileSystem().getRoot());
}
- private void testRoot(final FileObject root) throws FileSystemException
- {
+ private void testRoot(final FileObject root) throws FileSystemException {
assertTrue(root.exists());
assertTrue(root.getType() != FileType.IMAGINARY);
}
@@ -134,8 +117,7 @@ public class ContentTests
/**
* Tests parent identity
*/
- public void testParent() throws FileSystemException
- {
+ public void testParent() throws FileSystemException {
// Test when both exist
FileObject folder = getReadFolder().resolveFile("dir1");
FileObject child = folder.resolveFile("file3.txt");
@@ -160,13 +142,10 @@ public class ContentTests
// TODO - refactor out test cases for layered vs originating fs
final FileSystem fileSystem = getFileSystem();
final FileObject root = fileSystem.getRoot();
- if (fileSystem.getParentLayer() == null)
- {
+ if (fileSystem.getParentLayer() == null) {
// No parent layer, so parent should be null
assertNull("root has null parent", root.getParent());
- }
- else
- {
+ } else {
// Parent should be parent of parent layer.
assertSame(fileSystem.getParentLayer().getParent(), root.getParent());
}
@@ -175,19 +154,15 @@ public class ContentTests
/**
* Tests that children cannot be listed for non-folders.
*/
- public void testChildren() throws FileSystemException
- {
+ public void testChildren() throws FileSystemException {
// Check for file
FileObject file = getReadFolder().resolveFile("file1.txt");
assertSame(FileType.FILE, file.getType());
assertTrue(file.isFile());
- try
- {
+ try {
file.getChildren();
fail();
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
assertSameMessage("vfs.provider/list-children-not-folder.error", file, e);
}
@@ -198,13 +173,10 @@ public class ContentTests
// Check for unknown file
file = getReadFolder().resolveFile("unknown-file");
assertTrue(!file.exists());
- try
- {
+ try {
file.getChildren();
fail();
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
assertSameMessage("vfs.provider/list-children-not-folder.error", file, e);
}
@@ -216,8 +188,7 @@ public class ContentTests
/**
* Tests content.
*/
- public void testContent() throws Exception
- {
+ public void testContent() throws Exception {
// Test non-empty file
FileObject file = getReadFolder().resolveFile("file1.txt");
assertSameContent(FILE1_CONTENT, file);
@@ -230,28 +201,21 @@ public class ContentTests
/**
* Tests that unknown files have no content.
*/
- public void testUnknownContent() throws Exception
- {
+ public void testUnknownContent() throws Exception {
// Try getting the content of an unknown file
final FileObject unknownFile = getReadFolder().resolveFile("unknown-file");
final FileContent content = unknownFile.getContent();
- try
- {
+ try {
content.getInputStream();
fail();
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
assertSameMessage("vfs.provider/read-not-file.error", unknownFile, e);
}
- try
- {
+ try {
content.getSize();
fail();
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
assertSameMessage("vfs.provider/get-size-not-file.error", unknownFile, e);
}
}
@@ -259,8 +223,7 @@ public class ContentTests
/**
* Tests concurrent reads on a file.
*/
- public void testReadSingleSequencial() throws Exception
- {
+ public void testReadSingleSequencial() throws Exception {
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertTrue(file.exists());
@@ -271,20 +234,16 @@ public class ContentTests
/**
* Tests concurrent reads on a file.
*/
- public void testReadSingleConcurrent() throws Exception
- {
+ public void testReadSingleConcurrent() throws Exception {
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertTrue(file.exists());
// Start reading from the file
final InputStream instr = file.getContent().getInputStream();
- try
- {
+ try {
// Start reading again
file.getContent().getInputStream().close();
- }
- finally
- {
+ } finally {
instr.close();
}
}
@@ -292,8 +251,7 @@ public class ContentTests
/**
* Tests concurrent reads on different files works.
*/
- public void testReadMultipleConcurrent() throws Exception
- {
+ public void testReadMultipleConcurrent() throws Exception {
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertTrue(file.exists());
final FileObject emptyFile = getReadFolder().resolveFile("empty.txt");
@@ -301,13 +259,10 @@ public class ContentTests
// Start reading from the file
final InputStream instr = file.getContent().getInputStream();
- try
- {
+ try {
// Try to read from other file
assertSameContent("", emptyFile);
- }
- finally
- {
+ } finally {
instr.close();
}
}
@@ -315,8 +270,7 @@ public class ContentTests
/**
* Tests that content and file objects are usable after being closed.
*/
- public void testReuse() throws Exception
- {
+ public void testReuse() throws Exception {
// Get the test file
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertEquals(FileType.FILE, file.getType());
@@ -339,8 +293,7 @@ public class ContentTests
/**
* Tests that input streams are cleaned up on file close.
*/
- public void testInputStreamMultipleCleanup() throws Exception
- {
+ public void testInputStreamMultipleCleanup() throws Exception {
// Get the test file
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertEquals(FileType.FILE, file.getType());
@@ -363,8 +316,7 @@ public class ContentTests
/**
* Tests that input streams are cleaned up on file close.
*/
- public void testInputStreamSingleCleanup() throws Exception
- {
+ public void testInputStreamSingleCleanup() throws Exception {
// Get the test file
final FileObject file = getReadFolder().resolveFile("file1.txt");
assertEquals(FileType.FILE, file.getType());
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileInfo.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileInfo.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileInfo.java Thu Sep 14 19:26:39 2017
@@ -24,38 +24,33 @@ import org.apache.commons.vfs2.FileType;
/**
* Info about a file.
*/
-class FileInfo
-{
+class FileInfo {
String baseName;
FileType type;
String content;
Map<String, FileInfo> children = new HashMap<>();
FileInfo parent;
- public FileInfo(final String name, final FileType type)
- {
+ public FileInfo(final String name, final FileType type) {
baseName = name;
this.type = type;
this.content = null;
}
- public FileInfo(final String name, final FileType type, final String content)
- {
+ public FileInfo(final String name, final FileType type, final String content) {
baseName = name;
this.type = type;
this.content = content;
}
- public FileInfo getParent()
- {
+ public FileInfo getParent() {
return parent;
}
/**
* Adds a child.
*/
- public void addChild(final FileInfo child)
- {
+ public void addChild(final FileInfo child) {
children.put(child.baseName, child);
child.parent = this;
}
@@ -63,8 +58,7 @@ class FileInfo
/**
* Adds a child file.
*/
- public FileInfo addFile(final String baseName, final String content)
- {
+ public FileInfo addFile(final String baseName, final String content) {
final FileInfo child = new FileInfo(baseName, FileType.FILE, content);
addChild(child);
return child;
@@ -73,8 +67,7 @@ class FileInfo
/**
* Adds a child folder.
*/
- public FileInfo addFolder(final String baseName)
- {
+ public FileInfo addFolder(final String baseName) {
final FileInfo child = new FileInfo(baseName, FileType.FOLDER, null);
addChild(child);
return child;
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java Thu Sep 14 19:26:39 2017
@@ -28,14 +28,11 @@ import org.apache.commons.vfs2.VFS;
/**
* Test cases for the VFS factory.
*/
-public class FileSystemManagerFactoryTestCase
- extends AbstractVfsTestCase
-{
+public class FileSystemManagerFactoryTestCase extends AbstractVfsTestCase {
/**
* Sanity test.
*/
- public void testDefaultInstance() throws Exception
- {
+ public void testDefaultInstance() throws Exception {
// Locate the default manager
final FileSystemManager manager = VFS.getManager();
@@ -52,8 +49,7 @@ public class FileSystemManagerFactoryTes
check(manager, file3);
}
- private void check(final FileSystemManager manager, FileObject file) throws FileSystemException
- {
+ private void check(final FileSystemManager manager, FileObject file) throws FileSystemException {
assertNotNull(file);
assertTrue(file.exists());
assertSame(FileType.FILE, file.getType());