Package de.xima.fc.testhelper
Class WebDavServer
- java.lang.Object
-
- de.xima.fc.testhelper.WebDavServer
-
- All Implemented Interfaces:
AutoCloseable
public final class WebDavServer extends Object implements AutoCloseable
A simple WebDav server against which integration tests can be run.- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()StringdavUri(String... path)booleanexists(String... path)byte[]fileContentAsByteArray(String... path)InputStreamfileContentAsStream(String... path)StringfileContentAsUtf8String(String... path)StringhttpUri(String... paths)List<com.github.sardine.DavResource>lsDir(int depth, String... path)List<com.github.sardine.DavResource>lsDir(String... path)List<com.github.sardine.DavResource>lsDirAll(String... path)voidmkdir(String... path)static WebDavServernewServer()Starts a new WebDAV server that does not required credentials.static WebDavServernewServer(String username, String password, Path tmpDir)Starts a new WebDAV server secured with the given credentials.voidput(String path, byte[] data)voidput(String path, File data)voidput(String path, InputStream data)voidput(String path, String data, Charset charset)voidput(String path, Path data)voidputUtf8String(String path, String data)
-
-
-
Method Detail
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
davUri
public String davUri(String... path)
- Parameters:
path- Path on the WebDAV server.- Returns:
- URL for the given path, with the
dav://protocol.
-
exists
public boolean exists(String... path) throws IOException
- Parameters:
path- Path to check.- Returns:
trueif the given path exists on the server, orfalseotherwise.- Throws:
IOException- When the path could not be checked, usually due to a network error.
-
fileContentAsByteArray
public byte[] fileContentAsByteArray(String... path) throws IOException
- Parameters:
path- Path on the WebDAV server.- Returns:
- The contents of the file at the given path, as a byte array.
- Throws:
IOException- When the file could not be read.
-
fileContentAsStream
public InputStream fileContentAsStream(String... path) throws IOException
- Parameters:
path- Path on the WebDAV server.- Returns:
- The contents of the file at the given path, as an input stream.
- Throws:
IOException- When the file could not be read.
-
fileContentAsUtf8String
public String fileContentAsUtf8String(String... path) throws IOException
- Parameters:
path- Path on the WebDAV server.- Returns:
- The contents of the file at the given path, as a string with the UTF-8 encoding.
- Throws:
IOException- When the file could not be read.
-
httpUri
public String httpUri(String... paths)
- Parameters:
paths- Path on the WebDAV server.- Returns:
- URL for the given path, with the
http://protocol.
-
lsDir
public List<com.github.sardine.DavResource> lsDir(int depth, String... path) throws IOException
- Parameters:
depth- The depth to look at (use 0 for single resource, 1 for directory listing, -1 for infinite recursion)path- Path to process.- Returns:
- The contents of the given directory.
- Throws:
IOException- When the path could not be checked, usually due to a network error.
-
lsDir
public List<com.github.sardine.DavResource> lsDir(String... path) throws IOException
- Parameters:
path- Path to process.- Returns:
- The contents of the given directory, not including subdirectories.
- Throws:
IOException- When the path could not be checked, usually due to a network error.
-
lsDirAll
public List<com.github.sardine.DavResource> lsDirAll(String... path) throws IOException
- Parameters:
path- Path to process.- Returns:
- The contents of the given directory, including subdirectories.
- Throws:
IOException- When the path could not be checked, usually due to a network error.
-
mkdir
public void mkdir(String... path) throws IOException
- Parameters:
path- Path on the WebDAV server.- Throws:
IOException- Creates the given directory. The directory itself must not exist, all parent directories must exist.
-
put
public void put(String path, byte[] data) throws IOException
- Parameters:
path- Path on the WebDAV server.data- The data of the file.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
put
public void put(String path, File data) throws IOException
- Parameters:
path- Path on the WebDAV server.data- A file with the data.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
put
public void put(String path, InputStream data) throws IOException
- Parameters:
path- Path on the WebDAV server.data- The data of the file.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
put
public void put(String path, Path data) throws IOException
- Parameters:
path- Path on the WebDAV server.data- The data of the file.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
put
public void put(String path, String data, Charset charset) throws IOException
- Parameters:
path- Path on the WebDAV server.data- A string with the data.charset- Encoding to use for converting the string to bytes.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
putUtf8String
public void putUtf8String(String path, String data) throws IOException
- Parameters:
path- Path on the WebDAV server.data- The data of the file.- Throws:
IOException- Creates a file at the given path and the given data. All parent directories must exist.
-
newServer
public static WebDavServer newServer() throws Exception
Starts a new WebDAV server that does not required credentials.- Returns:
- A new server that does not require credentials.
- Throws:
Exception- When the server could not be created or when it failed to start.
-
newServer
public static WebDavServer newServer(String username, String password, Path tmpDir) throws Exception
Starts a new WebDAV server secured with the given credentials.- Parameters:
username- User name that must be specified when connecting to the server.password- Password that must be specified when connecting to the server.tmpDir- Temporary directory for caching files.- Returns:
- A new server that requires the given user name and password for a connection.
- Throws:
Exception- When the server could not be created or when it failed to start.
-
-