Search in sources :

Example 1 with DefaultURLConnector

use of aQute.bnd.deployer.http.DefaultURLConnector in project bnd by bndtools.

the class CachingUriResourceHandlerTest method testLoadFromRemote.

public static void testLoadFromRemote() throws Exception {
    String testDirName = "testdata/httpcache/3";
    File cacheDir = new File(testDirName);
    URI baseUri = new URI("http://localhost:18083/bundles");
    URI uri = new URI(baseUri + "/dummybundle.jar");
    CachingUriResourceHandle handle = new CachingUriResourceHandle(uri, cacheDir, new DefaultURLConnector(), (String) null);
    NanoHTTPD httpd = new NanoHTTPD(18083, IO.getFile("testdata/http"));
    try {
        File result = handle.request();
        assertEquals(IO.getFile("testdata/httpcache/3/http%3A%2F%2Flocalhost%3A18083%2Fbundles/dummybundle.jar").getAbsolutePath(), result.getAbsolutePath());
        File shaFile = new File(result.getAbsolutePath() + AbstractIndexedRepo.REPO_INDEX_SHA_EXTENSION);
        assertEquals(EXPECTED_SHA, IO.collect(shaFile));
        result.delete();
        shaFile.delete();
        /* cleanup */
        List<String> cacheFiles = Arrays.asList(cacheDir.list());
        String uriCacheDir = URLEncoder.encode(baseUri.toURL().toExternalForm(), "UTF-8");
        assert (cacheFiles.size() == 1 || cacheFiles.size() == 2);
        assert (cacheFiles.contains(uriCacheDir));
        if (cacheFiles.size() == 2) {
            assert (cacheFiles.contains(".gitignore"));
        }
        IO.getFile(testDirName + "/" + uriCacheDir).delete();
    } finally {
        httpd.stop();
    }
}
Also used : NanoHTTPD(test.lib.NanoHTTPD) File(java.io.File) URI(java.net.URI) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector)

Example 2 with DefaultURLConnector

use of aQute.bnd.deployer.http.DefaultURLConnector in project bnd by bndtools.

the class CachingUriResourceHandlerTest method testReplaceCache.

public static void testReplaceCache() throws Exception {
    File cached = IO.getFile("testdata/httpcache/5/http%3A%2F%2Flocalhost%3A18083%2Fbundles/dummybundle.jar");
    long cacheTimestamp = cached.lastModified();
    // Clear the SHA so the file appears modified
    File shaFile = new File(cached.getAbsolutePath() + AbstractIndexedRepo.REPO_INDEX_SHA_EXTENSION);
    IO.store("00000000", shaFile);
    CachingUriResourceHandle handle = new CachingUriResourceHandle(new URI("http://localhost:18083/bundles/dummybundle.jar"), IO.getFile("testdata/httpcache/5"), new DefaultURLConnector(), EXPECTED_SHA);
    NanoHTTPD httpd = new NanoHTTPD(18083, IO.getFile("testdata/http"));
    try {
        File result = handle.request();
        assertEquals(cached, result);
        assertNotSame("File timestamp SHOULD change", cacheTimestamp, result.lastModified());
        assertEquals(EXPECTED_SHA, IO.collect(shaFile));
    } finally {
        httpd.stop();
    }
}
Also used : NanoHTTPD(test.lib.NanoHTTPD) File(java.io.File) URI(java.net.URI) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector)

Example 3 with DefaultURLConnector

use of aQute.bnd.deployer.http.DefaultURLConnector in project bnd by bndtools.

the class CachingUriResourceHandlerTest method testLoadFromCache.

public static void testLoadFromCache() throws Exception {
    CachingUriResourceHandle handle = new CachingUriResourceHandle(new URI("http://localhost:18083/bundles/dummybundle.jar"), IO.getFile("testdata/httpcache/1"), new DefaultURLConnector(), (String) null);
    File result = handle.request();
    assertEquals(IO.getFile("testdata/httpcache/1/http%3A%2F%2Flocalhost%3A18083%2Fbundles/dummybundle.jar").getAbsolutePath(), result.getAbsolutePath());
}
Also used : URI(java.net.URI) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector) File(java.io.File)

