Changeset 9529 in josm for trunk/test/functional/org/openstreetmap/josm/tools
- Timestamp:
- 2016-01-18T21:42:58+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r9255 r9529 17 17 import javax.json.spi.JsonProvider; 18 18 19 import org.junit.Before; 19 20 import org.junit.BeforeClass; 20 21 import org.junit.Test; 21 22 import org.openstreetmap.josm.JOSMFixture; 23 import org.openstreetmap.josm.TestUtils; 22 24 import org.openstreetmap.josm.data.Version; 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 26 24 27 /** … … 27 30 public class HttpClientTest { 28 31 32 private ProgressMonitor progress; 33 29 34 @BeforeClass 30 35 public static void setUpBeforeClass() { 31 36 JOSMFixture.createFunctionalTestFixture().init(); 37 } 38 39 @Before 40 public void setUp() throws Exception { 41 progress = TestUtils.newTestProgressMonitor(); 32 42 } 33 43 … … 51 61 @Test 52 62 public void testGet() throws Exception { 53 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect( );63 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect(progress); 54 64 assertThat(response.getRequestMethod(), is("GET")); 55 65 assertThat(response.getResponseCode(), is(200)); … … 70 80 @Test 71 81 public void testUserAgent() throws Exception { 72 try (final InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect( ).getContent();82 try (final InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent(); 73 83 final JsonReader json = JsonProvider.provider().createReader(in)) { 74 84 assertThat(json.readObject().getString("user-agent"), is(Version.getInstance().getFullAgentString())); … … 78 88 @Test 79 89 public void testFetchUtf8Content() throws Exception { 80 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect( );90 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect(progress); 81 91 assertThat(response.getResponseCode(), is(200)); 82 92 final String content = response.fetchContent(); … … 91 101 .setHeader("Content-Type", "text/plain") 92 102 .setRequestBody(text.getBytes(StandardCharsets.UTF_8)) 93 .connect( );103 .connect(progress); 94 104 assertThat(response.getResponseCode(), is(200)); 95 105 try (final InputStream in = response.getContent(); … … 100 110 101 111 @Test 112 public void testPostZero() throws Exception { 113 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST") 114 .setHeader("Content-Type", "text/plain") 115 .setRequestBody("".getBytes(StandardCharsets.UTF_8)) 116 .connect(progress); 117 assertThat(response.getResponseCode(), is(200)); 118 try (final InputStream in = response.getContent(); 119 final JsonReader json = JsonProvider.provider().createReader(in)) { 120 assertThat(json.readObject().getString("data"), is("")); 121 } 122 } 123 124 @Test 102 125 public void testRelativeRedirects() throws Exception { 103 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/5")).connect( );126 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/5")).connect(progress); 104 127 assertThat(response.getResponseCode(), is(200)); 105 128 assertThat(response.getContentLength() > 100, is(true)); … … 108 131 @Test 109 132 public void testAbsoluteRedirects() throws Exception { 110 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/5")).connect( );133 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/5")).connect(progress); 111 134 assertThat(response.getResponseCode(), is(200)); 112 135 assertThat(response.getContentLength() > 100, is(true)); … … 115 138 @Test(expected = IOException.class) 116 139 public void testTooMuchRedirects() throws Exception { 117 HttpClient.create(new URL("https://httpbin.org/redirect/5")).setMaxRedirects(4).connect( );140 HttpClient.create(new URL("https://httpbin.org/redirect/5")).setMaxRedirects(4).connect(progress); 118 141 } 119 142 … … 121 144 public void test418() throws Exception { 122 145 // https://tools.ietf.org/html/rfc2324 123 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect( );146 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect(progress); 124 147 assertThat(response.getResponseCode(), is(418)); 125 148 assertThat(response.getResponseMessage(), is("I'M A TEAPOT")); … … 130 153 @Test 131 154 public void testRequestInTime() throws Exception { 132 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(3500).connect( );155 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(3500).connect(progress); 133 156 assertThat(response.getResponseCode(), is(200)); 134 157 } … … 136 159 @Test(expected = IOException.class) 137 160 public void testTakesTooLong() throws Exception { 138 HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(2500).connect( );161 HttpClient.create(new URL("https://httpbin.org/delay/3")).setReadTimeout(2500).connect(progress); 139 162 } 140 163 }
Note:
See TracChangeset
for help on using the changeset viewer.