author | jjiang |
Mon, 15 Oct 2018 22:47:03 +0800 | |
changeset 52121 | 934969c63223 |
parent 49765 | ee6f7a61f3a5 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
49765 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
/* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
* @test |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
* @bug 8161157 |
48083 | 27 |
* @summary Test response body handlers/subscribers when there is no body |
52121
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
49765
diff
changeset
|
28 |
* @library /test/lib http2/server |
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
49765
diff
changeset
|
29 |
* @build jdk.test.lib.net.SimpleSSLContext |
48083 | 30 |
* @modules java.base/sun.net.www.http |
49765 | 31 |
* java.net.http/jdk.internal.net.http.common |
32 |
* java.net.http/jdk.internal.net.http.frame |
|
33 |
* java.net.http/jdk.internal.net.http.hpack |
|
34 |
* @run testng/othervm |
|
35 |
* -Djdk.internal.httpclient.debug=true |
|
36 |
* -Djdk.httpclient.HttpClient.log=all |
|
37 |
* NoBodyPartOne |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
39 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
40 |
import java.net.URI; |
48083 | 41 |
import java.nio.file.Files; |
42 |
import java.nio.file.Path; |
|
43 |
import java.nio.file.Paths; |
|
49765 | 44 |
import java.net.http.HttpClient; |
45 |
import java.net.http.HttpRequest; |
|
46 |
import java.net.http.HttpRequest.BodyPublishers; |
|
47 |
import java.net.http.HttpResponse; |
|
48 |
import java.net.http.HttpResponse.BodyHandler; |
|
49 |
import java.net.http.HttpResponse.BodyHandlers; |
|
48083 | 50 |
import org.testng.annotations.Test; |
51 |
import static java.nio.charset.StandardCharsets.UTF_8; |
|
52 |
import static org.testng.Assert.assertEquals; |
|
53 |
import static org.testng.Assert.assertTrue; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
54 |
|
48083 | 55 |
public class NoBodyPartOne extends AbstractNoBody { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
56 |
|
48083 | 57 |
@Test(dataProvider = "variants") |
58 |
public void testAsString(String uri, boolean sameClient) throws Exception { |
|
59 |
printStamp(START, "testAsString(\"%s\", %s)", uri, sameClient); |
|
60 |
HttpClient client = null; |
|
61 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
62 |
if (!sameClient || client == null) |
|
63 |
client = newHttpClient(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
|
48083 | 65 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
49765 | 66 |
.PUT(BodyPublishers.ofString(SIMPLE_STRING)) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
67 |
.build(); |
49765 | 68 |
BodyHandler<String> handler = i % 2 == 0 ? BodyHandlers.ofString() |
69 |
: BodyHandlers.ofString(UTF_8); |
|
48083 | 70 |
HttpResponse<String> response = client.send(req, handler); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
71 |
String body = response.body(); |
48083 | 72 |
assertEquals(body, ""); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
73 |
} |
48083 | 74 |
// We have created many clients here. Try to speed up their release. |
75 |
if (!sameClient) System.gc(); |
|
76 |
} |
|
77 |
||
78 |
@Test(dataProvider = "variants") |
|
79 |
public void testAsFile(String uri, boolean sameClient) throws Exception { |
|
80 |
printStamp(START, "testAsFile(\"%s\", %s)", uri, sameClient); |
|
81 |
HttpClient client = null; |
|
82 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
83 |
if (!sameClient || client == null) |
|
84 |
client = newHttpClient(); |
|
85 |
||
86 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
|
49765 | 87 |
.PUT(BodyPublishers.ofString(SIMPLE_STRING)) |
48083 | 88 |
.build(); |
89 |
Path p = Paths.get("NoBody_testAsFile.txt"); |
|
49765 | 90 |
HttpResponse<Path> response = client.send(req, BodyHandlers.ofFile(p)); |
48083 | 91 |
Path bodyPath = response.body(); |
92 |
assertTrue(Files.exists(bodyPath)); |
|
93 |
assertEquals(Files.size(bodyPath), 0); |
|
94 |
} |
|
95 |
// We have created many clients here. Try to speed up their release. |
|
96 |
if (!sameClient) System.gc(); |
|
97 |
} |
|
98 |
||
99 |
@Test(dataProvider = "variants") |
|
100 |
public void testAsByteArray(String uri, boolean sameClient) throws Exception { |
|
101 |
printStamp(START, "testAsByteArray(\"%s\", %s)", uri, sameClient); |
|
102 |
HttpClient client = null; |
|
103 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
104 |
if (!sameClient || client == null) |
|
105 |
client = newHttpClient(); |
|
106 |
||
107 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
|
49765 | 108 |
.PUT(BodyPublishers.ofString(SIMPLE_STRING)) |
48083 | 109 |
.build(); |
49765 | 110 |
HttpResponse<byte[]> response = client.send(req, BodyHandlers.ofByteArray()); |
48083 | 111 |
byte[] body = response.body(); |
112 |
assertEquals(body.length, 0); |
|
113 |
} |
|
114 |
// We have created many clients here. Try to speed up their release. |
|
115 |
if (!sameClient) System.gc(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
117 |
} |