Package de.xima.fc.testhelper
Class WebDavServer
java.lang.Object
de.xima.fc.testhelper.WebDavServer
- All Implemented Interfaces:
AutoCloseable
A simple WebDav server against which integration tests can be run.
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
byte[]
fileContentAsByteArray
(String... path) fileContentAsStream
(String... path) fileContentAsUtf8String
(String... path) List<com.github.sardine.DavResource>
List<com.github.sardine.DavResource>
List<com.github.sardine.DavResource>
void
static WebDavServer
Starts a new WebDAV server that does not required credentials.static WebDavServer
Starts a new WebDAV server secured with the given credentials.void
void
void
put
(String path, InputStream data) void
void
void
putUtf8String
(String path, String data)
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
davUri
- Parameters:
path
- Path on the WebDAV server.- Returns:
- URL for the given path, with the
dav://
protocol.
-
exists
- Parameters:
path
- Path to check.- Returns:
true
if the given path exists on the server, orfalse
otherwise.- Throws:
IOException
- When the path could not be checked, usually due to a network error.
-
fileContentAsByteArray
- 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
- 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
- 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
- Parameters:
paths
- Path on the WebDAV server.- Returns:
- URL for the given path, with the
http://
protocol.
-
lsDir
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
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.
-