Changeset 10641 in josm
- Timestamp:
- 2016-07-25T21:41:53+02:00 (7 years ago)
- Location:
- trunk/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r10302 r10641 7 7 import static org.junit.Assert.assertThat; 8 8 9 import java.io.BufferedReader; 9 10 import java.io.IOException; 10 11 import java.io.InputStream; … … 17 18 import javax.json.spi.JsonProvider; 18 19 20 import org.junit.Assert; 19 21 import org.junit.Before; 20 22 import org.junit.BeforeClass; 21 23 import org.junit.Test; 22 24 import org.openstreetmap.josm.JOSMFixture; 25 import org.openstreetmap.josm.Main; 23 26 import org.openstreetmap.josm.TestUtils; 24 27 import org.openstreetmap.josm.data.Version; … … 38 41 39 42 @Before 40 public void setUp() throws Exception{43 public void setUp() { 41 44 progress = TestUtils.newTestProgressMonitor(); 42 45 } 43 46 44 47 @Test 45 public void testConstructorGetterSetter() throws Exception {48 public void testConstructorGetterSetter() throws IOException { 46 49 final HttpClient client = HttpClient.create(new URL("https://httpbin.org/")); 47 50 assertThat(client.getURL(), is(new URL("https://httpbin.org/"))); … … 60 63 61 64 @Test 62 public void testGet() throws Exception {65 public void testGet() throws IOException { 63 66 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect(progress); 64 67 assertThat(response.getRequestMethod(), is("GET")); … … 79 82 80 83 @Test 81 public void testUserAgent() throws Exception {84 public void testUserAgent() throws IOException { 82 85 try (final InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent(); 83 86 final JsonReader json = JsonProvider.provider().createReader(in)) { … … 87 90 88 91 @Test 89 public void testFetchUtf8Content() throws Exception {92 public void testFetchUtf8Content() throws IOException { 90 93 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect(progress); 91 94 assertThat(response.getResponseCode(), is(200)); … … 96 99 97 100 @Test 98 public void testPost() throws Exception {101 public void testPost() throws IOException { 99 102 final String text = "Hello World!\nGeetings from JOSM, the Java OpenStreetMap Editor"; 100 103 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST") … … 111 114 112 115 @Test 113 public void testPostZero() throws Exception {116 public void testPostZero() throws IOException { 114 117 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST") 115 118 .setHeader("Content-Type", "text/plain") … … 125 128 126 129 @Test 127 public void testRelativeRedirects() throws Exception {130 public void testRelativeRedirects() throws IOException { 128 131 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/5")).connect(progress); 129 132 assertThat(response.getResponseCode(), is(200)); … … 132 135 133 136 @Test 134 public void testAbsoluteRedirects() throws Exception {137 public void testAbsoluteRedirects() throws IOException { 135 138 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/5")).connect(progress); 136 139 assertThat(response.getResponseCode(), is(200)); … … 139 142 140 143 @Test(expected = IOException.class) 141 public void testTooMuchRedirects() throws Exception {144 public void testTooMuchRedirects() throws IOException { 142 145 HttpClient.create(new URL("https://httpbin.org/redirect/5")).setMaxRedirects(4).connect(progress); 143 146 } 144 147 145 148 @Test 146 public void test418() throws Exception {149 public void test418() throws IOException { 147 150 // https://tools.ietf.org/html/rfc2324 148 151 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect(progress); … … 154 157 155 158 @Test 156 public void testRequestInTime() throws Exception {159 public void testRequestInTime() throws IOException { 157 160 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(3500).connect(progress); 158 161 assertThat(response.getResponseCode(), is(200)); … … 160 163 161 164 @Test(expected = IOException.class) 162 public void testTakesTooLong() throws Exception {165 public void testTakesTooLong() throws IOException { 163 166 HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(2500).connect(progress); 164 167 } 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 } 165 208 } -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r10638 r10641 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.io.BufferedReader;7 import java.io.IOException;8 import java.net.URL;9 6 import java.util.Arrays; 10 7 import java.util.Collections; … … 14 11 import org.junit.Assert; 15 12 import org.junit.Test; 16 import org.openstreetmap.josm.Main;17 13 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 14 … … 87 83 Assert.assertEquals("127f", Utils.toHexString(new byte[]{0x12, 0x7f})); 88 84 Assert.assertEquals("fedc", Utils.toHexString(new byte[]{(byte) 0xfe, (byte) 0xdc})); 89 }90 91 /**92 * Test of {@link Utils#openURLReaderAndDecompress} method with Gzip compression.93 * @throws IOException if any I/O error occurs94 */95 @Test96 public void testOpenUrlGzip() throws IOException {97 Main.initApplicationPreferences();98 final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");99 try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {100 Assert.assertTrue(x.readLine().startsWith("<?xml version="));101 }102 }103 104 /**105 * Test of {@link Utils#openURLReaderAndDecompress} method with Bzip compression.106 * @throws IOException if any I/O error occurs107 */108 @Test109 public void testOpenUrlBzip() throws IOException {110 Main.initApplicationPreferences();111 final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");112 try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {113 Assert.assertTrue(x.readLine().startsWith("<?xml version="));114 }115 }116 117 /**118 * Test of {@link Utils#openURLReaderAndDecompress} method with Bzip compression.119 * @throws IOException if any I/O error occurs120 */121 @Test122 public void testTicket9660() throws IOException {123 Main.initApplicationPreferences();124 final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");125 try (BufferedReader x = HttpClient.create(url).connect()126 .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {127 Assert.assertTrue(x.readLine().startsWith("<?xml version="));128 }129 85 } 130 86
Note: See TracChangeset
for help on using the changeset viewer.