Search in sources :

Example 1 with Support_TestWebServer

use of tests.support.Support_TestWebServer in project robovm by robovm.

the class URLConnectionTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    server = new Support_TestWebServer();
    port = server.initServer();
    url = new URL("http://localhost:" + port + "/test1");
    uc = url.openConnection();
    url2 = new URL("http://localhost:" + port + "/test2");
    uc2 = url2.openConnection();
    fileURL = createTempHelloWorldFile();
    fileURLCon = fileURL.openConnection();
    jarURLCon = openJarURLConnection();
    gifURLCon = openGifURLConnection();
}
Also used : Support_TestWebServer(tests.support.Support_TestWebServer) URL(java.net.URL)

Example 2 with Support_TestWebServer

use of tests.support.Support_TestWebServer in project robovm by robovm.

the class OldURLClassLoaderTest method test_findResourceLjava_lang_String.

@SideEffect("Support_TestWebServer requires isolation.")
public void test_findResourceLjava_lang_String() throws Exception {
    File tmp = File.createTempFile("test", ".txt");
    Support_TestWebServer server = new Support_TestWebServer();
    try {
        int port = server.initServer(tmp.getAbsolutePath(), "text/html");
        URL[] urls = { new URL("http://localhost:" + port + "/") };
        ucl = new URLClassLoader(urls);
        URL res = ucl.findResource("test1");
        assertNotNull("Failed to locate resource", res);
        StringBuffer sb = getResContent(res);
        assertEquals("Returned incorrect resource", new String(Support_TestWebData.test1), sb.toString());
    } finally {
        server.close();
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) Support_TestWebServer(tests.support.Support_TestWebServer) File(java.io.File) URL(java.net.URL) SideEffect(dalvik.annotation.SideEffect)

Example 3 with Support_TestWebServer

use of tests.support.Support_TestWebServer in project robovm by robovm.

the class OldURLClassLoaderTest method test_findResource_String.

/**
     * Regression for Harmony-2237
     */
@SideEffect("Support_TestWebServer requires isolation.")
public void test_findResource_String() throws Exception {
    File tempFile1 = File.createTempFile("textFile", ".txt");
    tempFile1.createNewFile();
    tempFile1.deleteOnExit();
    File tempFile2 = File.createTempFile("jarFile", ".jar");
    tempFile2.delete();
    tempFile2.deleteOnExit();
    Support_TestWebServer server = new Support_TestWebServer();
    try {
        int port = server.initServer();
        String tempPath1 = tempFile1.getParentFile().getAbsolutePath() + "/";
        InputStream is = getClass().getResourceAsStream("/tests/resources/hyts_patch.jar");
        Support_Resources.copyLocalFileto(tempFile2, is);
        String tempPath2 = tempFile2.getAbsolutePath();
        String tempPath3 = "http://localhost:" + port + "/";
        URLClassLoader urlLoader = getURLClassLoader(tempPath1, tempPath2);
        assertNull("Found inexistant resource", urlLoader.findResource("XXX"));
        assertNotNull("Couldn't find resource from directory", urlLoader.findResource(tempFile1.getName()));
        assertNotNull("Couldn't find resource from jar", urlLoader.findResource("Blah.txt"));
        urlLoader = getURLClassLoader(tempPath1, tempPath2, tempPath3);
        assertNotNull("Couldn't find resource from web", urlLoader.findResource("test1"));
        assertNull("Found inexistant resource from web", urlLoader.findResource("test3"));
    } finally {
        server.close();
    }
}
Also used : InputStream(java.io.InputStream) URLClassLoader(java.net.URLClassLoader) Support_TestWebServer(tests.support.Support_TestWebServer) File(java.io.File) SideEffect(dalvik.annotation.SideEffect)

Aggregations

Support_TestWebServer (tests.support.Support_TestWebServer)3 SideEffect (dalvik.annotation.SideEffect)2 File (java.io.File)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 InputStream (java.io.InputStream)1