author | chegar |
Sun, 05 Nov 2017 17:32:13 +0000 | |
branch | http-client-branch |
changeset 55763 | 634d8e14c172 |
parent 47216 | 71c04702a3d5 |
child 55833 | 3e1f7cdef8a5 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, 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 |
import java.net.URI; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
import jdk.incubator.http.HttpClient; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
import java.time.Duration; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
27 |
import java.util.Arrays; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import java.util.function.BiFunction; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import java.util.function.Function; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
30 |
import java.util.function.Supplier; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
31 |
import java.util.stream.Collectors; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
32 |
import java.util.stream.Stream; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
33 |
import jdk.incubator.http.HttpRequest; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
34 |
import static jdk.incubator.http.HttpRequest.BodyPublisher.fromString; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
* @test |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
* @bug 8170064 |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
39 |
* @summary HttpRequest[.Builder] API and behaviour checks |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
40 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
41 |
public class HttpRequestBuilderTest { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
42 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
43 |
static final URI TEST_URI = URI.create("http://www.foo.com/"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
44 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
45 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
47 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
48 |
test0("newBuilder().build()", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
49 |
() -> HttpRequest.newBuilder().build(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
50 |
IllegalStateException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
51 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
52 |
test0("newBuilder(null)", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
53 |
() -> HttpRequest.newBuilder(null), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
54 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
55 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
56 |
test0("newBuilder(URI.create(\"badScheme://www.foo.com/\")", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
57 |
() -> HttpRequest.newBuilder(URI.create("badScheme://www.foo.com/")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
58 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
59 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
60 |
test0("newBuilder(URI.create(\"http://www.foo.com:-1/\")", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
61 |
() -> HttpRequest.newBuilder(URI.create("http://www.foo.com:-1/")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
62 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
63 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
64 |
test0("newBuilder(URI.create(\"https://www.foo.com:-1/\")", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
65 |
() -> HttpRequest.newBuilder(URI.create("https://www.foo.com:-1/")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
66 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
67 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
68 |
test0("newBuilder(" + TEST_URI + ").uri(null)", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
69 |
() -> HttpRequest.newBuilder(TEST_URI).uri(null), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
70 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
71 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
72 |
test0("newBuilder(uri).build()", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
73 |
() -> HttpRequest.newBuilder(TEST_URI).build() |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
74 |
/* no expected exceptions */ ); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
75 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
76 |
HttpRequest.Builder builder = HttpRequest.newBuilder(); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
77 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
78 |
builder = test1("uri", builder, builder::uri, (URI)null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
79 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
80 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
81 |
builder = test1("uri", builder, builder::uri, URI.create("http://www.foo.com:-1/"), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
82 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
83 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
84 |
builder = test1("uri", builder, builder::uri, URI.create("https://www.foo.com:-1/"), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
85 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
86 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
builder = test2("header", builder, builder::header, (String) null, "bar", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
88 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
89 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
builder = test2("header", builder, builder::header, "foo", (String) null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
92 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
builder = test2("header", builder, builder::header, (String)null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
(String) null, NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
95 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
96 |
builder = test2("header", builder, builder::header, "", "bar", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
97 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
98 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
99 |
builder = test2("header", builder, builder::header, "foo", "\r", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
100 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
101 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
builder = test1("headers", builder, builder::headers, (String[]) null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
104 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
105 |
builder = test1("headers", builder, builder::headers, new String[0], |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
106 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
107 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
builder = test1("headers", builder, builder::headers, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
(String[]) new String[] {null, "bar"}, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
110 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
111 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
112 |
builder = test1("headers", builder, builder::headers, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
113 |
(String[]) new String[] {"foo", null}, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
114 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
115 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
builder = test1("headers", builder, builder::headers, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
117 |
(String[]) new String[] {null, null}, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
118 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
119 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
120 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
121 |
(String[]) new String[] {"foo", "bar", null}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
122 |
NullPointerException.class, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
123 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
124 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
125 |
builder = test1("headers", builder, builder::headers, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
126 |
(String[]) new String[] {"foo", "bar", null, null}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
127 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
128 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
129 |
builder = test1("headers", builder, builder::headers, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
130 |
(String[]) new String[] {"foo", "bar", "baz", null}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
131 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
132 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
133 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
134 |
(String[]) new String[] {"foo", "bar", "\r", "baz"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
135 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
136 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
137 |
builder = test1("headers", builder, builder::headers, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
138 |
(String[]) new String[] {"foo", "bar", "baz", "\n"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
139 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
140 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
141 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
142 |
(String[]) new String[] {"foo", "bar", "", "baz"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
143 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
144 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
146 |
(String[]) new String[] {"foo", "bar", null, "baz"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
147 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
148 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
149 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
150 |
(String[]) new String[] {"foo", "bar", "baz"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
151 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
152 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
153 |
builder = test1("headers", builder, builder::headers, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
154 |
(String[]) new String[] {"foo"}, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
155 |
IllegalArgumentException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
156 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
157 |
builder = test1("DELETE", builder, builder::DELETE, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
158 |
HttpRequest.noBody(), null); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
159 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
160 |
builder = test1("POST", builder, builder::POST, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
161 |
HttpRequest.noBody(), null); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
162 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
163 |
builder = test1("PUT", builder, builder::PUT, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
164 |
HttpRequest.noBody(), null); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
165 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
166 |
builder = test2("method", builder, builder::method, "GET", |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
167 |
HttpRequest.noBody(), null); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
168 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
169 |
builder = test1("DELETE", builder, builder::DELETE, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
170 |
(HttpRequest.BodyPublisher)null, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
171 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
172 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
173 |
builder = test1("POST", builder, builder::POST, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
174 |
(HttpRequest.BodyPublisher)null, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
175 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
176 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
177 |
builder = test1("PUT", builder, builder::PUT, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
178 |
(HttpRequest.BodyPublisher)null, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
179 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
180 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
181 |
builder = test2("method", builder, builder::method, "GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
182 |
(HttpRequest.BodyPublisher) null, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
183 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
184 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
185 |
builder = test2("setHeader", builder, builder::setHeader, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
186 |
(String) null, "bar", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
187 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
188 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
189 |
builder = test2("setHeader", builder, builder::setHeader, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
190 |
"foo", (String) null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
191 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
192 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
193 |
builder = test2("setHeader", builder, builder::setHeader, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
194 |
(String)null, (String) null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
195 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
196 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
197 |
builder = test1("timeout", builder, builder::timeout, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
198 |
(Duration)null, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
199 |
NullPointerException.class); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
200 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
201 |
builder = test1("version", builder, builder::version, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
202 |
(HttpClient.Version)null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
203 |
NullPointerException.class); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
204 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
205 |
builder = test2("method", builder, builder::method, null, |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
206 |
HttpRequest.BodyPublisher.fromString("foo"), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
207 |
NullPointerException.class); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
208 |
// see JDK-8170093 |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
209 |
// |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
210 |
// builder = test2("method", builder, builder::method, "foo", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
211 |
// HttpRequest.BodyProcessor.fromString("foo"), |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
212 |
// IllegalArgumentException.class); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
213 |
// |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
214 |
// builder.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
215 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
216 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
217 |
method("newBuilder(TEST_URI).build().method() == GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
218 |
() -> HttpRequest.newBuilder(TEST_URI), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
219 |
"GET"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
220 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
221 |
method("newBuilder(TEST_URI).GET().build().method() == GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
222 |
() -> HttpRequest.newBuilder(TEST_URI).GET(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
223 |
"GET"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
224 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
225 |
method("newBuilder(TEST_URI).POST(fromString(\"\")).GET().build().method() == GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
226 |
() -> HttpRequest.newBuilder(TEST_URI).POST(fromString("")).GET(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
227 |
"GET"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
228 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
229 |
method("newBuilder(TEST_URI).PUT(fromString(\"\")).GET().build().method() == GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
230 |
() -> HttpRequest.newBuilder(TEST_URI).PUT(fromString("")).GET(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
231 |
"GET"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
232 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
233 |
method("newBuilder(TEST_URI).DELETE(fromString(\"\")).GET().build().method() == GET", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
234 |
() -> HttpRequest.newBuilder(TEST_URI).DELETE(fromString("")).GET(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
235 |
"GET"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
236 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
237 |
method("newBuilder(TEST_URI).POST(fromString(\"\")).build().method() == POST", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
238 |
() -> HttpRequest.newBuilder(TEST_URI).POST(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
239 |
"POST"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
240 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
241 |
method("newBuilder(TEST_URI).PUT(fromString(\"\")).build().method() == PUT", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
242 |
() -> HttpRequest.newBuilder(TEST_URI).PUT(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
243 |
"PUT"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
244 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
245 |
method("newBuilder(TEST_URI).DELETE(fromString(\"\")).build().method() == DELETE", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
246 |
() -> HttpRequest.newBuilder(TEST_URI).DELETE(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
247 |
"DELETE"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
248 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
249 |
method("newBuilder(TEST_URI).GET().POST(fromString(\"\")).build().method() == POST", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
250 |
() -> HttpRequest.newBuilder(TEST_URI).GET().POST(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
251 |
"POST"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
252 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
253 |
method("newBuilder(TEST_URI).GET().PUT(fromString(\"\")).build().method() == PUT", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
254 |
() -> HttpRequest.newBuilder(TEST_URI).GET().PUT(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
255 |
"PUT"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
256 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
257 |
method("newBuilder(TEST_URI).GET().DELETE(fromString(\"\")).build().method() == DELETE", |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
258 |
() -> HttpRequest.newBuilder(TEST_URI).GET().DELETE(fromString("")), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
259 |
"DELETE"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
260 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
261 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
262 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
263 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
264 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
265 |
private static boolean shouldFail(Class<? extends Exception> ...exceptions) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
266 |
return exceptions != null && exceptions.length > 0; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
267 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
268 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
269 |
private static String expectedNames(Class<? extends Exception> ...exceptions) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
270 |
return Stream.of(exceptions).map(Class::getSimpleName) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
271 |
.collect(Collectors.joining("|")); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
272 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
273 |
private static boolean isExpected(Exception x, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
274 |
Class<? extends Exception> ...expected) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
275 |
return expected != null && Stream.of(expected) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
276 |
.filter(c -> c.isInstance(x)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
277 |
.findAny().isPresent(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
278 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
279 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
280 |
static void method(String name, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
281 |
Supplier<HttpRequest.Builder> supplier, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
282 |
String expectedMethod) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
283 |
HttpRequest request = supplier.get().build(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
284 |
String method = request.method(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
285 |
if (request.method().equals("GET") && request.bodyPublisher().isPresent()) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
286 |
throw new AssertionError("failed: " + name |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
287 |
+ ". Unexpected body processor for GET: " |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
288 |
+ request.bodyPublisher().get()); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
289 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
290 |
if (expectedMethod.equals(method)) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
291 |
System.out.println("success: " + name); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
292 |
} else { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
293 |
throw new AssertionError("failed: " + name |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
294 |
+ ". Expected " + expectedMethod + ", got " + method); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
295 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
296 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
297 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
298 |
static void test0(String name, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
299 |
Runnable r, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
300 |
Class<? extends Exception> ...ex) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
301 |
try { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
302 |
r.run(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
303 |
if (!shouldFail(ex)) { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
304 |
System.out.println("success: " + name); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
305 |
return; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
306 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
307 |
throw new AssertionError("Expected " + expectedNames(ex) |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
308 |
+ " not raised for " + name); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
309 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
310 |
} catch (Exception x) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
311 |
if (!isExpected(x, ex)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
312 |
throw x; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
313 |
} else { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
314 |
System.out.println("success: " + name + |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
315 |
" - Got expected exception: " + x); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
316 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
317 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
318 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
319 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
320 |
public static <R,P> R test1(String name, R receiver, Function<P, R> m, P arg, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
321 |
Class<? extends Exception> ...ex) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
322 |
String argMessage = arg == null ? "null" : arg.toString(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
323 |
if (arg instanceof String[]) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
324 |
argMessage = Arrays.asList((String[])arg).toString(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
325 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
326 |
try { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
327 |
R result = m.apply(arg); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
328 |
if (!shouldFail(ex)) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
329 |
System.out.println("success: " + name + "(" + argMessage + ")"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
330 |
return result; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
331 |
} else { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
332 |
throw new AssertionError("Expected " + expectedNames(ex) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
333 |
+ " not raised for " + name + "(" + argMessage + ")"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
334 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
335 |
} catch (Exception x) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
336 |
if (!isExpected(x, ex)) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
337 |
throw x; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
338 |
} else { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
339 |
System.out.println("success: " + name + "(" + argMessage + ")" + |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
340 |
" - Got expected exception: " + x); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
341 |
return receiver; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
342 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
343 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
344 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
345 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
346 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
347 |
public static <R,P1, P2> R test2(String name, R receiver, BiFunction<P1, P2, R> m, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
348 |
P1 arg1, P2 arg2, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
349 |
Class<? extends Exception> ...ex) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
350 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
351 |
R result = m.apply(arg1, arg2); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
352 |
if (!shouldFail(ex)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
353 |
System.out.println("success: " + name + "(" + arg1 + ", " |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
354 |
+ arg2 + ")"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
355 |
return result; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
356 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
357 |
throw new AssertionError("Expected " + expectedNames(ex) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
358 |
+ " not raised for " |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
359 |
+ name + "(" + arg1 +", " + arg2 + ")"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
360 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
361 |
} catch (Exception x) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
362 |
if (!isExpected(x, ex)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
363 |
throw x; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
364 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
365 |
System.out.println("success: " + name + "(" + arg1 + ", " |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
366 |
+ arg2 + ") - Got expected exception: " + x); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
367 |
return receiver; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
368 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
369 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
370 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
371 |
} |