diff --git a/brouter-server/src/test/java/btools/server/RouteServerTest.java b/brouter-server/src/test/java/btools/server/RouteServerTest.java index d4c971e..ad6776c 100644 --- a/brouter-server/src/test/java/btools/server/RouteServerTest.java +++ b/brouter-server/src/test/java/btools/server/RouteServerTest.java @@ -14,6 +14,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.ConnectException; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -28,7 +30,7 @@ public class RouteServerTest { public static TemporaryFolder profileDir = new TemporaryFolder(); @BeforeClass - public static void setupServer() throws IOException, InterruptedException { + public static void setupServer() throws IOException, InterruptedException, URISyntaxException { File workingDir = new File(".").getCanonicalFile(); File segmentDir = new File(workingDir, "../brouter-map-creator/build/resources/test/tmp/segments"); File profileSourceDir = new File(workingDir, "../misc/profiles2"); @@ -41,7 +43,7 @@ public class RouteServerTest { try { RouteServer.main(new String[]{segmentDir.getAbsolutePath(), profileDir.getRoot().getAbsolutePath(), customProfileDir, port, "1"}); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(System.out); } }; @@ -49,7 +51,7 @@ public class RouteServerTest { thread.start(); // Busy-wait for server startup - URL requestUrl = new URL(baseUrl); + URL requestUrl = new URI(baseUrl).toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); for (int i = 20; i >= 0; i--) { try { @@ -66,8 +68,8 @@ public class RouteServerTest { } @Test - public void defaultRouteTrekking() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.723037,50.000491|8.712737,50.002899&nogos=&profile=trekking&alternativeidx=0&format=geojson"); + public void defaultRouteTrekking() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.723037,50.000491%7C8.712737,50.002899&nogos=&profile=trekking&alternativeidx=0&format=geojson").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -82,8 +84,8 @@ public class RouteServerTest { } @Test - public void overrideParameter() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.723037,50.000491|8.712737,50.002899&nogos=&profile=trekking&alternativeidx=0&format=geojson&profile:avoid_unsafe=1"); + public void overrideParameter() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.723037,50.000491%7C8.712737,50.002899&nogos=&profile=trekking&alternativeidx=0&format=geojson&profile:avoid_unsafe=1").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -95,8 +97,8 @@ public class RouteServerTest { } @Test - public void voiceHints() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.705796,50.003124|8.705859,50.0039599&nogos=&profile=trekking&alternativeidx=0&format=geojson&timode=2"); + public void voiceHints() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.705796,50.003124%7C8.705859,50.0039599&nogos=&profile=trekking&alternativeidx=0&format=geojson&timode=2").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -108,8 +110,8 @@ public class RouteServerTest { } @Test - public void directRoutingFirst() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.718354,50.001514|8.718917,50.001361|8.716986,50.000105|8.718306,50.00145&nogos=&profile=trekking&alternativeidx=0&format=geojson&straight=0&timode=3"); + public void directRoutingFirst() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.718354,50.001514%7C8.718917,50.001361%7C8.716986,50.000105%7C8.718306,50.00145&nogos=&profile=trekking&alternativeidx=0&format=geojson&straight=0&timode=3").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -121,8 +123,8 @@ public class RouteServerTest { } @Test - public void directRoutingLast() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.718306,50.00145|8.717464,50.000405|8.718917,50.001361|8.718354,50.001514&nogos=&profile=trekking&alternativeidx=0&format=geojson&straight=2&timode=3"); + public void directRoutingLast() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.718306,50.00145%7C8.717464,50.000405%7C8.718917,50.001361%7C8.718354,50.001514&nogos=&profile=trekking&alternativeidx=0&format=geojson&straight=2&timode=3").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -134,8 +136,8 @@ public class RouteServerTest { } @Test - public void directRoutingMiddle() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.718539,50.006581|8.718198,50.006065,d|8.71785,50.006034|8.7169,50.004456&nogos=&profile=trekking&alternativeidx=0&format=geojson&timode=3"); + public void directRoutingMiddle() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.718539,50.006581%7C8.718198,50.006065,d%7C8.71785,50.006034%7C8.7169,50.004456&nogos=&profile=trekking&alternativeidx=0&format=geojson&timode=3").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -147,8 +149,8 @@ public class RouteServerTest { } @Test - public void misplacedPoints() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter?lonlats=8.708678,49.999188|8.71145,49.999761|8.715801,50.00065&nogos=&profile=trekking&alternativeidx=0&format=geojson&correctMisplacedViaPoints=1&timode=3"); + public void misplacedPoints() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.708678,49.999188%7C8.71145,49.999761%7C8.715801,50.00065&nogos=&profile=trekking&alternativeidx=0&format=geojson&correctMisplacedViaPoints=1&timode=3").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -160,8 +162,21 @@ public class RouteServerTest { } @Test - public void uploadValidProfile() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter/profile"); + public void misplacedPointsRoundabout() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter?lonlats=8.699487,50.001257%7C8.701569,50.000092%7C8.704873,49.998898&nogos=&profile=trekking&alternativeidx=0&format=geojson&profile:correctMisplacedViaPoints=1&timode=3").toURL(); + HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); + httpConnection.connect(); + + Assert.assertEquals(HttpURLConnection.HTTP_OK, httpConnection.getResponseCode()); + + InputStream inputStream = httpConnection.getInputStream(); + JSONObject geoJson = new JSONObject(new String(inputStream.readAllBytes(), StandardCharsets.UTF_8)); + Assert.assertEquals("482", geoJson.query("/features/0/properties/track-length")); + } + + @Test + public void uploadValidProfile() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter/profile").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.setRequestMethod("POST"); @@ -192,8 +207,8 @@ public class RouteServerTest { } @Test - public void uploadInvalidProfile() throws IOException { - URL requestUrl = new URL(baseUrl + "brouter/profile"); + public void uploadInvalidProfile() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "brouter/profile").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.setRequestMethod("POST"); @@ -214,8 +229,8 @@ public class RouteServerTest { } @Test - public void robots() throws IOException { - URL requestUrl = new URL(baseUrl + "robots.txt"); + public void robots() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "robots.txt").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect(); @@ -226,8 +241,8 @@ public class RouteServerTest { } @Test - public void invalidUrl() throws IOException { - URL requestUrl = new URL(baseUrl + "invalid"); + public void invalidUrl() throws IOException, URISyntaxException { + URL requestUrl = new URI(baseUrl + "invalid").toURL(); HttpURLConnection httpConnection = (HttpURLConnection) requestUrl.openConnection(); httpConnection.connect();