1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 |
|
---|
6 | import java.time.Instant;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.BeforeEach;
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
11 | import org.openstreetmap.josm.data.osm.history.History;
|
---|
12 | import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
|
---|
13 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
14 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
15 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
16 | import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
|
---|
17 | import org.openstreetmap.josm.testutils.annotations.HTTP;
|
---|
18 |
|
---|
19 | import com.github.tomakehurst.wiremock.WireMockServer;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link OsmServerHistoryReader} class.
|
---|
23 | */
|
---|
24 | @BasicPreferences
|
---|
25 | @BasicWiremock
|
---|
26 | @HTTP
|
---|
27 | class OsmServerHistoryReaderTest {
|
---|
28 | /**
|
---|
29 | * HTTP mock.
|
---|
30 | */
|
---|
31 | @BasicWiremock
|
---|
32 | WireMockServer wireMockServer;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Setup tests.
|
---|
36 | */
|
---|
37 | @BeforeEach
|
---|
38 | void setUp() {
|
---|
39 | Config.getPref().put("osm-server.url", wireMockServer.url("/__files/api"));
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Tests node history fetching.
|
---|
44 | * @throws OsmTransferException if any error occurs
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | void testNode() throws OsmTransferException {
|
---|
48 | OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.NODE, 266187);
|
---|
49 | HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
|
---|
50 | History h = ds.getHistory(266187, OsmPrimitiveType.NODE);
|
---|
51 | assertEquals(5, h.getNumVersions());
|
---|
52 | assertEquals(1, h.getLatest().getNumKeys());
|
---|
53 | assertEquals(65565982, h.getLatest().getChangesetId());
|
---|
54 | assertEquals(Instant.ofEpochMilli(1545089885000L), h.getLatest().getInstant());
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Tests way history fetching.
|
---|
59 | * @throws OsmTransferException if any error occurs
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | void testWay() throws OsmTransferException {
|
---|
63 | OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.WAY, 3058844);
|
---|
64 | HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
|
---|
65 | History h = ds.getHistory(3058844, OsmPrimitiveType.WAY);
|
---|
66 | assertEquals(14, h.getNumVersions());
|
---|
67 | assertEquals(10, h.getLatest().getNumKeys());
|
---|
68 | assertEquals(26368284, h.getLatest().getChangesetId());
|
---|
69 | assertEquals(Instant.ofEpochMilli(1414429134000L), h.getLatest().getInstant());
|
---|
70 | assertEquals(11, h.getWhichChangedTag(h.getByVersion(14), "bicycle", false).getVersion());
|
---|
71 | assertEquals(1, h.getWhichChangedTag(h.getByVersion(10), "bicycle", false).getVersion());
|
---|
72 | assertEquals(5, h.getWhichChangedTag(h.getByVersion(14), "created_by", false).getVersion());
|
---|
73 | assertEquals(2, h.getWhichChangedTag(h.getByVersion(4), "created_by", false).getVersion());
|
---|
74 | assertEquals(1, h.getWhichChangedTag(h.getByVersion(1), "highway", false).getVersion());
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Tests relation history fetching.
|
---|
79 | * @throws OsmTransferException if any error occurs
|
---|
80 | */
|
---|
81 | @Test
|
---|
82 | void testRelation() throws OsmTransferException {
|
---|
83 | OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.RELATION, 49);
|
---|
84 | HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
|
---|
85 | History h = ds.getHistory(49, OsmPrimitiveType.RELATION);
|
---|
86 | assertEquals(3, h.getNumVersions());
|
---|
87 | assertEquals(0, h.getLatest().getNumKeys());
|
---|
88 | assertEquals(486501, h.getLatest().getChangesetId());
|
---|
89 | assertEquals(Instant.ofEpochMilli(1194886166000L), h.getLatest().getInstant());
|
---|
90 | }
|
---|
91 | }
|
---|