Changeset 12557 in josm
- Timestamp:
- 2017-08-02T20:41:01+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 16 added
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r12503 r12557 22 22 <classpathentry kind="lib" path="test/lib/unitils-core/unitils-core-3.4.6.jar"/> 23 23 <classpathentry kind="lib" path="test/lib/commons-testing/commons-testing-2.1.0.jar"/> 24 <classpathentry kind="lib" path="test/lib/wiremock-standalone-2.7.1.jar"/> 24 25 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 25 26 <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/> -
trunk/netbeans/nbproject/project.properties
r12516 r12557 58 58 file.reference.unitils-core-3.4.6.jar=../test/lib/unitils-core/unitils-core-3.4.6.jar 59 59 file.reference.system-rules-1.16.1.jar=../test/lib/system-rules-1.16.1.jar 60 file.reference.wiremock-standalone-2.7.1.jar=../test/lib/wiremock-standalone-2.7.1.jar 60 61 includes=**/*.java 61 62 jar.compress=false … … 91 92 ${file.reference.unitils-core-3.4.6.jar}:\ 92 93 ${file.reference.system-rules-1.16.1.jar}:\ 94 ${file.reference.wiremock-standalone-2.7.1.jar}:\ 93 95 ${file.reference.findbugs.jar}:\ 94 96 ${file.reference.commons-testing-2.1.0.jar} -
trunk/src/org/openstreetmap/josm/io/NameFinder.java
r11746 r12557 18 18 import org.openstreetmap.josm.data.osm.PrimitiveId; 19 19 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 20 import org.openstreetmap.josm.data.preferences.StringProperty; 20 21 import org.openstreetmap.josm.tools.HttpClient; 22 import org.openstreetmap.josm.tools.HttpClient.Response; 21 23 import org.openstreetmap.josm.tools.OsmUrlToBounds; 22 24 import org.openstreetmap.josm.tools.UncheckedParseException; … … 34 36 35 37 /** 36 * Nominatim URL.38 * Nominatim default URL. 37 39 */ 38 40 public static final String NOMINATIM_URL = "https://nominatim.openstreetmap.org/search?format=xml&q="; 41 42 /** 43 * Nominatim URL property. 44 * @since xxx 45 */ 46 public static final StringProperty NOMINATIM_URL_PROP = new StringProperty("nominatim-url", NOMINATIM_URL); 39 47 40 48 private NameFinder() { … … 48 56 */ 49 57 public static List<SearchResult> queryNominatim(final String searchExpression) throws IOException { 50 return query(new URL(NOMINATIM_URL + Utils.encodeUrl(searchExpression)));58 return query(new URL(NOMINATIM_URL_PROP.get() + Utils.encodeUrl(searchExpression))); 51 59 } 52 60 … … 59 67 public static List<SearchResult> query(final URL url) throws IOException { 60 68 final HttpClient connection = HttpClient.create(url); 61 connection.connect(); 62 try (Reader reader = connection.getResponse().getContentReader()) { 69 Response response = connection.connect(); 70 if (response.getResponseCode() >= 400) { 71 throw new IOException(response.getResponseMessage() + ": " + response.fetchContent()); 72 } 73 try (Reader reader = response.getContentReader()) { 63 74 return parseSearchResults(reader); 64 75 } catch (ParserConfigurationException | SAXException ex) { -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r12475 r12557 30 30 import org.openstreetmap.josm.data.projection.Projections; 31 31 import org.openstreetmap.josm.tools.HttpClient; 32 import org.openstreetmap.josm.tools.HttpClient.Response; 32 33 import org.openstreetmap.josm.tools.Utils; 33 34 import org.w3c.dom.Document; … … 226 227 } 227 228 228 final String incomingData = HttpClient.create(getCapabilitiesUrl).connect().fetchContent(); 229 final Response response = HttpClient.create(getCapabilitiesUrl).connect(); 230 final String incomingData = response.fetchContent(); 229 231 Main.debug("Server response to Capabilities request:"); 230 232 Main.debug(incomingData); 233 234 if (response.getResponseCode() >= 400) { 235 throw new WMSGetCapabilitiesException(response.getResponseMessage(), incomingData); 236 } 231 237 232 238 try { -
trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java
r12444 r12557 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 4 8 import static org.junit.Assert.assertEquals; 5 9 import static org.junit.Assert.assertTrue; … … 10 14 import org.junit.Test; 11 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.TestUtils; 12 17 import org.openstreetmap.josm.data.imagery.ImageryInfo; 13 18 import org.openstreetmap.josm.gui.layer.TMSLayer; 19 import org.openstreetmap.josm.gui.layer.WMSLayer; 14 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 22 import com.github.tomakehurst.wiremock.junit.WireMockRule; 15 23 16 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 30 38 31 39 /** 40 * HTTP mock. 41 */ 42 @Rule 43 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())); 44 45 /** 32 46 * Unit test of {@link AddImageryLayerAction#updateEnabledState}. 33 47 */ … … 45 59 */ 46 60 @Test 47 public void testActionPerformedEnabled () {61 public void testActionPerformedEnabledTms() { 48 62 assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty()); 49 63 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null); … … 51 65 assertEquals(1, tmsLayers.size()); 52 66 Main.getLayerManager().removeLayer(tmsLayers.get(0)); 67 } 68 69 /** 70 * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases for WMS. 71 */ 72 @Test 73 public void testActionPerformedEnabledWms() { 74 wireMockRule.stubFor(get(urlEqualTo("/wms?VERSION=1.1.1&SERVICE=WMS&REQUEST=GetCapabilities")) 75 .willReturn(aResponse() 76 .withStatus(200) 77 .withHeader("Content-Type", "text/xml") 78 .withBodyFile("imagery/wms-capabilities.xml"))); 79 new AddImageryLayerAction(new ImageryInfo("localhost", "http://localhost:" + wireMockRule.port() + "/wms?", 80 "wms_endpoint", null, null)).actionPerformed(null); 81 List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class); 82 assertEquals(1, wmsLayers.size()); 83 84 Main.getLayerManager().removeLayer(wmsLayers.get(0)); 53 85 } 54 86 -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java
r12248 r12557 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit.Rule;11 10 import org.junit.Test; 12 11 import org.openstreetmap.josm.data.gpx.GpxData; 13 import org.openstreetmap.josm.testutils.JOSMTestRules;14 15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;16 12 17 13 /** 18 14 * Unit tests for class {@link DownloadGpsTask}. 19 15 */ 20 public class DownloadGpsTaskTest { 21 22 private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/data_nodist/munich.gpx"; 23 24 /** 25 * Setup test. 26 */ 27 @Rule 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 29 public JOSMTestRules test = new JOSMTestRules().https(); 16 public class DownloadGpsTaskTest extends AbstractDownloadTaskTest { 30 17 31 18 /** … … 45 32 assertTrue(task.acceptsUrl("https://www.openstreetmap.org/edit?gpx=750057")); 46 33 assertTrue(task.acceptsUrl("http://www.openstreetmap.org/edit?gpx=2277313#map=14/-20.7321/-40.5328")); 47 assertTrue(task.acceptsUrl( REMOTE_FILE));34 assertTrue(task.acceptsUrl(getRemoteFileUrl())); 48 35 } 49 36 … … 55 42 @Test 56 43 public void testDownloadExternalFile() throws InterruptedException, ExecutionException { 44 mockHttp(); 57 45 DownloadGpsTask task = new DownloadGpsTask(); 58 task.loadUrl(false, REMOTE_FILE, null).get();46 task.loadUrl(false, getRemoteFileUrl(), null).get(); 59 47 GpxData data = task.getDownloadedData(); 60 48 assertNotNull(data); … … 62 50 assertFalse(data.tracks.isEmpty()); 63 51 } 52 53 @Override 54 protected String getRemoteFile() { 55 return "samples/data.gpx"; 56 } 64 57 } -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTaskTest.java
r12248 r12557 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit.Rule;11 10 import org.junit.Test; 12 11 import org.openstreetmap.josm.data.osm.NoteData; 13 import org.openstreetmap.josm.testutils.JOSMTestRules;14 15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;16 12 17 13 /** 18 14 * Unit tests for class {@link DownloadNotesTask}. 19 15 */ 20 public class DownloadNotesTaskTest { 21 22 private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/test/data/planet-notes-extract.osn"; 23 24 /** 25 * Setup test. 26 */ 27 @Rule 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 29 public JOSMTestRules test = new JOSMTestRules().platform().https(); 16 public class DownloadNotesTaskTest extends AbstractDownloadTaskTest { 30 17 31 18 /** … … 41 28 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.xml?bbox=-0.65094,51.312159,0.374908,51.669148")); 42 29 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.gpx?bbox=-0.65094,51.312159,0.374908,51.669148")); 43 assertTrue(task.acceptsUrl( REMOTE_FILE));30 assertTrue(task.acceptsUrl(getRemoteFileUrl())); 44 31 } 45 32 … … 51 38 @Test 52 39 public void testDownloadExternalFile() throws InterruptedException, ExecutionException { 40 mockHttp(); 53 41 DownloadNotesTask task = new DownloadNotesTask(); 54 task.loadUrl(false, REMOTE_FILE, null).get();42 task.loadUrl(false, getRemoteFileUrl(), null).get(); 55 43 NoteData data = task.getDownloadedData(); 56 44 assertNotNull(data); 57 45 assertFalse(data.getNotes().isEmpty()); 58 46 } 47 48 @Override 49 protected String getRemoteFile() { 50 return "samples/data.osn"; 51 } 59 52 } -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java
r12248 r12557 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit.Rule;11 10 import org.junit.Test; 12 11 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.testutils.JOSMTestRules;14 15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;16 12 17 13 /** 18 14 * Unit tests for class {@link DownloadOsmTask}. 19 15 */ 20 public class DownloadOsmTaskTest { 21 22 private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/data_nodist/direction-arrows.osm"; 23 24 /** 25 * Setup test. 26 */ 27 @Rule 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 29 public JOSMTestRules test = new JOSMTestRules().https(); 16 public class DownloadOsmTaskTest extends AbstractDownloadTaskTest { 30 17 31 18 /** … … 43 30 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/ways?ways=101,102,103")); 44 31 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relations?relations=101,102,103")); 45 assertTrue(task.acceptsUrl( REMOTE_FILE));32 assertTrue(task.acceptsUrl(getRemoteFileUrl())); 46 33 } 47 34 … … 53 40 @Test 54 41 public void testDownloadExternalFile() throws InterruptedException, ExecutionException { 42 mockHttp(); 55 43 DownloadOsmTask task = new DownloadOsmTask(); 56 task.loadUrl(false, REMOTE_FILE, null).get();44 task.loadUrl(false, getRemoteFileUrl(), null).get(); 57 45 DataSet ds = task.getDownloadedData(); 58 46 assertNotNull(ds); … … 60 48 assertFalse(ds.getWays().isEmpty()); 61 49 } 50 51 @Override 52 protected String getRemoteFile() { 53 return "samples/data.osm"; 54 } 62 55 } -
trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java
r10378 r12557 2 2 package org.openstreetmap.josm.gui; 3 3 4 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 4 8 import static org.junit.Assert.assertEquals; 5 9 … … 10 14 import java.util.List; 11 15 12 import org.junit. BeforeClass;16 import org.junit.Rule; 13 17 import org.junit.Test; 14 import org.openstreetmap.josm.JOSMFixture;15 18 import org.openstreetmap.josm.TestUtils; 16 19 import org.openstreetmap.josm.data.osm.DataSet; … … 24 27 import org.openstreetmap.josm.io.IllegalDataException; 25 28 import org.openstreetmap.josm.io.OsmReader; 29 import org.openstreetmap.josm.testutils.JOSMTestRules; 26 30 import org.xml.sax.SAXException; 31 32 import com.github.tomakehurst.wiremock.junit.WireMockRule; 27 33 28 34 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 34 40 35 41 /** 36 * Setup test s42 * Setup test. 37 43 */ 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())); 42 53 43 54 /** … … 50 61 @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY") 51 62 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)); 54 70 55 71 Comparator<Relation> comparator = DefaultNameFormatter.getInstance().getRelationComparator(); -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTest.java
r10977 r12557 4 4 import static org.junit.Assert.assertNotNull; 5 5 6 import java.io.File; 7 import java.util.Arrays; 8 6 9 import org.junit.Rule; 7 10 import org.junit.Test; 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.TestUtils; 8 13 import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils; 9 14 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 21 26 @Rule 22 27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules test = new JOSMTestRules().platform(). commands();28 public JOSMTestRules test = new JOSMTestRules().platform().mainMenu(); 24 29 25 30 /** … … 36 41 @Test 37 42 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)); 38 45 PreferencesTestUtils.doTestPreferenceSettingAddGui(new ImageryPreference.Factory(), null); 39 46 } -
trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java
r11917 r12557 2 2 package org.openstreetmap.josm.io; 3 3 4 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 4 8 import static org.junit.Assert.assertEquals; 5 9 import static org.junit.Assert.assertTrue; … … 7 11 import java.util.regex.Matcher; 8 12 13 import org.junit.Before; 9 14 import org.junit.Rule; 10 15 import org.junit.Test; 16 import org.openstreetmap.josm.TestUtils; 11 17 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.gui.preferences.server.OverpassServerPreference;13 18 import org.openstreetmap.josm.io.OverpassDownloadReader.OverpassOutpoutFormat; 14 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 15 20 import org.openstreetmap.josm.tools.OverpassTurboQueryWizard; 16 21 import org.openstreetmap.josm.tools.Utils; 22 23 import com.github.tomakehurst.wiremock.junit.WireMockRule; 17 24 18 25 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 28 35 @Rule 29 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 30 public JOSMTestRules test = new JOSMTestRules().timeout(15000); 37 public JOSMTestRules test = new JOSMTestRules().preferences(); 38 39 /** 40 * HTTP mock. 41 */ 42 @Rule 43 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())); 44 45 private static final String NOMINATIM_URL_PATH = "/search?format=xml&q="; 46 47 /** 48 * Setup test. 49 */ 50 @Before 51 public void setUp() { 52 NameFinder.NOMINATIM_URL_PROP.put("http://localhost:" + wireMockRule.port() + NOMINATIM_URL_PATH); 53 } 31 54 32 55 private String getExpandedQuery(String search) { 33 56 final String query = OverpassTurboQueryWizard.getInstance().constructQuery(search); 34 final String request = new OverpassDownloadReader(new Bounds(1, 2, 3, 4), OverpassServerPreference.getOverpassServer(), query)57 final String request = new OverpassDownloadReader(new Bounds(1, 2, 3, 4), null, query) 35 58 .getRequestForBbox(1, 2, 3, 4) 36 59 .substring("interpreter?data=".length()); … … 55 78 } 56 79 80 private void stubNominatim(String query) { 81 wireMockRule.stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query)) 82 .willReturn(aResponse() 83 .withStatus(200) 84 .withHeader("Content-Type", "text/xml") 85 .withBodyFile("nominatim/" + query + ".xml"))); 86 } 87 57 88 /** 58 89 * Tests evaluating the extended query feature {@code geocodeArea}. … … 60 91 @Test 61 92 public void testGeocodeArea() { 93 stubNominatim("London"); 62 94 final String query = getExpandedQuery("amenity=drinking_water in London"); 63 95 assertEquals("" + … … 78 110 @Test 79 111 public void testGeocodeUnknownArea() { 112 stubNominatim("foo-bar-baz-does-not-exist"); 80 113 final String query = OverpassDownloadReader.expandExtendedQueries("{{geocodeArea:foo-bar-baz-does-not-exist}}"); 81 114 assertEquals("// Failed to evaluate {{geocodeArea:foo-bar-baz-does-not-exist}}\n", query); -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r12556 r12557 17 17 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 18 18 import org.openstreetmap.josm.data.projection.Projections; 19 import org.openstreetmap.josm.gui.MainApplication; 20 import org.openstreetmap.josm.gui.MainMenu; 19 21 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 20 22 import org.openstreetmap.josm.gui.util.GuiHelper; … … 55 57 private boolean territories; 56 58 private boolean rlTraffic; 59 private boolean main; 60 private boolean mainMenu; 57 61 58 62 /** … … 205 209 public JOSMTestRules rlTraffic() { 206 210 rlTraffic = true; 211 return this; 212 } 213 214 /** 215 * Use the {@link Main#main} application in this test. 216 * @return this instance, for easy chaining 217 * @since xxx 218 */ 219 public JOSMTestRules main() { 220 main = true; 221 return this; 222 } 223 224 /** 225 * Use the {@link Main#menu} in this test. 226 * @return this instance, for easy chaining 227 * @since xxx 228 */ 229 public JOSMTestRules mainMenu() { 230 main(); 231 mainMenu = true; 207 232 return this; 208 233 } … … 311 336 // TODO: Implement a more selective version of this once Main is restructured. 312 337 JOSMFixture.createUnitTestFixture().init(true); 338 } else { 339 if (main) { 340 new MainApplication(); 341 } 342 343 if (mainMenu) { 344 JOSMFixture.initContentPane(); 345 JOSMFixture.initToolbar(); 346 Main.main.menu = new MainMenu(); 347 } 313 348 } 314 349 }
Note:
See TracChangeset
for help on using the changeset viewer.