Changeset 18106 in josm for trunk/test/functional/org


Ignore:
Timestamp:
2021-08-01T21:21:38+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21150 - Add JUnit5 annotation for WireMockServer (patch by taylor.smock)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r17211 r18106  
    1616import static org.hamcrest.MatcherAssert.assertThat;
    1717import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
    18 import static org.junit.Assert.assertEquals;
    19 import static org.junit.Assert.assertTrue;
     18import static org.junit.jupiter.api.Assertions.assertEquals;
     19import static org.junit.jupiter.api.Assertions.assertThrows;
     20import static org.junit.jupiter.api.Assertions.assertTrue;
    2021
    2122import java.io.BufferedReader;
     
    3435import java.util.stream.Collectors;
    3536
    36 import org.junit.Before;
    37 import org.junit.Rule;
    38 import org.junit.Test;
     37import org.junit.jupiter.api.BeforeEach;
     38import org.junit.jupiter.api.Test;
     39import org.junit.jupiter.api.Timeout;
    3940import org.openstreetmap.josm.TestUtils;
    4041import org.openstreetmap.josm.data.Version;
    4142import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    42 import org.openstreetmap.josm.testutils.JOSMTestRules;
     43import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     44import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     45import org.openstreetmap.josm.testutils.annotations.HTTP;
    4346import org.openstreetmap.josm.tools.HttpClient.Response;
    4447
    45 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
     48import com.github.tomakehurst.wiremock.WireMockServer;
    4649import com.github.tomakehurst.wiremock.http.HttpHeader;
    4750import com.github.tomakehurst.wiremock.http.HttpHeaders;
    48 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    4951import com.github.tomakehurst.wiremock.matching.UrlPattern;
    50 
    51 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    5252
    5353/**
    5454 * Tests the {@link HttpClient}.
    5555 */
    56 public class HttpClientTest {
    57 
    58     /**
    59      * Setup test
    60      */
    61     @Rule
    62     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    63     public JOSMTestRules test = new JOSMTestRules().preferences().timeout(15000);
    64 
     56@HTTP
     57@BasicWiremock
     58@BasicPreferences
     59@Timeout(15)
     60class HttpClientTest {
    6561    /**
    6662     * mocked local http server
    6763     */
    68     @Rule
    69     public WireMockRule localServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
     64    @BasicWiremock
     65    public WireMockServer localServer;
    7066
    7167    private ProgressMonitor progress;
     
    9187     * Setup test.
    9288     */
    93     @Before
     89    @BeforeEach
    9490    public void setUp() {
    9591        localServer.resetAll();
     
    105101     */
    106102    @Test
    107     public void testConstructorGetterSetter() throws IOException {
     103    void testConstructorGetterSetter() throws IOException {
    108104        final URL localUrl = url("");
    109105        final HttpClient client = HttpClient.create(localUrl);
     
    127123     */
    128124    @Test
    129     public void testGet() throws IOException {
     125    void testGet() throws IOException {
    130126        final UrlPattern pattern = urlEqualTo("/get?foo=bar");
    131127        localServer.stubFor(get(pattern).willReturn(aResponse().withStatusMessage("OK")
     
    151147     */
    152148    @Test
    153     public void testHeaders() throws IOException {
     149    void testHeaders() throws IOException {
    154150        final UrlPattern pattern = urlEqualTo("/headers");
    155151        localServer.stubFor(get(pattern).willReturn(aResponse()));
     
    166162     */
    167163    @Test
    168     public void testFetchUtf8Content() throws IOException {
     164    void testFetchUtf8Content() throws IOException {
    169165        localServer.stubFor(get(urlEqualTo("/encoding/utf8"))
    170166                .willReturn(aResponse().withBody("∀x∈ℝ: UTF-8 encoded sample plain-text file")));
     
    181177     */
    182178    @Test
    183     public void testPost() throws IOException {
     179    void testPost() throws IOException {
    184180        final UrlPattern pattern = urlEqualTo("/post");
    185181        localServer.stubFor(post(pattern).willReturn(aResponse()));
     
    200196     */
    201197    @Test
    202     public void testPostZero() throws IOException {
     198    void testPostZero() throws IOException {
    203199        final UrlPattern pattern = urlEqualTo("/post");
    204200        localServer.stubFor(post(pattern).willReturn(aResponse()));
     
    215211
    216212    @Test
    217     public void testRelativeRedirects() throws IOException {
     213    void testRelativeRedirects() throws IOException {
    218214        mockRedirects(false, 3);
    219215        final Response response = connect("/relative-redirect/3");
     
    223219
    224220    @Test
    225     public void testAbsoluteRedirects() throws IOException {
     221    void testAbsoluteRedirects() throws IOException {
    226222        mockRedirects(true, 3);
    227223        final Response response = connect("/absolute-redirect/3");
     
    234230     * @throws IOException if an I/O error occurs
    235231     */
    236     @Test(expected = IOException.class)
    237     public void testTooMuchRedirects() throws IOException {
     232    @Test
     233    void testTooMuchRedirects() throws IOException {
    238234        mockRedirects(false, 3);
    239         HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2).connect(progress);
     235        assertThrows(IOException.class, () -> HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2).connect(progress));
    240236    }
    241237
     
    245241     */
    246242    @Test
    247     public void testHttp418() throws IOException {
     243    void testHttp418() throws IOException {
    248244        // https://tools.ietf.org/html/rfc2324
    249245        final Response response = doTestHttp(418, "I'm a teapot!", "I'm a teapot!",
     
    257253     */
    258254    @Test
    259     public void testHttp401() throws IOException {
     255    void testHttp401() throws IOException {
    260256        // https://tools.ietf.org/html/rfc2324
    261257        doTestHttp(401, "UNAUTHORIZED", null);
     
    267263     */
    268264    @Test
    269     public void testHttp402() throws IOException {
     265    void testHttp402() throws IOException {
    270266        // https://tools.ietf.org/html/rfc2324
    271267        doTestHttp(402, "PAYMENT REQUIRED", "Fuck you, pay me!");
     
    277273     */
    278274    @Test
    279     public void testHttp403() throws IOException {
     275    void testHttp403() throws IOException {
    280276        // https://tools.ietf.org/html/rfc2324
    281277        doTestHttp(403, "FORBIDDEN", null);
     
    287283     */
    288284    @Test
    289     public void testHttp404() throws IOException {
     285    void testHttp404() throws IOException {
    290286        // https://tools.ietf.org/html/rfc2324
    291287        doTestHttp(404, "NOT FOUND", null);
     
    297293     */
    298294    @Test
    299     public void testHttp500() throws IOException {
     295    void testHttp500() throws IOException {
    300296        // https://tools.ietf.org/html/rfc2324
    301297        doTestHttp(500, "INTERNAL SERVER ERROR", null);
     
    307303     */
    308304    @Test
    309     public void testRequestInTime() throws IOException {
     305    void testRequestInTime() throws IOException {
    310306        mockDelay(1);
    311307        final Response response = HttpClient.create(url("/delay/1")).setReadTimeout(2000).connect(progress);
     
    317313     * @throws IOException always
    318314     */
    319     @Test(expected = IOException.class)
    320     public void testTakesTooLong() throws IOException {
     315    @Test
     316    void testTakesTooLong() throws IOException {
    321317        mockDelay(1);
    322         HttpClient.create(url("/delay/1")).setReadTimeout(500).connect(progress);
     318        assertThrows(IOException.class, () -> HttpClient.create(url("/delay/1")).setReadTimeout(500).connect(progress));
    323319    }
    324320
     
    328324     */
    329325    @Test
    330     public void testGzip() throws IOException {
     326    void testGzip() throws IOException {
    331327        localServer.stubFor(get(urlEqualTo("/gzip")).willReturn(aResponse().withBody("foo")));
    332328        final Response response = connect("/gzip");
     
    341337     */
    342338    @Test
    343     public void testOpenUrlGzip() throws IOException {
     339    void testOpenUrlGzip() throws IOException {
    344340        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.gz");
    345341        final byte[] gpx = Files.readAllBytes(path);
     
    361357     */
    362358    @Test
    363     public void testOpenUrlBzip() throws IOException {
     359    void testOpenUrlBzip() throws IOException {
    364360        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2");
    365361        final byte[] gpx = Files.readAllBytes(path);
     
    381377     */
    382378    @Test
    383     public void testOpenUrlBzipAccordingToContentDisposition() throws IOException {
     379    void testOpenUrlBzipAccordingToContentDisposition() throws IOException {
    384380        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2");
    385381        final byte[] gpx = Files.readAllBytes(path);
     
    402398     */
    403399    @Test
    404     public void testTomcatErrorMessage() {
     400    void testTomcatErrorMessage() {
    405401        Matcher m = HttpClient.getTomcatErrorMatcher(
    406402            "<html><head><title>Apache Tomcat/DGFiP - Rapport d''erreur</title><style><!--"+
Note: See TracChangeset for help on using the changeset viewer.