Changeset 17189 in josm


Ignore:
Timestamp:
2020-10-13T20:40:32+02:00 (4 years ago)
Author:
simon04
Message:

see #15102 - see #16637 - get rid of real HTTP calls to https://josm.openstreetmap.de/josmticket in unit tests, mock them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportSenderTest.java

    r10067 r17189  
    22package org.openstreetmap.josm.tools.bugreport;
    33
     4import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
     5import static com.github.tomakehurst.wiremock.client.WireMock.containing;
     6import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
     7import static com.github.tomakehurst.wiremock.client.WireMock.post;
     8import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
     9import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
     10import static com.github.tomakehurst.wiremock.client.WireMock.verify;
     11import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
     12import static org.junit.Assert.assertEquals;
    413import static org.junit.Assert.assertFalse;
    514import static org.junit.Assert.assertNotNull;
    615import static org.junit.Assert.assertNull;
    716
     17import java.net.URI;
     18import java.util.List;
     19
    820import org.junit.Before;
     21import org.junit.Rule;
    922import org.junit.Test;
    1023import org.openstreetmap.josm.JOSMFixture;
    1124import org.openstreetmap.josm.actions.ShowStatusReportAction;
     25import org.openstreetmap.josm.spi.preferences.Config;
     26import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker;
     27
     28import com.github.tomakehurst.wiremock.junit.WireMockRule;
    1229
    1330/**
     
    2542
    2643    /**
     44     * HTTP mock.
     45     */
     46    @Rule
     47    public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
     48
     49    /**
    2750     * Unit test for {@link BugReportSender#BugReportSender}.
    2851     * @throws InterruptedException if the thread is interrupted
     
    3053    @Test
    3154    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
    3266        BugReportSender sender = BugReportSender.reportBug(ShowStatusReportAction.getReportHeader());
    3367        assertNotNull(sender);
     
    3771            }
    3872        }
     73
    3974        assertFalse(sender.isAlive());
    4075        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());
    4181    }
    4282}
Note: See TracChangeset for help on using the changeset viewer.