Ignore:
Timestamp:
2020-10-13T22:07:11+02:00 (4 years ago)
Author:
simon04
Message:

see #15102 - see #16637 - get rid of real HTTP calls to https://api.openstreetmap.org in OsmServerHistoryReaderTest, mock them

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java

    r17192 r17194  
    5858    @Test
    5959    public void testNominalUrl() {
    60         ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/osm_api"));
     60        ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/api"));
    6161        task.run();
    6262        assertTrue(task.isSuccess());
  • trunk/test/unit/org/openstreetmap/josm/io/CapabilitiesTest.java

    r17193 r17194  
    2424    public void testCapabilities() throws Exception {
    2525        final Capabilities capabilities;
    26         try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("__files/osm_api/0.6/capabilities")) {
     26        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("__files/api/0.6/capabilities")) {
    2727            capabilities = Capabilities.CapabilitiesParser.parse(new InputSource(inputStream));
    2828        }
  • trunk/test/unit/org/openstreetmap/josm/io/OsmServerHistoryReaderTest.java

    r17193 r17194  
    22package org.openstreetmap.josm.io;
    33
    4 import static org.junit.Assert.assertTrue;
     4import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
     5import static org.junit.Assert.assertEquals;
    56
    6 import org.junit.BeforeClass;
     7import org.junit.Before;
     8import org.junit.Rule;
    79import org.junit.Test;
    810import org.openstreetmap.josm.JOSMFixture;
     11import org.openstreetmap.josm.TestUtils;
    912import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1013import org.openstreetmap.josm.data.osm.history.History;
     
    1316import org.openstreetmap.josm.spi.preferences.Config;
    1417
     18import com.github.tomakehurst.wiremock.junit.WireMockRule;
     19
    1520/**
    16  * History fetching tests. This test operates with production API.
     21 * Unit tests of {@link OsmServerHistoryReader} class.
    1722 */
    1823public class OsmServerHistoryReaderTest {
    1924
    2025    /**
     26     * HTTP mock.
     27     */
     28    @Rule
     29    public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
     30
     31    /**
    2132     * Setup tests.
    2233     */
    23     @BeforeClass
    24     public static void init() {
     34    @Before
     35    public void setUp() {
    2536        JOSMFixture.createUnitTestFixture().init();
    26         Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl());
     37        Config.getPref().put("osm-server.url", wireMockRule.url("/__files/api"));
    2738    }
    2839
     
    3647        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
    3748        History h = ds.getHistory(266187, OsmPrimitiveType.NODE);
    38         assertTrue("NumVersions", h.getNumVersions() >= 4);
     49        assertEquals(5, h.getNumVersions());
     50        assertEquals(1, h.getLatest().getNumKeys());
     51        assertEquals(65565982, h.getLatest().getChangesetId());
     52        assertEquals(1545089885000L, h.getLatest().getTimestamp().getTime());
    3953    }
    4054
     
    4862        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
    4963        History h = ds.getHistory(3058844, OsmPrimitiveType.WAY);
    50         assertTrue("NumVersions", h.getNumVersions() >= 13);
     64        assertEquals(14, h.getNumVersions());
     65        assertEquals(10, h.getLatest().getNumKeys());
     66        assertEquals(26368284, h.getLatest().getChangesetId());
     67        assertEquals(1414429134000L, h.getLatest().getTimestamp().getTime());
    5168    }
    5269
     
    6077        HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
    6178        History h = ds.getHistory(49, OsmPrimitiveType.RELATION);
    62         assertTrue("NumVersions", h.getNumVersions() >= 3);
     79        assertEquals(3, h.getNumVersions());
     80        assertEquals(0, h.getLatest().getNumKeys());
     81        assertEquals(486501, h.getLatest().getChangesetId());
     82        assertEquals(1194886166000L, h.getLatest().getTimestamp().getTime());
    6383    }
    6484}
Note: See TracChangeset for help on using the changeset viewer.