Search in sources :

Example 6 with Downloader

use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.

the class GMTEDProviderTest method testFileNotFound.

@Test
public void testFileNotFound() {
    File file = new File(instance.getCacheDir(), instance.getFileName(46, -20) + ".gh");
    File zipFile = new File(instance.getCacheDir(), instance.getFileName(46, -20) + ".tif");
    file.delete();
    zipFile.delete();
    instance.setDownloader(new Downloader("test GH") {

        @Override
        public void downloadFile(String url, String toFile) throws IOException {
            throw new FileNotFoundException("xyz");
        }
    });
    assertEquals(0, instance.getEle(46, -20), 1);
    // file not found
    assertTrue(file.exists());
    assertEquals(1048676, file.length());
    instance.setDownloader(new Downloader("test GH") {

        @Override
        public void downloadFile(String url, String toFile) throws IOException {
            throw new SocketTimeoutException("xyz");
        }
    });
    try {
        instance.setSleep(30);
        instance.getEle(16, -20);
        fail();
    } catch (Exception ex) {
    }
    file.delete();
    zipFile.delete();
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) FileNotFoundException(java.io.FileNotFoundException) Downloader(com.graphhopper.util.Downloader) IOException(java.io.IOException) File(java.io.File) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test)

Aggregations

Downloader (com.graphhopper.util.Downloader)6 GHRequest (com.graphhopper.GHRequest)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HttpURLConnection (java.net.HttpURLConnection)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 GHResponse (com.graphhopper.GHResponse)1 PathWrapper (com.graphhopper.PathWrapper)1