|
| 1 | +package org.heigit.ors.routing.graphhopper.extensions.util.parsers; |
| 2 | + |
| 3 | +import org.heigit.ors.common.EncoderNameEnum; |
| 4 | +import org.heigit.ors.config.EngineProperties; |
| 5 | +import org.heigit.ors.config.profile.BuildProperties; |
| 6 | +import org.heigit.ors.config.profile.ExtendedStorageName; |
| 7 | +import org.heigit.ors.config.profile.ExtendedStorageProperties; |
| 8 | +import org.heigit.ors.config.profile.ProfileProperties; |
| 9 | +import org.heigit.ors.routing.graphhopper.extensions.GraphProcessContext; |
| 10 | +import org.heigit.ors.routing.graphhopper.extensions.ORSGraphHopper; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | + |
| 13 | +import java.nio.file.Path; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 18 | + |
| 19 | +class BorderParserTest { |
| 20 | + |
| 21 | + private ORSGraphHopper initializeGraphHopper(ExtendedStorageProperties parameters) throws Exception { |
| 22 | + parameters.setIds(Path.of("../ors-api/src/test/files/borders/ids.csv")); |
| 23 | + parameters.setOpenborders(Path.of("../ors-api/src/test/files/borders/openborders.csv")); |
| 24 | + |
| 25 | + BuildProperties buildProperties = new BuildProperties(); |
| 26 | + buildProperties.setExtStorages(Map.of(ExtendedStorageName.BORDERS.getName(), parameters)); |
| 27 | + |
| 28 | + ProfileProperties profileProperties = new ProfileProperties(); |
| 29 | + profileProperties.setBuild(buildProperties); |
| 30 | + profileProperties.setEncoderName(EncoderNameEnum.DRIVING_CAR); |
| 31 | + |
| 32 | + return new ORSGraphHopper(new GraphProcessContext(profileProperties), new EngineProperties(), profileProperties); |
| 33 | + } |
| 34 | + |
| 35 | + /* |
| 36 | + * Test that the builder successfully initializes with a valid boundaries file and throws an exception |
| 37 | + * if the boundaries file is invalid. |
| 38 | + */ |
| 39 | + @Test |
| 40 | + void TestInit() throws Exception { |
| 41 | + ExtendedStorageProperties parameters = new ExtendedStorageProperties(); |
| 42 | + ORSGraphHopper gh = initializeGraphHopper(parameters); |
| 43 | + |
| 44 | + parameters.setBoundaries(Path.of("foo.bar")); |
| 45 | + assertThrows(RuntimeException.class, () -> { |
| 46 | + new BorderParser(gh); |
| 47 | + }); |
| 48 | + |
| 49 | + parameters.setBoundaries(Path.of("../ors-api/src/test/files/borders/borders.geojson")); |
| 50 | + assertDoesNotThrow(() -> { |
| 51 | + new BorderParser(gh); |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + /* |
| 56 | + * Test that the builder successfully initializes for preprocessed OSM data in case of invalid boundaries file, |
| 57 | + * as it is not needed for already annotated data. |
| 58 | + */ |
| 59 | + @Test |
| 60 | + void TestInitPreprocessed() throws Exception { |
| 61 | + ExtendedStorageProperties parameters = new ExtendedStorageProperties(); |
| 62 | + ORSGraphHopper gh = initializeGraphHopper(parameters); |
| 63 | + |
| 64 | + parameters.setPreprocessed(true); |
| 65 | + parameters.setBoundaries(Path.of("foo.bar")); |
| 66 | + assertDoesNotThrow(() -> { |
| 67 | + new BorderParser(gh); |
| 68 | + }); |
| 69 | + } |
| 70 | +} |
0 commit comments