Ignore:
Timestamp:
2020-11-23T16:01:19+01:00 (10 months ago)
Author:
Don-vip
Message:

fix #20131 - fix unit tests and codestyle violations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java

    r17275 r17332  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
     5import static com.github.tomakehurst.wiremock.client.WireMock.get;
     6import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    47import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    58import static org.junit.jupiter.api.Assertions.assertEquals;
    69import static org.junit.jupiter.api.Assertions.assertThrows;
    710
     11import org.junit.jupiter.api.Test;
    812import org.junit.jupiter.api.extension.RegisterExtension;
    9 import org.junit.jupiter.api.Test;
     13import org.openstreetmap.josm.TestUtils;
    1014import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
     15import org.openstreetmap.josm.spi.preferences.Config;
    1116import org.openstreetmap.josm.testutils.JOSMTestRules;
     17
     18import com.github.tomakehurst.wiremock.WireMockServer;
    1219
    1320import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3643    @Test
    3744    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());
    3947    }
    4048
     
    6270    @Test
    6371    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>";
    6595    }
    6696}
Note: See TracChangeset for help on using the changeset viewer.