*/
public class ApplicationServerHandlerTest extends TestCase {
public void testFileRetrieval() throws Exception {
WebServerFactory webServerFactory = WebServerFactory.newInstance();
ServerBinding serverBinding = new ServerBinding() {
public InetAddress getInetAddress() {
try {
return InetAddress.getByName("localhost");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
public int getPort() {
return 8989;
}
};
URL basePathURL = GVSServerLauncher.class
.getResource("/META-INF/web/application/");
PathNode rootNode = PathNodeFactory.getPathNode(basePathURL);
WebServer webServer = webServerFactory.startNewWebServer(
new ApplicationServerHandler(rootNode, "/application"),
serverBinding);
try {
URL serverURL = new URL("http://"
+ serverBinding.getInetAddress().getHostAddress() + ":"
+ serverBinding.getPort()
+ "/application/test-dir/test-data");
InputStream remoteStream = serverURL.openStream();
InputStream resourceStream = ApplicationServerHandler.class
.getResourceAsStream("/META-INF/web/application/test-dir/test-data.txt");
for (int i = resourceStream.read(); i < -1; i = resourceStream
.read()) {
assertEquals(i, remoteStream.read());
}
// same with URL-extension
serverURL = new URL("http://"
+ serverBinding.getInetAddress().getHostAddress() + ":"
+ serverBinding.getPort()
+ "/application/test-dir/test-data.txt");
remoteStream = serverURL.openStream();
resourceStream = ApplicationServerHandler.class
.getResourceAsStream("/META-INF/web/application/test-dir/test-data.txt");
for (int i = resourceStream.read(); i > -1; i = resourceStream