Example 4 with DefaultURLConnector

use of aQute.bnd.deployer.http.DefaultURLConnector in project bnd by bndtools.

the class CachingUriResourceHandlerTest method testFailedLoadFromRemote.

public static void testFailedLoadFromRemote() throws Exception {
    String testDirName = "testdata/httpcache/2";
    File cacheDir = new File(testDirName);
    URI baseUri = new URI("http://localhost:18083/bundles");
    URI uri = new URI(baseUri + "/dummybundle.jar");
    CachingUriResourceHandle handle = new CachingUriResourceHandle(uri, cacheDir, new DefaultURLConnector(), (String) null);
    try {
        handle.request();
        fail("Should throw IOException");
    } catch (IOException e) {
        // expected
        /* cleanup */
        List<String> cacheFiles = Arrays.asList(cacheDir.list());
        String uriCacheDir = URLEncoder.encode(baseUri.toURL().toExternalForm(), "UTF-8");
        assert (cacheFiles.size() == 1 || cacheFiles.size() == 2);
        assert (cacheFiles.contains(uriCacheDir));
        if (cacheFiles.size() == 2) {
            assert (cacheFiles.contains(".gitignore"));
        }
        IO.getFile(testDirName + "/" + uriCacheDir).delete();
    }
}
Also used : List(java.util.List) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector)

Example 5 with DefaultURLConnector

use of aQute.bnd.deployer.http.DefaultURLConnector in project bnd by bndtools.

the class CachingUriResourceHandlerTest method testEmptyCache.

public static void testEmptyCache() throws Exception {
    String testDirName = "testdata/httpcache/6";
    File cacheDir = new File(testDirName);
    URI baseUri = new URI("http://localhost:18083/bundles");
    String jarName = "dummybundle.jar";
    URI uri = new URI(baseUri + "/" + jarName);
    String uriCacheDir = URLEncoder.encode(baseUri.toURL().toExternalForm(), "UTF-8");
    File cached = IO.getFile(testDirName + "/" + uriCacheDir + "/" + jarName);
    cached.delete();
    File shaFile = new File(cached.getAbsolutePath() + AbstractIndexedRepo.REPO_INDEX_SHA_EXTENSION);
    shaFile.delete();
    CachingUriResourceHandle handle = new CachingUriResourceHandle(uri, cacheDir, new DefaultURLConnector(), EXPECTED_SHA);
    NanoHTTPD httpd = new NanoHTTPD(18083, IO.getFile("testdata/http"));
    try {
        File result = handle.request();
        assertEquals(cached, result.getAbsoluteFile());
        assertEquals(EXPECTED_SHA, IO.collect(shaFile));
        /* cleanup */
        List<String> cacheFiles = Arrays.asList(cacheDir.list());
        assert (cacheFiles.size() == 1 || cacheFiles.size() == 2);
        assert (cacheFiles.contains(uriCacheDir));
        if (cacheFiles.size() == 2) {
            assert (cacheFiles.contains(".gitignore"));
        }
        IO.delete(IO.getFile(testDirName + "/" + uriCacheDir));
    } finally {
        httpd.stop();
    }
}
Also used : NanoHTTPD(test.lib.NanoHTTPD) File(java.io.File) URI(java.net.URI) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector)

Aggregations

DefaultURLConnector (aQute.bnd.deployer.http.DefaultURLConnector)8 File (java.io.File)7 URI (java.net.URI)7 NanoHTTPD (test.lib.NanoHTTPD)4 URLConnector (aQute.bnd.service.url.URLConnector)1 IOException (java.io.IOException)1 List (java.util.List)1