Changeset 10641 in josm for trunk/test/functional


Ignore:
Timestamp:
2016-07-25T21:41:53+02:00 (3 years ago)
Author:
Don-vip
Message:

move unit tests from UtilsTest to HttpClientTest (should have been done in r9720)

File:
1 edited

Legend:

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

    r10302 r10641  
    77import static org.junit.Assert.assertThat;
    88
     9import java.io.BufferedReader;
    910import java.io.IOException;
    1011import java.io.InputStream;
     
    1718import javax.json.spi.JsonProvider;
    1819
     20import org.junit.Assert;
    1921import org.junit.Before;
    2022import org.junit.BeforeClass;
    2123import org.junit.Test;
    2224import org.openstreetmap.josm.JOSMFixture;
     25import org.openstreetmap.josm.Main;
    2326import org.openstreetmap.josm.TestUtils;
    2427import org.openstreetmap.josm.data.Version;
     
    3841
    3942    @Before
    40     public void setUp() throws Exception {
     43    public void setUp() {
    4144        progress = TestUtils.newTestProgressMonitor();
    4245    }
    4346
    4447    @Test
    45     public void testConstructorGetterSetter() throws Exception {
     48    public void testConstructorGetterSetter() throws IOException {
    4649        final HttpClient client = HttpClient.create(new URL("https://httpbin.org/"));
    4750        assertThat(client.getURL(), is(new URL("https://httpbin.org/")));
     
    6063
    6164    @Test
    62     public void testGet() throws Exception {
     65    public void testGet() throws IOException {
    6366        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect(progress);
    6467        assertThat(response.getRequestMethod(), is("GET"));
     
    7982
    8083    @Test
    81     public void testUserAgent() throws Exception {
     84    public void testUserAgent() throws IOException {
    8285        try (final InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent();
    8386             final JsonReader json = JsonProvider.provider().createReader(in)) {
     
    8790
    8891    @Test
    89     public void testFetchUtf8Content() throws Exception {
     92    public void testFetchUtf8Content() throws IOException {
    9093        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect(progress);
    9194        assertThat(response.getResponseCode(), is(200));
     
    9699
    97100    @Test
    98     public void testPost() throws Exception {
     101    public void testPost() throws IOException {
    99102        final String text = "Hello World!\nGeetings from JOSM, the Java OpenStreetMap Editor";
    100103        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST")
     
    111114
    112115    @Test
    113     public void testPostZero() throws Exception {
     116    public void testPostZero() throws IOException {
    114117        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST")
    115118                .setHeader("Content-Type", "text/plain")
     
    125128
    126129    @Test
    127     public void testRelativeRedirects() throws Exception {
     130    public void testRelativeRedirects() throws IOException {
    128131        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/5")).connect(progress);
    129132        assertThat(response.getResponseCode(), is(200));
     
    132135
    133136    @Test
    134     public void testAbsoluteRedirects() throws Exception {
     137    public void testAbsoluteRedirects() throws IOException {
    135138        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/5")).connect(progress);
    136139        assertThat(response.getResponseCode(), is(200));
     
    139142
    140143    @Test(expected = IOException.class)
    141     public void testTooMuchRedirects() throws Exception {
     144    public void testTooMuchRedirects() throws IOException {
    142145        HttpClient.create(new URL("https://httpbin.org/redirect/5")).setMaxRedirects(4).connect(progress);
    143146    }
    144147
    145148    @Test
    146     public void test418() throws Exception {
     149    public void test418() throws IOException {
    147150        // https://tools.ietf.org/html/rfc2324
    148151        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect(progress);
     
    154157
    155158    @Test
    156     public void testRequestInTime() throws Exception {
     159    public void testRequestInTime() throws IOException {
    157160        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(3500).connect(progress);
    158161        assertThat(response.getResponseCode(), is(200));
     
    160163
    161164    @Test(expected = IOException.class)
    162     public void testTakesTooLong() throws Exception {
     165    public void testTakesTooLong() throws IOException {
    163166        HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(2500).connect(progress);
    164167    }
     168
     169    /**
     170     * Test of {@link HttpClient.Response#uncompress} method with Gzip compression.
     171     * @throws IOException if any I/O error occurs
     172     */
     173    @Test
     174    public void testOpenUrlGzip() throws IOException {
     175        Main.initApplicationPreferences();
     176        final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
     177        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
     178            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     179        }
     180    }
     181
     182    /**
     183     * Test of {@link HttpClient.Response#uncompress} method with Bzip compression.
     184     * @throws IOException if any I/O error occurs
     185     */
     186    @Test
     187    public void testOpenUrlBzip() throws IOException {
     188        Main.initApplicationPreferences();
     189        final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
     190        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
     191            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     192        }
     193    }
     194
     195    /**
     196     * Test of {@link HttpClient.Response#uncompress} method with Bzip compression.
     197     * @throws IOException if any I/O error occurs
     198     */
     199    @Test
     200    public void testTicket9660() throws IOException {
     201        Main.initApplicationPreferences();
     202        final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
     203        try (BufferedReader x = HttpClient.create(url).connect()
     204                .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {
     205            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     206        }
     207    }
    165208}
Note: See TracChangeset for help on using the changeset viewer.