Changeset 17332 in josm for trunk/test
- Timestamp:
- 2020-11-23T16:01:19+01:00 (4 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r17275 r17332 480 480 481 481 /** 482 * Return WireMock server serving files under ticke rdirectory482 * Return WireMock server serving files under ticket directory 483 483 * @param ticketId Ticket numeric identifier 484 484 * @return WireMock HTTP server on dynamic port … … 493 493 494 494 /** 495 * Return WireMock server serving files under ticker directory495 * Return WireMock server 496 496 * @return WireMock HTTP server on dynamic port 497 497 */ … … 499 499 return new WireMockServer( 500 500 WireMockConfiguration.options() 501 .withRootDirectory("test/data") 501 502 .dynamicPort() 502 503 ); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java
r17275 r17332 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 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; 4 7 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 8 import static org.junit.jupiter.api.Assertions.assertEquals; 6 9 import static org.junit.jupiter.api.Assertions.assertThrows; 7 10 11 import org.junit.jupiter.api.Test; 8 12 import org.junit.jupiter.api.extension.RegisterExtension; 9 import org. junit.jupiter.api.Test;13 import org.openstreetmap.josm.TestUtils; 10 14 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 15 import org.openstreetmap.josm.spi.preferences.Config; 11 16 import org.openstreetmap.josm.testutils.JOSMTestRules; 17 18 import com.github.tomakehurst.wiremock.WireMockServer; 12 19 13 20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 36 43 @Test 37 44 void testBadRequestNoParam() { 38 assertDoesNotThrow(() -> newHandler(null).handle()); 45 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 46 assertEquals("No valid object identifier has been provided", e.getMessage()); 39 47 } 40 48 … … 62 70 @Test 63 71 void testNominalRequest() { 64 assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle()); 72 WireMockServer wiremock = TestUtils.getWireMockServer(); 73 wiremock.addStubMapping(get(urlEqualTo("/capabilities")).willReturn(aResponse().withStatusMessage("OK") 74 .withBodyFile("api/capabilities")).build()); 75 String w1 = "<way id=\"1\" version=\"1\"><nd ref=\"1\"/><nd ref=\"2\"/></way>"; 76 String n1 = "<node id=\"1\" version=\"1\"/>"; 77 String n2 = "<node id=\"2\" version=\"1\"/>"; 78 wiremock.addStubMapping(get(urlEqualTo("/0.6/ways?ways=1")).willReturn(aResponse().withStatusMessage("OK") 79 .withBody(osm(w1))).build()); 80 wiremock.addStubMapping(get(urlEqualTo("/0.6/nodes?nodes=1,2")).willReturn(aResponse().withStatusMessage("OK") 81 .withBody(osm(n1 + n2))).build()); 82 wiremock.addStubMapping(get(urlEqualTo("/0.6/way/1/full")).willReturn(aResponse().withStatusMessage("OK") 83 .withBody(osm(n1 + n2 + w1))).build()); 84 wiremock.start(); 85 Config.getPref().put("osm-server.url", wiremock.baseUrl()); 86 try { 87 assertDoesNotThrow(() -> newHandler("https://localhost?objects=n1,w1").handle()); 88 } finally { 89 wiremock.stop(); 90 } 91 } 92 93 private static String osm(String xml) { 94 return "<osm version=\"0.6\">" + xml + "</osm>"; 65 95 } 66 96 }
Note:
See TracChangeset
for help on using the changeset viewer.