test/jdk/java/net/httpclient/websocket/WebSocketBuilderTest.java
author chegar
Thu, 26 Apr 2018 14:42:36 +0100
branchhttp-client-branch
changeset 56486 b664a887e277
parent 56451 9585061fdb04
permissions -rw-r--r--
http-client-branch: set NO_PROXY in several WebSocket tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     1
/*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     4
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     8
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    13
 * accompanied this code).
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    14
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    18
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    21
 * questions.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    22
 */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    23
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    24
/*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    25
 * @test
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    26
 * @bug 8159053
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    27
 * @run testng/othervm WebSocketBuilderTest
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    28
 */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    29
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    30
import org.testng.annotations.DataProvider;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    31
import org.testng.annotations.Test;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    32
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    33
import java.net.URI;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    34
import java.net.http.HttpClient;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    35
import java.net.http.WebSocket;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    36
import java.time.Duration;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    37
import java.util.List;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    38
import java.util.concurrent.CompletionStage;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    39
import java.util.function.Function;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    40
import java.util.stream.Collectors;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    41
import java.util.stream.Stream;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    42
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    43
import static org.testng.Assert.assertThrows;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    44
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    45
/*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    46
 * In some places in this test a new String is created out of a string literal.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    47
 * The idea is to make sure the code under test relies on something better than
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    48
 * the reference equality ( == ) for string equality checks.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    49
 */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    50
