Ignore:
Timestamp:
2017-08-02T20:41:01+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15102 - first batch of HTTP unit tests mocking, using WireMock 2.7.1

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

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java

    r10378 r12557  
    22package org.openstreetmap.josm.gui;
    33
     4import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
     5import static com.github.tomakehurst.wiremock.client.WireMock.get;
     6import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
     7import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
    48import static org.junit.Assert.assertEquals;
    59
     
    1014import java.util.List;
    1115
    12 import org.junit.BeforeClass;
     16import org.junit.Rule;
    1317import org.junit.Test;
    14 import org.openstreetmap.josm.JOSMFixture;
    1518import org.openstreetmap.josm.TestUtils;
    1619import org.openstreetmap.josm.data.osm.DataSet;
     
    2427import org.openstreetmap.josm.io.IllegalDataException;
    2528import org.openstreetmap.josm.io.OsmReader;
     29import org.openstreetmap.josm.testutils.JOSMTestRules;
    2630import org.xml.sax.SAXException;
     31
     32import com.github.tomakehurst.wiremock.junit.WireMockRule;
    2733
    2834import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3440
    3541    /**
    36      * Setup tests
     42     * Setup test.
    3743     */
    38     @BeforeClass
    39     public static void setUpBeforeClass() {
    40         JOSMFixture.createUnitTestFixture().init();
    41     }
     44    @Rule
     45    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     46    public JOSMTestRules test = new JOSMTestRules().platform();
     47
     48    /**
     49     * HTTP mock.
     50     */
     51    @Rule
     52    public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
    4253
    4354    /**
     
    5061    @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY")
    5162    public void testTicket9632() throws IllegalDataException, IOException, SAXException {
    52         String source = "http://josm.openstreetmap.de/josmfile?page=Presets/BicycleJunction&preset";
    53         TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(source, true));
     63        String source = "presets/Presets_BicycleJunction-preset.xml";
     64        wireMockRule.stubFor(get(urlEqualTo("/" + source))
     65                .willReturn(aResponse()
     66                    .withStatus(200)
     67                    .withHeader("Content-Type", "text/xml")
     68                    .withBodyFile(source)));
     69        TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll("http://localhost:" + wireMockRule.port() + "/" + source, true));
    5470
    5571        Comparator<Relation> comparator = DefaultNameFormatter.getInstance().getRelationComparator();
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTest.java

    r10977 r12557  
    44import static org.junit.Assert.assertNotNull;
    55
     6import java.io.File;
     7import java.util.Arrays;
     8
    69import org.junit.Rule;
    710import org.junit.Test;
     11import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.TestUtils;
    813import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils;
    914import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2126    @Rule
    2227    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    23     public JOSMTestRules test = new JOSMTestRules().platform().commands();
     28    public JOSMTestRules test = new JOSMTestRules().platform().mainMenu();
    2429
    2530    /**
     
    3641    @Test
    3742    public void testAddGui() {
     43        String fileUrl = new File(TestUtils.getTestDataRoot()+"__files/imagery/maps.xml").toURI().toString();
     44        Main.pref.putCollection("imagery.layers.sites", Arrays.asList(fileUrl));
    3845        PreferencesTestUtils.doTestPreferenceSettingAddGui(new ImageryPreference.Factory(), null);
    3946    }
Note: See TracChangeset for help on using the changeset viewer.