This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new 40f1a94 Refactor and add tests to support main side of PR
https://github.com/apache/commons-vfs/pull/82
40f1a94 is described below
commit 40f1a943df650a9c5b21166044d2e00ce674d1ee
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Feb 8 12:41:37 2021 -0500
Refactor and add tests to support main side of PR
https://github.com/apache/commons-vfs/pull/82
Add disabled test for upcoming MTDM feature.
---
.../org/apache/commons/vfs2/AbstractTestSuite.java | 8 +++-
.../org/apache/commons/vfs2/LastModifiedTests.java | 36 ++++++++++-----
.../provider/ftp/FtpMdtmOffLastModifiedTests.java | 51 ++++++++++++++++++++++
.../provider/ftp/FtpMdtmOnLastModifiedTests.java | 50 +++++++++++++++++++++
...stCase.java => FtpProviderMdtmOffTestCase.java} | 5 +--
...estCase.java => FtpProviderMdtmOnTestCase.java} | 7 +--
.../vfs2/provider/ftp/FtpProviderTestCase.java | 22 +++++-----
.../provider/ftp/FtpProviderUserDirTestCase.java | 16 +++----
8 files changed, 158 insertions(+), 37 deletions(-)
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
index ae190e0..5e698df 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
@@ -42,6 +42,10 @@ import junit.framework.TestSuite;
* The suite of tests for a file system.
*/
public abstract class AbstractTestSuite extends TestSetup {
+
+ public static final String WRITE_TESTS_FOLDER = "write-tests";
+ public static final String READ_TESTS_FOLDER = "read-tests";
+
private final ProviderTestConfig providerConfig;
private final String prefix;
private TestSuite testSuite;
@@ -159,8 +163,8 @@ public abstract class AbstractTestSuite extends TestSetup {
// Locate the base folders
baseFolder = providerConfig.getBaseTestFolder(manager);
- readFolder = baseFolder.resolveFile("read-tests");
- writeFolder = baseFolder.resolveFile("write-tests");
+ readFolder = baseFolder.resolveFile(READ_TESTS_FOLDER);
+ writeFolder = baseFolder.resolveFile(WRITE_TESTS_FOLDER);
// Make some assumptions about the read folder
Assert.assertTrue("Folder does not exist: " + readFolder,
readFolder.exists());
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/LastModifiedTests.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/LastModifiedTests.java
index b20f18b..64f8532 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/LastModifiedTests.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/LastModifiedTests.java
@@ -18,6 +18,10 @@ package org.apache.commons.vfs2;
import static org.junit.Assert.assertNotEquals;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
@@ -30,17 +34,27 @@ import org.junit.Test;
*/
public class LastModifiedTests extends AbstractProviderTestCase {
- private static final Duration ONE_DAY = Duration.ofDays(1);
+ protected static final Duration ONE_DAY = Duration.ofDays(1);
- private void assertDelta(final String message, final long expected, final
long actual, final long delta) {
+ protected void assertDeltaMillis(final String message, final long
expected, final long actual, final long delta) {
if (expected == actual) {
return;
}
- if (Math.abs(expected - actual) > Math.max(delta, 1000)) //
getLastModTimeAccuracy() is not accurate
- {
- Assert.fail(String.format("%s expected=%d (%s), actual=%d (%s),
delta=%d", message, Long.valueOf(expected),
- new Date(expected).toString(), Long.valueOf(actual), new
Date(actual).toString(),
- Long.valueOf(delta)));
+ // getLastModTimeAccuracy() is not accurate
+ final long actualDelta = Math.abs(expected - actual);
+ if (actualDelta > Math.max(delta, 1000)) {
+ Assert.fail(String.format("%s expected=%,d (%s), actual=%,d (%s),
expected delta=%,d, actual delta=%,d",
+ message, Long.valueOf(expected), new
Date(expected).toString(), Long.valueOf(actual),
+ new Date(actual).toString(), Long.valueOf(delta),
Long.valueOf(actualDelta)));
+ }
+ }
+
+ protected void assertEqualMillis(final String message, final long
expected, final long actual) {
+ if (expected != actual) {
+ final long delta = Math.abs(expected - actual);
+ Assert
+ .fail(String.format("%s expected=%,d (%s), actual=%,d (%s),
delta=%,d", message, Long.valueOf(expected),
+ new Date(expected).toString(), Long.valueOf(actual), new
Date(actual).toString(), delta));
}
}
@@ -49,7 +63,7 @@ public class LastModifiedTests extends
AbstractProviderTestCase {
*/
@Override
protected Capability[] getRequiredCapabilities() {
- return new Capability[] { Capability.GET_LAST_MODIFIED };
+ return new Capability[] {Capability.GET_LAST_MODIFIED};
}
/**
@@ -106,7 +120,8 @@ public class LastModifiedTests extends
AbstractProviderTestCase {
final long lastModTimeAccuracyMillis = (long)
folder.getFileSystem().getLastModTimeAccuracy();
// folder.refresh(); TODO: does not work with SSH VFS-563
final long lastModifiedTime =
folder.getContent().getLastModifiedTime();
- assertDelta("set/getLastModified on Folder", yesterdayMillis,
lastModifiedTime, lastModTimeAccuracyMillis);
+ assertDeltaMillis("set/getLastModified on Folder",
yesterdayMillis, lastModifiedTime,
+ lastModTimeAccuracyMillis);
}
}
@@ -126,7 +141,8 @@ public class LastModifiedTests extends
AbstractProviderTestCase {
final long lastModTimeAccuracyMillis = (long)
file.getFileSystem().getLastModTimeAccuracy();
// folder.refresh(); TODO: does not work with SSH VFS-563
final long lastModifiedTime =
file.getContent().getLastModifiedTime();
- assertDelta("set/getLastModified on File", yesterdayMillis,
lastModifiedTime, lastModTimeAccuracyMillis);
+ assertDeltaMillis("set/getLastModified on File", yesterdayMillis,
lastModifiedTime,
+ lastModTimeAccuracyMillis);
}
}
}
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOffLastModifiedTests.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOffLastModifiedTests.java
new file mode 100644
index 0000000..393563a
--- /dev/null
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOffLastModifiedTests.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.provider.ftp;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.time.Duration;
+
+import org.apache.commons.vfs2.AbstractTestSuite;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.LastModifiedTests;
+import org.junit.Test;
+
+public class FtpMdtmOffLastModifiedTests extends LastModifiedTests {
+
+ /**
+ * Tests getting the last modified time of a file.
+ */
+ @Test
+ public void testGetLastModifiedFileInexactMatch() throws IOException {
+ final String fileName = "file1.txt";
+
getFileSystem().getFileSystemManager().getFilesCache().clear(getFileSystem());
+ final FileObject readFolder = getReadFolder();
+ final FileObject fileObject = readFolder.resolveFile(fileName);
+ final long lastModifiedTimeMillis =
fileObject.getContent().getLastModifiedTime();
+ // now try to match
+ final long lastModTimeAccuracyMillis = (long)
readFolder.getFileSystem().getLastModTimeAccuracy();
+ final FileTime lastModifiedTime = Files
+ .getLastModifiedTime(Paths.get(getTestDirectory(),
AbstractTestSuite.READ_TESTS_FOLDER, fileName));
+ assertDeltaMillis("getLastModified on File",
lastModifiedTime.toMillis(), lastModifiedTimeMillis,
+ Math.max(lastModTimeAccuracyMillis,
Duration.ofMinutes(1).toMillis()));
+ }
+
+}
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOnLastModifiedTests.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOnLastModifiedTests.java
new file mode 100644
index 0000000..a228379
--- /dev/null
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpMdtmOnLastModifiedTests.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.provider.ftp;
+
+import static org.junit.Assert.assertNotEquals;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+
+import org.apache.commons.vfs2.AbstractTestSuite;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.LastModifiedTests;
+import org.junit.Test;
+
+public class FtpMdtmOnLastModifiedTests extends LastModifiedTests {
+
+ /**
+ * Tests getting the last modified time of a file.
+ */
+ @Test
+ public void testGetLastModifiedFileExactMatch() throws IOException {
+ final String fileName = "file1.txt";
+ final FileObject readFolder = getReadFolder();
+ final FileObject fileObject = readFolder.resolveFile(fileName);
+ final long lastModifiedTimeMillis =
fileObject.getContent().getLastModifiedTime();
+ // now try to match
+ final long lastModTimeAccuracyMillis = (long)
readFolder.getFileSystem().getLastModTimeAccuracy();
+ final FileTime lastModifiedTime = Files
+ .getLastModifiedTime(Paths.get(getTestDirectory(),
AbstractTestSuite.READ_TESTS_FOLDER, fileName));
+ assertEqualMillis("getLastModified on File",
lastModifiedTime.toMillis(), lastModifiedTimeMillis);
+ }
+
+}
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderNoMdtmTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOffTestCase.java
similarity index 92%
rename from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderNoMdtmTestCase.java
rename to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOffTestCase.java
index bf464f0..e61fbd1 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderNoMdtmTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOffTestCase.java
@@ -18,7 +18,6 @@ package org.apache.commons.vfs2.provider.ftp;
import java.io.IOException;
-import org.apache.commons.vfs2.LastModifiedTests;
import org.apache.ftpserver.command.Command;
import org.apache.ftpserver.command.CommandFactory;
import org.apache.ftpserver.command.CommandFactoryFactory;
@@ -32,10 +31,10 @@ import org.apache.ftpserver.impl.LocalizedFtpReply;
import junit.framework.Test;
-public class FtpProviderNoMdtmTestCase extends FtpProviderTestCase {
+public class FtpProviderMdtmOffTestCase extends FtpProviderTestCase {
public static Test suite() throws Exception {
- return suite(new FtpProviderNoMdtmTestCase(), LastModifiedTests.class);
+ return suite(new FtpProviderMdtmOffTestCase(),
FtpMdtmOffLastModifiedTests.class);
}
/**
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOnTestCase.java
similarity index 84%
rename from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmTestCase.java
rename to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOnTestCase.java
index dbdba5f..e768c93 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderMdtmOnTestCase.java
@@ -16,16 +16,17 @@
*/
package org.apache.commons.vfs2.provider.ftp;
-import org.apache.commons.vfs2.LastModifiedTests;
+import org.junit.Ignore;
import junit.framework.Test;
-public class FtpProviderMdtmTestCase extends FtpProviderTestCase {
+@Ignore
+public class FtpProviderMdtmOnTestCase extends FtpProviderTestCase {
/**
* MDTM is supported by default for underlying Apache MINA FTP server.
*/
public static Test suite() throws Exception {
- return suite(new FtpProviderTestCase(), LastModifiedTests.class);
+ return suite(new FtpProviderTestCase(),
FtpMdtmOnLastModifiedTests.class);
}
}
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
index e10fb00..0361006 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
@@ -196,10 +196,12 @@ public class FtpProviderTestCase extends
AbstractProviderTestConfig {
}
/**
- * Gets the setting for UserDirIsRoot. Defaults to false.
+ * Gets the FTP server command factory. Defaults to null for no override.
+ *
+ * @return the FTP server command factory or null.
*/
- protected boolean getUserDirIsRoot() {
- return false;
+ protected CommandFactory getCommandFactory() {
+ return null;
}
/**
@@ -211,19 +213,17 @@ public class FtpProviderTestCase extends
AbstractProviderTestConfig {
}
/**
- * Gets the FTP server command factory. Defaults to null for no override.
- *
- * @return the FTP server command factory or null.
+ * Gets the root of the local FTP Server file system.
*/
- protected CommandFactory getCommandFactory() {
- return null;
+ protected String getFtpRootDir() {
+ return getTestDirectory();
}
/**
- * Gets the root of the local FTP Server file system.
+ * Gets the setting for UserDirIsRoot. Defaults to false.
*/
- protected String getFtpRootDir() {
- return getTestDirectory();
+ protected boolean getUserDirIsRoot() {
+ return false;
}
/**
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderUserDirTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderUserDirTestCase.java
index a170751..adc0121 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderUserDirTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderUserDirTestCase.java
@@ -40,14 +40,6 @@ public class FtpProviderUserDirTestCase extends
FtpProviderTestCase {
}
/**
- * Prepares the file system manager.
- */
- @Override
- protected boolean getUserDirIsRoot() {
- return true;
- }
-
- /**
* Gets option file system factory for local FTP server.
*/
@Override
@@ -80,4 +72,12 @@ public class FtpProviderUserDirTestCase extends
FtpProviderTestCase {
return new File(getTestDirectory(), "homeDirIsRoot").getPath();
}
+ /**
+ * Prepares the file system manager.
+ */
+ @Override
+ protected boolean getUserDirIsRoot() {
+ return true;
+ }
+
}