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 b8889cbf Feature/vfs 848 webdav config option (#425) b8889cbf is described below commit b8889cbfb1a0a71c88656b657a76af296c747014 Author: beise <t.be...@web.de> AuthorDate: Sat Sep 23 15:25:55 2023 +0200 Feature/vfs 848 webdav config option (#425) * VFS-848: Config option to append trailing slash in webdav URI ... when the request is a directory operation. * VFS-848: Enhance testcases with filenames without extension * VFS-848: Remove preceding "question mark" if the queryString is empty. * VFS-848: Enhance testcases with a queryString in url. * VFS-848: Add @since Tag and fix some javadoc. --------- Co-authored-by: Thorsten Beise <thorsten.be...@lbbw-am.de> --- .../vfs2/provider/webdav4/Webdav4FileName.java | 110 ++++++++ .../vfs2/provider/webdav4/Webdav4FileObject.java | 5 +- .../webdav4/Webdav4FileSystemConfigBuilder.java | 37 +++ .../vfs2/provider/webdav4/Webdav4FileNameTest.java | 285 +++++++++++++++++++++ 4 files changed, 435 insertions(+), 2 deletions(-) diff --git a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileName.java b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileName.java new file mode 100644 index 00000000..95848ed3 --- /dev/null +++ b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileName.java @@ -0,0 +1,110 @@ +/* + * 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.webdav4; + +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.provider.GenericURLFileName; +import org.apache.commons.vfs2.util.URIUtils; + +/** + * Webdav4 file name that represents a URL. + * + * @since 2.10.0 + */ +public class Webdav4FileName extends GenericURLFileName { + private static final int BUFFER_SIZE = 250; + + private boolean appendTrailingSlash; + + /** + * Constructs a new instance. + * + * @param scheme Host scheme. + * @param hostName Host name or IP address. + * @param port Host port. + * @param defaultPort Default host port. + * @param userName user name. + * @param password user password. + * @param path Path on the host. + * @param type File type on the host. + * @param queryString Query string for the path. + */ + public Webdav4FileName(final String scheme, final String hostName, final int port, final int defaultPort, + final String userName, final String password, final String path, final FileType type, + final String queryString) { + this(scheme, hostName, port, defaultPort, userName, password, path, type, queryString, false); + } + + /** + * Constructs a new instance. + * + * @param scheme Host scheme. + * @param hostName Host name or IP address. + * @param port Host port. + * @param defaultPort Default host port. + * @param userName user name. + * @param password user password. + * @param path Path on the host. + * @param type File type on the host. + * @param queryString Query string for the path. + * @param appendTrailingSlash Append trailing slash to path. + */ + public Webdav4FileName(final String scheme, final String hostName, final int port, final int defaultPort, + final String userName, final String password, final String path, final FileType type, + final String queryString, boolean appendTrailingSlash) { + super(scheme, hostName, port, defaultPort, userName, password, path, type, queryString); + this.appendTrailingSlash = appendTrailingSlash; + } + + /** + * Gets the path encoded suitable for url like file system e.g. (http, webdav). + * Reappend the trailing slash ( / ) if this FileName is a directory and not ROOT + * because many WEBDav-Servers require the trailing slash if the request access a directory + * + * @param charset the charset used for the path encoding + * @return The encoded path. + * @throws FileSystemException If some other error occurs. + */ + @Override + public String getPathQueryEncoded(final String charset) throws FileSystemException { + String pathDecoded = getPathDecoded(); + + if (appendTrailingSlash && getType() == FileType.FOLDER && getPath().length() > 1) { + pathDecoded += FileName.SEPARATOR; + } + + if (getQueryString() == null || getQueryString().isEmpty()) { + if (charset != null) { + return URIUtils.encodePath(pathDecoded, charset); + } + return URIUtils.encodePath(pathDecoded); + } + + final StringBuilder sb = new StringBuilder(BUFFER_SIZE); + if (charset != null) { + sb.append(URIUtils.encodePath(pathDecoded, charset)); + } else { + sb.append(URIUtils.encodePath(pathDecoded)); + } + sb.append("?"); + sb.append(getQueryString()); + return sb.toString(); + } + +} diff --git a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java index d2224a48..e3cf84c4 100644 --- a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java +++ b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java @@ -652,8 +652,9 @@ public class Webdav4FileObject extends Http4FileObject<Webdav4FileSystem> { password = name.getPassword(); } try { - final GenericURLFileName newFile = new GenericURLFileName(getInternalURI().getScheme(), name.getHostName(), name.getPort(), name.getDefaultPort(), - user, password, name.getPath(), name.getType(), name.getQueryString()); + final GenericURLFileName newFile = new Webdav4FileName(getInternalURI().getScheme(), name.getHostName(), name.getPort(), name.getDefaultPort(), + user, password, name.getPath(), name.getType(), name.getQueryString(), + builder.getAppendTrailingSlash(getFileSystem().getFileSystemOptions())); return newFile.getURIEncoded(this.getUrlCharset()); } catch (final Exception e) { return name.getURI(); diff --git a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileSystemConfigBuilder.java b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileSystemConfigBuilder.java index 05ddf55c..5fc5bc7d 100644 --- a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileSystemConfigBuilder.java +++ b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileSystemConfigBuilder.java @@ -27,8 +27,20 @@ import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder; */ public final class Webdav4FileSystemConfigBuilder extends Http4FileSystemConfigBuilder { + /** + * Defines whether a trailing slash ( / ) should be appended to the path. + * <p> + * This parameter expects a value of type {@link Boolean}. + * </p> + * + * @since 2.10.0 + */ + protected static final String KEY_APPEND_TRAILING_SLASH = "appendTrailingSlash"; + private static final Webdav4FileSystemConfigBuilder BUILDER = new Webdav4FileSystemConfigBuilder(); + private static final boolean DEFAULT_APPEND_TRAILING_SLASH = false; + private static final boolean DEFAULT_FOLLOW_REDIRECT = false; private Webdav4FileSystemConfigBuilder() { @@ -52,6 +64,19 @@ public final class Webdav4FileSystemConfigBuilder extends Http4FileSystemConfigB return Webdav4FileSystem.class; } + /** + * Gets whether a trailing slash ( / ) should be appended to the path. + * + * @param opts The FileSystem options. + * @return {@code true} to follow redirects, {@code false} not to. + * @see #setAppendTrailingSlash + * + * @since 2.10.0 + */ + public boolean getAppendTrailingSlash(final FileSystemOptions opts) { + return getBoolean(opts, KEY_APPEND_TRAILING_SLASH, DEFAULT_APPEND_TRAILING_SLASH); + } + /** * Return the user name to be associated with changes to the file. * @@ -84,6 +109,18 @@ public final class Webdav4FileSystemConfigBuilder extends Http4FileSystemConfigB return getBoolean(opts, "versioning", false); } + /** + * Sets whether a trailing slash ( / ) should be appended to the path. + * + * @param opts The FileSystem options. + * @param appendTrailingSlash {@code true} to append slash, {@code false} not to. + * + * @since 2.10.0 + */ + public void setAppendTrailingSlash(final FileSystemOptions opts, final boolean appendTrailingSlash) { + setParam(opts, KEY_APPEND_TRAILING_SLASH, appendTrailingSlash); + } + /** * The user name to be associated with changes to the file. * diff --git a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileNameTest.java b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileNameTest.java new file mode 100644 index 00000000..d651e892 --- /dev/null +++ b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileNameTest.java @@ -0,0 +1,285 @@ +/* + * 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.webdav4; + +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.VFS; +import org.apache.commons.vfs2.provider.GenericURLFileName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests {@link Webdav4FileName}. + */ +public class Webdav4FileNameTest { + /** + * If the resolved path ends with a '/' + */ + @Test + public void testWebdavUrlWithTrailingSlash() throws FileSystemException { + @SuppressWarnings("resource") + FileSystemOptions fsoptsWithTrailingSlash = new FileSystemOptions(); + Webdav4FileSystemConfigBuilder.getInstance().setAppendTrailingSlash(fsoptsWithTrailingSlash, true); + + final FileSystemManager fileSystemManager = VFS.getManager(); + + final String urlBase = "webdav4://localhost:80"; + final String urlWithFile1 = "webdav4://localhost:80/File.txt"; + final String urlWithFile2 = "webdav4://localhost:80/Path/File.txt"; + final String urlWithFileWithoutExtension1 = "webdav4://localhost:80/File"; + final String urlWithFileWithoutExtension2 = "webdav4://localhost:80/Path/File"; + final String urlWithSubpath = "webdav4://localhost:80/Path/Sub Path/"; + final String urlWithRelativePart1 = "webdav4://localhost:80/Path/."; + final String urlWithRelativePart2 = "webdav4://localhost:80/Path/./"; + final String urlWithRelativePart3 = "webdav4://localhost:80/Path/../Decendant Path/"; + final String urlWithRelativePart4 = "webdav4://localhost:80/Path/Sub Path/.."; + final String urlWithRelativePart5 = "webdav4://localhost:80/Path/Sub Path/../"; + final String urlWithQuery1 = "webdav4://localhost:80/Path/Sub Path/?"; + final String urlWithQuery2 = "webdav4://localhost:80/Path/Sub Path/?foo=bar"; + final String urlWithQuery3 = "webdav4://localhost:80/Path/Sub Path/?foo=1&bar=2"; + final String urlWithQuery4 = "webdav4://localhost:80/Path/Sub Path/?foo=1&bar=2"; + final String urlWithQuery5 = "webdav4://localhost:80/Path/File?foo=1&bar=2"; + + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlBase, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile1, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile2, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension1, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension2, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithSubpath, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart1, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart2, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart3, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Decendant%20Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart4, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart5, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery1, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery2, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path/?foo=bar", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery3, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path/?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery4, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path/?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery5, fsoptsWithTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File?foo=1&bar=2", file.toUrlString(fileName)); + } + } + + /** + * If the resolved path ends without a '/' + */ + @Test + public void testWebdavUrlWithoutTrailingSlash() throws FileSystemException { + @SuppressWarnings("resource") + FileSystemOptions fsoptsWithToutrailingSlashDefault = new FileSystemOptions(); + FileSystemOptions fsoptsWithoutTrailingSlash = new FileSystemOptions(); + Webdav4FileSystemConfigBuilder.getInstance().setAppendTrailingSlash(fsoptsWithoutTrailingSlash, false); + final FileSystemManager fileSystemManager = VFS.getManager(); + + final String urlBase = "webdav4://localhost:80"; + final String urlWithFile1 = "webdav4://localhost:80/File.txt"; + final String urlWithFile2 = "webdav4://localhost:80/Path/File.txt"; + final String urlWithFileWithoutExtension1 = "webdav4://localhost:80/File"; + final String urlWithFileWithoutExtension2 = "webdav4://localhost:80/Path/File"; + final String urlWithSubpath = "webdav4://localhost:80/Path/Sub Path/"; + final String urlWithRelativePart1 = "webdav4://localhost:80/Path/."; + final String urlWithRelativePart2 = "webdav4://localhost:80/Path/./"; + final String urlWithRelativePart3 = "webdav4://localhost:80/Path/../Decendant Path/"; + final String urlWithRelativePart4 = "webdav4://localhost:80/Path/Sub Path/.."; + final String urlWithRelativePart5 = "webdav4://localhost:80/Path/Sub Path/../"; + final String urlWithQuery1 = "webdav4://localhost:80/Path/Sub Path/?"; + final String urlWithQuery2 = "webdav4://localhost:80/Path/Sub Path/?foo=bar"; + final String urlWithQuery3 = "webdav4://localhost:80/Path/Sub Path/?foo=1&bar=2"; + final String urlWithQuery4 = "webdav4://localhost:80/Path/Sub Path/?foo=1&bar=2"; + final String urlWithQuery5 = "webdav4://localhost:80/Path/File?foo=1&bar=2"; + + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlBase, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + //The ROOT is always with trailing slash + assertEquals("http://localhost/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlBase, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + //The ROOT is always with trailing slash + assertEquals("http://localhost/", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile1, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile1, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile2, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFile2, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File.txt", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension1, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension1, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension2, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithFileWithoutExtension2, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithSubpath, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithSubpath, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart1, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart1, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart2, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart2, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart3, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Decendant%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart3, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Decendant%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart4, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart4, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart5, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithRelativePart5, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery1, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery1, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery2, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=bar", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery2, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=bar", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery3, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery3, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery4, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery4, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/Sub%20Path?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery5, fsoptsWithoutTrailingSlash)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File?foo=1&bar=2", file.toUrlString(fileName)); + } + try (final Webdav4FileObject file = (Webdav4FileObject) fileSystemManager.resolveFile(urlWithQuery5, fsoptsWithToutrailingSlashDefault)) { + final GenericURLFileName fileName = (GenericURLFileName) file.getName(); + assertEquals("http://localhost/Path/File?foo=1&bar=2", file.toUrlString(fileName)); + } + } +}