Skip to content

Commit

Permalink
VFS-783: Proper http scheme setting on webdav/webdav2 with unit tests (
Browse files Browse the repository at this point in the history
…#143)

* VFS-783 - Based on WEBDAV4 vs WEBDAV4S set backend http scheme accordingly

* VFS-783 - refactor code to use internal URI scheme

* VFS-783: adding unit test

* VFS-783: fixing unit test to verify with #toUrlString(name)

Co-authored-by: Satish Bhor <[email protected]>
  • Loading branch information
woonsan and satish-csi authored Dec 10, 2020
1 parent 0b96da5 commit 0a7ae04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -486,12 +485,6 @@ protected FileContentInfoFactory getFileContentInfoFactory() {
return new Webdav4FileContentInfoFactory();
}

// Just for the unit test in the same package (package-private) to access this during validation.
@Override
protected URI getInternalURI() throws FileSystemException {
return super.getInternalURI();
}

DavPropertySet getProperties(final GenericURLFileName name) throws FileSystemException {
return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false);
}
Expand Down Expand Up @@ -603,12 +596,18 @@ private void setupRequest(final HttpUriRequest request) {
request.addHeader("Expires", "0");
}

private String toUrlString(final GenericURLFileName name) {
/**
* Converts the given URLFileName to an encoded URL String to internally use in real DAV operations.
*
* @param name The FileName.
* @return The encoded URL String.
*/
String toUrlString(final GenericURLFileName name) {
return toUrlString(name, true);
}

/**
* Converts the given URLFileName to an encoded URL String.
* Converts the given URLFileName to an encoded URL String to internally use in real DAV operations.
*
* @param name The FileName.
* @param includeUserInfo true if user information should be included.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.net.URI;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.provider.GenericURLFileName;
import org.junit.Test;

public class Webdav4FileObjectTest {
Expand All @@ -38,26 +37,26 @@ public class Webdav4FileObjectTest {
@Test
public void testWebdav4FileObjectURLs() throws FileSystemException {
final FileSystemManager fsm = VFS.getManager();
try (final FileObject file = fsm.resolveFile(WEBDAV4_URL)) {

try (final FileObject file = fsm.resolveFile(WEBDAV4_URL)) {
assertEquals(WEBDAV4_URL, file.getURL().toString());
assertTrue(file instanceof Webdav4FileObject);

final Webdav4FileObject webdav4File = (Webdav4FileObject) file;
assertEquals(URI.create(INTERNAL_WEBDAV4_URL), webdav4File.getInternalURI());
assertEquals(INTERNAL_WEBDAV4_URL, webdav4File.toUrlString((GenericURLFileName) webdav4File.getName()));
}
}

@Test
public void testWebdav4sFileObjectURLs() throws FileSystemException {
final FileSystemManager fsm = VFS.getManager();
try (final FileObject file = fsm.resolveFile(WEBDAV4S_URL)) {

try (final FileObject file = fsm.resolveFile(WEBDAV4S_URL)) {
assertEquals(WEBDAV4S_URL, file.getURL().toString());
assertTrue(file instanceof Webdav4FileObject);

final Webdav4FileObject webdav4File = (Webdav4FileObject) file;
assertEquals(URI.create(INTERNAL_WEBDAV4S_URL), webdav4File.getInternalURI());
assertEquals(INTERNAL_WEBDAV4S_URL, webdav4File.toUrlString((GenericURLFileName) webdav4File.getName()));
}
}
}

0 comments on commit 0a7ae04

Please sign in to comment.