Skip to content

Commit 2f64412

Browse files
committed
add tests for complex extra tags
1 parent bccfdf3 commit 2f64412

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/test/java/de/komoot/photon/api/ApiIntegrationTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.file.Path;
1515
import java.util.Date;
1616
import java.util.List;
17+
import java.util.Map;
1718

1819
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
1920

@@ -31,6 +32,7 @@ class ApiIntegrationTest extends ApiBaseTester {
3132
@BeforeAll
3233
void setUp(@TempDir Path dataDirectory) throws Exception {
3334
getProperties().setSupportGeometries(true);
35+
getProperties().setExtraTags(List.of("ALL"));
3436
getProperties().setImportDate(TEST_DATE);
3537
setUpES(dataDirectory);
3638
Importer instance = makeImporter();
@@ -60,6 +62,20 @@ void setUp(@TempDir Path dataDirectory) throws Exception {
6062
.geometry(makeDocGeometry("LINESTRING (30 10, 10 30, 40 40)"))
6163
.names(makeDocNames("name", "berlin"))
6264
));
65+
instance.add(List.of(new PhotonDoc()
66+
.placeId("5100").osmType("N").osmId(105100).tagKey("highway").tagValue("bus_stop")
67+
.categories(List.of("osm.highway.bus_stop"))
68+
.importance(0.3).addressType(AddressType.HOUSE)
69+
.centroid(makePoint(12.5, -44.345))
70+
.names(makeDocNames("name", "MyBusStop"))
71+
.extraTags(Map.of(
72+
"number", 56.7,
73+
"boolean", true,
74+
"array", List.of(1, 2, 3),
75+
"object", Map.of("foo", "bar"),
76+
"string", "Foo"
77+
))
78+
));
6379

6480
instance.finish();
6581
refresh();
@@ -98,6 +114,22 @@ void testApi(String osmValue, String url) throws Exception {
98114
.containsEntry("name", "berlin");
99115
}
100116

117+
@Test
118+
void testComplexExtratags() throws Exception {
119+
assertThatJson(readURL("/api?q=MyBusStop")).isObject()
120+
.node("features").isArray().hasSize(1)
121+
.element(0).isObject()
122+
.node("properties").isObject()
123+
.node("extra").isObject()
124+
.hasSize(5)
125+
.containsEntry("number", 56.7)
126+
.containsEntry("boolean", true)
127+
.containsEntry("object", Map.of("foo", "bar"))
128+
.containsEntry("string", "Foo")
129+
.node("array").isArray()
130+
.containsExactly(1, 2, 3);
131+
}
132+
101133
@Test
102134
void testApiStatus() throws Exception {
103135
assertThatJson(readURL("/status")).isObject()

src/test/java/de/komoot/photon/json/JsonReaderTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,29 @@ void testNullAddressIgnored() throws IOException {
400400

401401
}
402402

403+
@Test
404+
void testComplexExtraTags() throws IOException {
405+
configExtraTags = new ConfigExtraTags(List.of("ALL"));
406+
input.println(TEST_SIMPLE_STREAM.replace("\"boat\": \"no\"",
407+
"""
408+
"number": 56.7,
409+
"boolean": true,
410+
"array": [1, 2, 3],
411+
"object": {"foo": "bar"}
412+
"""));
413+
414+
var importer = readJson();
415+
416+
assertThat(importer).singleElement()
417+
.hasFieldOrPropertyWithValue("extratags", Map.of(
418+
"number", 56.7,
419+
"boolean", true,
420+
"array", List.of(1, 2, 3),
421+
"object", Map.of("foo", "bar")
422+
));
423+
}
424+
425+
403426
@Test
404427
void testNullExtraIgnored() throws IOException {
405428
configExtraTags = new ConfigExtraTags(List.of("ALL"));

0 commit comments

Comments
 (0)