Changeset 17189 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2020-10-13T20:40:32+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportSenderTest.java
r10067 r17189 2 2 package org.openstreetmap.josm.tools.bugreport; 3 3 4 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 5 import static com.github.tomakehurst.wiremock.client.WireMock.containing; 6 import static com.github.tomakehurst.wiremock.client.WireMock.exactly; 7 import static com.github.tomakehurst.wiremock.client.WireMock.post; 8 import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; 9 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 10 import static com.github.tomakehurst.wiremock.client.WireMock.verify; 11 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 12 import static org.junit.Assert.assertEquals; 4 13 import static org.junit.Assert.assertFalse; 5 14 import static org.junit.Assert.assertNotNull; 6 15 import static org.junit.Assert.assertNull; 7 16 17 import java.net.URI; 18 import java.util.List; 19 8 20 import org.junit.Before; 21 import org.junit.Rule; 9 22 import org.junit.Test; 10 23 import org.openstreetmap.josm.JOSMFixture; 11 24 import org.openstreetmap.josm.actions.ShowStatusReportAction; 25 import org.openstreetmap.josm.spi.preferences.Config; 26 import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker; 27 28 import com.github.tomakehurst.wiremock.junit.WireMockRule; 12 29 13 30 /** … … 25 42 26 43 /** 44 * HTTP mock. 45 */ 46 @Rule 47 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); 48 49 /** 27 50 * Unit test for {@link BugReportSender#BugReportSender}. 28 51 * @throws InterruptedException if the thread is interrupted … … 30 53 @Test 31 54 public void testBugReportSender() throws InterruptedException { 55 Config.getPref().put("josm.url", wireMockRule.baseUrl()); 56 wireMockRule.stubFor(post(urlEqualTo("/josmticket")) 57 .willReturn(aResponse() 58 .withStatus(200) 59 .withHeader("Content-Type", "text/xml") 60 .withBody("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 61 "<josmticket status=\"ok\">\n" + 62 " <preparedid>6bccff5c0417217bfbbe5fff</preparedid>\n" + 63 "</josmticket>\n"))); 64 new OpenBrowserMocker(); 65 32 66 BugReportSender sender = BugReportSender.reportBug(ShowStatusReportAction.getReportHeader()); 33 67 assertNotNull(sender); … … 37 71 } 38 72 } 73 39 74 assertFalse(sender.isAlive()); 40 75 assertNull(sender.getErrorMessage(), sender.getErrorMessage()); 76 verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata="))); 77 78 List<URI> calledURIs = OpenBrowserMocker.getCalledURIs(); 79 assertEquals(1, calledURIs.size()); 80 assertEquals(wireMockRule.baseUrl() + "/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff", calledURIs.get(0).toString()); 41 81 } 42 82 }
Note:
See TracChangeset
for help on using the changeset viewer.