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