// Create a temporary directory for the tests
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests1" + new Date().getTime());
// Create a new Restlet component
final Component clientComponent = new Component();
clientComponent.getClients().add(Protocol.FILE);
// Create an application
final MyApplication application = new MyApplication(this.testDir);
// Attach the application to the component and start it
clientComponent.getDefaultHost().attach("", application);
// Now, let's start the component!
clientComponent.start();
// Allow extensions tunneling
application.getTunnelService().setExtensionsTunnel(true);
BioUtils.delete(this.testDir, true);
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests2" + new Date().getTime());
this.testDir.mkdirs();
application.setTestDirectory(testDir);
// Test the directory Restlet with an index name
testDirectory(application, application.getDirectory(), "index");
BioUtils.delete(this.testDir, true);
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests3" + new Date().getTime());
this.testDir.mkdirs();
application.setTestDirectory(testDir);
// Test the directory Restlet with no index name
testDirectory(application, application.getDirectory(), "");
// Avoid extensions tunneling
application.getTunnelService().setExtensionsTunnel(false);
BioUtils.delete(this.testDir, true);
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests4" + new Date().getTime());
this.testDir.mkdirs();
application.setTestDirectory(testDir);
// Test the directory Restlet with an index name
testDirectory(application, application.getDirectory(), "index");
BioUtils.delete(this.testDir, true);
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests5" + new Date().getTime());
this.testDir.mkdirs();
application.setTestDirectory(testDir);
// Test the directory Restlet with no index name
testDirectory(application, application.getDirectory(), "");
BioUtils.delete(this.testDir, true);
this.testDir = new File(System.getProperty("java.io.tmpdir"),
"DirectoryTestCase/tests6" + new Date().getTime());
this.testDir.mkdirs();
application.setTestDirectory(testDir);
// Test the access to the sub directories.
testDirectoryDeeplyAccessible(application, application.getDirectory());
// Now, let's stop the component!
clientComponent.stop();
}