public final class WebSocketBuilderTest {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    51
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    52
    private final static URI VALID_URI = URI.create("ws://websocket.example.com");
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    53
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    54
    @Test
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    55
    public void nullArguments() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    56
        HttpClient c = HttpClient.newHttpClient();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    57
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    58
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    59
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    60
                             .buildAsync(null, listener()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    61
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    62
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    63
                             .buildAsync(VALID_URI, null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    64
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    65
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    66
                             .buildAsync(null, null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    67
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    68
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    69
                             .header(null, "value"));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    70
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    71
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    72
                             .header("name", null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    73
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    74
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    75
                             .header(null, null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    76
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    77
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    78
                             .subprotocols(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    79
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    80
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    81
                             .subprotocols(null, "sub2.example.com"));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    82
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    83
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    84
                             .subprotocols("sub1.example.com", (String) null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    85
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    86
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    87
                             .subprotocols("sub1.example.com", (String[]) null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    88
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    89
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    90
                             .subprotocols("sub1.example.com", "sub2.example.com", null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    91
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    92
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    93
                             .subprotocols("sub1.example.com", null, "sub3.example.com"));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    94
        assertThrows(NullPointerException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    95
                     () -> c.newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    96
                             .connectTimeout(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    97
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    98
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    99
    @Test(dataProvider = "badURIs")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   100
    void illegalURI(URI uri) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   101
        WebSocket.Builder b = HttpClient.newHttpClient().newWebSocketBuilder();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   102
        assertFails(IllegalArgumentException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   103
                    b.buildAsync(uri, listener()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   104
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   105
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   106
    @Test
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   107
    public void illegalHeaders() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   108
        List<String> headers =
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   109
                List.of("Sec-WebSocket-Accept",
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   110
                        "Sec-WebSocket-Extensions",
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   111
                        "Sec-WebSocket-Key",
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   112
                        "Sec-WebSocket-Protocol",
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   113
                        "Sec-WebSocket-Version")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   114
                        .stream()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   115
                        .flatMap(s -> Stream.of(s, new String(s))) // a string and a copy of it
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   116
                        .collect(Collectors.toList());
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   117
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   118
        Function<String, CompletionStage<?>> f =
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   119
                header -> HttpClient.newHttpClient()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   120
                        .newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   121
                        .header(header, "value")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   122
                        .buildAsync(VALID_URI, listener());
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   123
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   124
        headers.forEach(h -> assertFails(IllegalArgumentException.class, f.apply(h)));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   125
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   126
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   127
    // TODO: test for bad syntax headers
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   128
    // TODO: test for overwrites (subprotocols) and additions (headers)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   129
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   130
    @Test(dataProvider = "badSubprotocols")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   131
    public void illegalSubprotocolsSyntax(String s) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   132
        WebSocket.Builder b = HttpClient.newHttpClient()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   133
                .newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   134
                .subprotocols(s);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   135
        assertFails(IllegalArgumentException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   136
                    b.buildAsync(VALID_URI, listener()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   137
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   138
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   139
    @Test(dataProvider = "duplicatingSubprotocols")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   140
    public void illegalSubprotocolsDuplicates(String mostPreferred,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   141
                                              String[] lesserPreferred) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   142
        WebSocket.Builder b = HttpClient.newHttpClient()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   143
                .newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   144
                .subprotocols(mostPreferred, lesserPreferred);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   145
        assertFails(IllegalArgumentException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   146
                    b.buildAsync(VALID_URI, listener()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   147
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   148
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   149
    @Test(dataProvider = "badConnectTimeouts")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   150
    public void illegalConnectTimeout(Duration d) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   151
        WebSocket.Builder b = HttpClient.newHttpClient()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   152
                .newWebSocketBuilder()
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   153
                .connectTimeout(d);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   154
        assertFails(IllegalArgumentException.class,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   155
                    b.buildAsync(VALID_URI, listener()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   156
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   157
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   158
    @DataProvider
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   159
    public Object[][] badURIs() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   160
        return new Object[][]{
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   161
                {URI.create("http://example.com")},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   162
                {URI.create("ftp://example.com")},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   163
                {URI.create("wss://websocket.example.com/hello#fragment")},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   164
                {URI.create("ws://websocket.example.com/hello#fragment")},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   165
        };
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   166
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   167
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   168
    @DataProvider
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   169
    public Object[][] badConnectTimeouts() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   170
        return new Object[][]{
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   171
                {Duration.ofDays(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   172
                {Duration.ofDays(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   173
                {Duration.ofHours(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   174
                {Duration.ofHours(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   175
                {Duration.ofMinutes(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   176
                {Duration.ofMinutes(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   177
                {Duration.ofSeconds(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   178
                {Duration.ofSeconds(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   179
                {Duration.ofMillis(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   180
                {Duration.ofMillis(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   181
                {Duration.ofNanos(0)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   182
                {Duration.ofNanos(-1)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   183
                {Duration.ZERO},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   184
        };
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   185
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   186
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   187
    // https://tools.ietf.org/html/rfc7230#section-3.2.6
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   188
    // https://tools.ietf.org/html/rfc20
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   189
    @DataProvider
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   190
    public static Object[][] badSubprotocols() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   191
        return new Object[][]{
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   192
                {""},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   193
                {new String("")},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   194
                {"round-brackets("},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   195
                {"round-brackets)"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   196
                {"comma,"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   197
                {"slash/"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   198
                {"colon:"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   199
                {"semicolon;"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   200
                {"angle-brackets<"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   201
                {"angle-brackets>"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   202
                {"equals="},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   203
                {"question-mark?"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   204
                {"at@"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   205
                {"brackets["},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   206
                {"backslash\\"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   207
                {"brackets]"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   208
                {"curly-brackets{"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   209
                {"curly-brackets}"},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   210
                {"space "},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   211
                {"non-printable-character " + Character.toString((char) 31)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   212
                {"non-printable-character " + Character.toString((char) 127)},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   213
        };
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   214
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   215
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   216
    @DataProvider
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   217
    public static Object[][] duplicatingSubprotocols() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   218
        return new Object[][]{
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   219
                {"a.b.c", new String[]{"a.b.c"}},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   220
                {"a.b.c", new String[]{"x.y.z", "p.q.r", "x.y.z"}},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   221
                {"a.b.c", new String[]{new String("a.b.c")}},
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   222
        };
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   223
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   224
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   225
    private static WebSocket.Listener listener() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   226
        return new WebSocket.Listener() { };
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   227
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   228
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   229
    /* shortcut */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   230
    public static void assertFails(Class<? extends Throwable> clazz,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   231
                                   CompletionStage<?> stage) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   232
        Support.assertCompletesExceptionally(clazz, stage);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   233
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   234
}