diff --git a/brouter-core/build.gradle b/brouter-core/build.gradle index c96982f..cb7dde5 100644 --- a/brouter-core/build.gradle +++ b/brouter-core/build.gradle @@ -3,11 +3,12 @@ plugins { } dependencies { - implementation project(':brouter-mapaccess') implementation project(':brouter-util') implementation project(':brouter-expressions') implementation project(':brouter-codec') - testImplementation 'junit:junit:4.13.1' - + testImplementation 'junit:junit:4.13.2' } + +// MapcreatorTest generates segments which are used in tests +test.dependsOn ':brouter-map-creator:test' diff --git a/brouter-server/src/test/java/btools/server/RouterTest.java b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java similarity index 63% rename from brouter-server/src/test/java/btools/server/RouterTest.java rename to brouter-core/src/test/java/btools/router/RoutingEngineTest.java index 210e033..ba2dc90 100644 --- a/brouter-server/src/test/java/btools/server/RouterTest.java +++ b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java @@ -1,50 +1,46 @@ -package btools.server; - -import java.util.*; +package btools.router; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import java.net.URL; import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; -import btools.router.*; -import btools.mapaccess.*; - -public class RouterTest { +public class RoutingEngineTest { private File workingDir; - @Test - public void routerTest() throws Exception { + @Before + public void before() { URL resulturl = this.getClass().getResource("/testtrack0.gpx"); - Assert.assertTrue("reference result not found: ", resulturl != null); + Assert.assertNotNull("reference result not found: ", resulturl); File resultfile = new File(resulturl.getFile()); workingDir = resultfile.getParentFile(); + } - String msg; - - // first test: route within dreiech test-map crossing tile border - - msg = calcRoute(8.720897, 50.002515, 8.723658, 49.997510, "testtrack"); - + @Test + public void routeCrossingSegmentBorder() { + String msg = calcRoute(8.720897, 50.002515, 8.723658, 49.997510, "testtrack"); // error message from router? - Assert.assertTrue("routing failed: " + msg, msg == null); + Assert.assertNull("routing failed: " + msg, msg); // if the track didn't change, we expect the first alternative also File a1 = new File(workingDir, "testtrack1.gpx"); Assert.assertTrue("result content missmatch", a1.exists()); - - // second test: to-point far off - - msg = calcRoute(8.720897, 50.002515, 16.723658, 49.997510, "notrack"); - - Assert.assertTrue(msg, msg != null && msg.indexOf("not found") >= 0); } - private String calcRoute(double flon, double flat, double tlon, double tlat, String trackname) throws Exception { + @Test + public void routeDestinationPointFarOff() { + String msg = calcRoute(8.720897, 50.002515, 16.723658, 49.997510, "notrack"); + Assert.assertTrue(msg, msg != null && msg.contains("not found")); + } + + private String calcRoute(double flon, double flat, double tlon, double tlat, String trackname) { String wd = workingDir.getAbsolutePath(); - List wplist = new ArrayList(); + List wplist = new ArrayList<>(); OsmNodeNamed n; n = new OsmNodeNamed(); n.name = "from"; @@ -60,7 +56,6 @@ public class RouterTest { RoutingContext rctx = new RoutingContext(); rctx.localFunction = wd + "/../../../../misc/profiles2/trekking.brf"; - // c.setAlternativeIdx( 1 ); RoutingEngine re = new RoutingEngine( wd + "/" + trackname, diff --git a/brouter-server/src/test/resources/testtrack0.gpx b/brouter-core/src/test/resources/testtrack0.gpx similarity index 100% rename from brouter-server/src/test/resources/testtrack0.gpx rename to brouter-core/src/test/resources/testtrack0.gpx diff --git a/brouter-mapaccess/build.gradle b/brouter-mapaccess/build.gradle index c920239..40189cb 100644 --- a/brouter-mapaccess/build.gradle +++ b/brouter-mapaccess/build.gradle @@ -6,4 +6,8 @@ dependencies { implementation project(':brouter-util') implementation project(':brouter-codec') implementation project(':brouter-expressions') + testImplementation 'junit:junit:4.13.2' } + +// MapcreatorTest generates segments which are used in tests +test.dependsOn ':brouter-map-creator:test' diff --git a/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java new file mode 100644 index 0000000..6685895 --- /dev/null +++ b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java @@ -0,0 +1,25 @@ +package btools.mapaccess; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +public class IntegrityCheckTest { + @Test + public void integrityTest() throws IOException { + File workingDir = new File(".").getCanonicalFile(); + File segmentDir = new File(workingDir, "../brouter-map-creator/build/resources/test/tmp/segments"); + File[] files = segmentDir.listFiles(); + + assertNotNull("Missing segments", files); + + for (File f : files) { + assertNull(PhysicalFile.checkFileIntegrity(f)); + } + } + +} diff --git a/brouter-server/src/test/java/btools/server/IntegrityCheckTest.java b/brouter-server/src/test/java/btools/server/IntegrityCheckTest.java deleted file mode 100644 index cdae8d3..0000000 --- a/brouter-server/src/test/java/btools/server/IntegrityCheckTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package btools.server; - -import java.io.File; -import java.net.URL; - -import org.junit.Assert; -import org.junit.Test; - -import btools.mapaccess.PhysicalFile; - -public class IntegrityCheckTest { - private File workingDir; - - @Test - public void integrityTest() throws Exception { - URL resulturl = this.getClass().getResource("/testtrack0.gpx"); - Assert.assertTrue("reference result not found: ", resulturl != null); - File resultfile = new File(resulturl.getFile()); - workingDir = resultfile.getParentFile(); - - File segmentDir = new File(workingDir, "/../../../../brouter-map-creator/build/resources/test/tmp/segments"); - File[] files = segmentDir.listFiles(); - - for (File f : files) { - PhysicalFile.checkFileIntegrity(f); - } - } - -}