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


Ignore:
Timestamp:
2020-10-13T23:48:18+02:00 (4 years ago)
Author:
simon04
Message:

see #15102 - see #16637 - get rid of real HTTP calls to https://www.openstreetmap.org/trace in HttpClientTest, mock them

File:
1 edited

Legend:

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

    r17154 r17197  
    339339    @Test
    340340    public void testOpenUrlGzip() throws IOException {
    341         final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
     341        final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.gz"));
     342        localServer.stubFor(get(urlEqualTo("/trace/1613906/data"))
     343                .willReturn(aResponse()
     344                        .withStatus(200)
     345                        .withHeader("content-type", "application/x-gzip")
     346                        .withBody(gpx)));
     347
     348        final URL url = new URL(localServer.url("/trace/1613906/data"));
    342349        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    343350            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     
    351358    @Test
    352359    public void testOpenUrlBzip() throws IOException {
    353         final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
     360        final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.bz2"));
     361        localServer.stubFor(get(urlEqualTo("/trace/785544/data"))
     362                .willReturn(aResponse()
     363                        .withStatus(200)
     364                        .withHeader("content-type", "application/x-bzip2")
     365                        .withBody(gpx)));
     366
     367        final URL url = new URL(localServer.url("/trace/785544/data"));
    354368        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    355369            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     
    362376     */
    363377    @Test
    364     public void testTicket9660() throws IOException {
    365         final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
     378    public void testOpenUrlBzipAccordingToContentDisposition() throws IOException {
     379        final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.bz2"));
     380        localServer.stubFor(get(urlEqualTo("/trace/1350010/data"))
     381                .willReturn(aResponse()
     382                        .withStatus(200)
     383                        .withHeader("content-type", "application/octet-stream")
     384                        .withHeader("content-disposition", "attachment; filename=\"1350010.gpx.bz2\"")
     385                        .withBody(gpx)));
     386
     387        final URL url = new URL(localServer.url("/trace/1350010/data"));
    366388        try (BufferedReader x = HttpClient.create(url).connect()
    367389                .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {
Note: See TracChangeset for help on using the changeset viewer.