Skip to content

Commit 472f8d2

Browse files
committed
test: add unit tests for the initialization of BorderParser
1 parent 5789707 commit 472f8d2

4 files changed

Lines changed: 73 additions & 5 deletions

File tree

ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/util/parsers/BorderParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BorderParser implements TagParser {
3434
private static final String TAG_KEY_COUNTRY2 = "country2";
3535
private final ExtendedStorageProperties parameters;
3636
private CountryBordersReader cbReader;
37-
boolean preprocessed = false;
37+
boolean preprocessed;
3838
private Map<Integer, Map<String, String>> nodeTags;
3939

4040

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
}

ors-engine/src/test/java/org/heigit/ors/routing/graphhopper/extensions/util/parsers/WaySurfaceParserTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class WaySurfaceParserTest {
1818
private static final WaySurface SIDEWALK_SURFACE = WaySurface.PAVING_STONES;
1919
private static final WaySurface SIDEWALK_SURFACE_OTHER = WaySurface.CONCRETE;
2020

21-
private EncodingManager em;
2221
private EnumEncodedValue<WaySurface> surfaceEnc;
2322
private WaySurfaceParser parser;
2423
private IntsRef intsRef, relFlags;
2524

2625
@BeforeEach
2726
void setUp() {
2827
parser = new WaySurfaceParser();
29-
em = new EncodingManager.Builder().add(parser).build();
28+
EncodingManager em = new EncodingManager.Builder().add(parser).build();
3029
surfaceEnc = em.getEnumEncodedValue(WaySurface.KEY, WaySurface.class);
3130
relFlags = em.createRelationFlags();
3231
intsRef = em.createEdgeFlags();

ors-engine/src/test/java/org/heigit/ors/routing/graphhopper/extensions/util/parsers/WayTypeParserTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
import static org.junit.jupiter.api.Assertions.assertEquals;
1313

1414
class WayTypeParserTest {
15-
private EncodingManager em;
1615
private EnumEncodedValue<WayType> wayTypeEnc;
1716
private WayTypeParser parser;
1817
private IntsRef intsRef, relFlags;
1918

2019
@BeforeEach
2120
void setUp() {
2221
parser = new WayTypeParser();
23-
em = new EncodingManager.Builder().add(parser).build();
22+
EncodingManager em = new EncodingManager.Builder().add(parser).build();
2423
wayTypeEnc = em.getEnumEncodedValue(WayType.KEY, WayType.class);
2524
relFlags = em.createRelationFlags();
2625
intsRef = em.createEdgeFlags();

0 commit comments

Comments
 (0)