Writing automatic tests requiring external resources

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (2)

View Page History
h2. Creating the web-server

The creation of the web-server requires the a HTTP port on which it will listen. The default listening port is '{{WebServer.DEFAULT_HTTP_PORT}'. You can use your own HTTP port using the right constructor:
{code}
// A web server listening on the default HTTP port
}
{code}

h1. A FTP server as external resource

The {{FTPServer}} rule allows creation of files and folders that are guaranteed to be deleted when the test method finishes (whether it passes or fails):
{code}
public static class HasFTPServer {
@Rule
public FTPServer ftpServer = new FTPServer();

@Test
public void testUsingFTPServer() throws IOException {
// ...
this.ftpServer.registerUser(user);
// ...
}
}
{code}

h2. Creating the FTP server

The creation of the FTP server requires a FTP port on which it will listen. The default listening port is '{{FTPServer.DEFAULT_HTTP_PORT}'. You can use your own FTP port using the right constructor:
{code}
// A FTP server listening on the default FTP port
@Rule
public FTPServer ftpServer = new FTPServer();

// A FTP server listening on your own FTP port
@Rule
public FTPServer ftpServer = new FTPServer(5000);
{code}

h2. Registering users on FTP server

Users must be declared on the FTP server side to be usable. So you must register the needed users before trying to use the FTP server.

A user is declared in the FTP server using the API '{{FTPServer.registerUser(user)}}':
{code}
public static class HasFTPServer {
@Rule
public FTPServer ftpServer = new FTPServer();

@Test
public void testUsingFTPServer() throws IOException {
// ...
final BaseUser user = new BaseUser();
user.setName("user");
user.setPassword("test");
final List<Authority> authorities = new ArrayList<Authority>();
authorities.add(new WritePermission());
user.setAuthorities(authorities);
final File homeDirectory = new File(this.ftpServer.getRootFileSystem(), user.getName());
user.setHomeDirectory(homeDirectory.getAbsolutePath());
this.ftpServer.registerUser(user);
// ...
}
}
{code}