use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.
the class GraphHopperWebTest method testCreateURL.
@Test
public void testCreateURL() throws Exception {
Downloader downloader = new Downloader("GraphHopper Test") {
@Override
public String downloadAsString(String url, boolean readErrorStreamNoException) throws IOException {
assertFalse(url.contains("xy"));
assertFalse(url.contains("algo1"));
assertTrue(url.contains("alternative_route.max_paths=4"));
assertEquals("https://graphhopper.com/api/1/route?point=52.0,13.0&point=52.0,14.0&&type=json&instructions=true&points_encoded=true&calc_points=true&algorithm=&locale=en_US&elevation=false&key=blup&alternative_route.max_paths=4", url);
return Helper.isToString(getClass().getResourceAsStream("test_encoded.json"));
}
};
GraphHopperWeb instance = new GraphHopperWeb();
instance.setKey("blup");
instance.setDownloader(downloader);
GHRequest req = new GHRequest(52, 13, 52, 14);
// should be ignored, use GraphHopperWeb or GHRequest directly instead
req.getHints().put("key", "xy");
req.getHints().put("algorithm", "algo1");
req.getHints().put("alternative_route.max_paths", "4");
instance.route(req);
}
use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.
the class GraphHopperWebTest method testReadEncoded.
// see also GraphHopperServletIT.testGraphHopperWeb for real routes against local jetty service
@Test
public void testReadEncoded() throws Exception {
Downloader downloader = new Downloader("GraphHopper Test") {
@Override
public InputStream fetch(HttpURLConnection conn, boolean readErrorStreamNoException) throws IOException {
return getClass().getResourceAsStream("test_encoded.json");
}
};
GraphHopperWeb instance = new GraphHopperWeb();
instance.setDownloader(downloader);
GHResponse rsp = instance.route(new GHRequest(52.47379, 13.362808, 52.4736925, 13.3904394));
PathWrapper arsp = rsp.getBest();
assertEquals(2138.3, arsp.getDistance(), 1e-1);
assertEquals(17, arsp.getPoints().getSize());
assertEquals(5, arsp.getInstructions().getSize());
assertEquals("(0,Geradeaus auf A 100,1268.519329705091,65237)", arsp.getInstructions().get(0).toString());
assertEquals(11, arsp.getInstructions().get(0).getPoints().size());
assertEquals(43.73595, arsp.getWaypoints().getLat(0), 1e-4);
assertEquals(7.42015, arsp.getWaypoints().getLon(0), 1e-4);
assertEquals(43.73761, arsp.getWaypoints().getLat(1), 1e-4);
}
use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.
the class BaseServletTester method nearestQuery.
protected JsonNode nearestQuery(String query) throws Exception {
String resQuery = "";
for (String q : query.split("\\&")) {
int index = q.indexOf("=");
if (index > 0)
resQuery += q.substring(0, index + 1) + WebHelper.encodeURL(q.substring(index + 1));
else
resQuery += WebHelper.encodeURL(q);
resQuery += "&";
}
String url = getTestNearestAPIUrl() + "?" + resQuery;
Downloader downloader = new Downloader("web integration tester");
return objectMapper.readTree(downloader.downloadAsString(url, true));
}
use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.
the class BaseServletTester method queryString.
protected String queryString(String query, int code) throws Exception {
String resQuery = "";
for (String q : query.split("\\&")) {
int index = q.indexOf("=");
if (index > 0)
resQuery += q.substring(0, index + 1) + WebHelper.encodeURL(q.substring(index + 1));
else
resQuery += WebHelper.encodeURL(q);
resQuery += "&";
}
String url = getTestRouteAPIUrl() + "?" + resQuery;
Downloader downloader = new Downloader("web integration tester").setTimeout(2000);
HttpURLConnection conn = downloader.createConnection(url);
conn.connect();
assertEquals(code, conn.getResponseCode());
return Helper.isToString(downloader.fetch(conn, true));
}
use of com.graphhopper.util.Downloader in project graphhopper by graphhopper.
the class CGIARProviderTest 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) + ".zip");
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();
}
Aggregations