-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathSocketTest.java
More file actions
121 lines (105 loc) · 3.81 KB
/
Copy pathSocketTest.java
File metadata and controls
121 lines (105 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package io.socket.engineio.client;
import io.socket.engineio.client.transports.Polling;
import io.socket.engineio.client.transports.WebSocket;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(JUnit4.class)
public class SocketTest {
@Test
public void filterUpgrades() {
Socket.Options opts = new Socket.Options();
opts.transports = new String[] {Polling.NAME};
Socket socket = new Socket(opts);
List<String> upgrades = new ArrayList<String>() {{
add(Polling.NAME);
add(WebSocket.NAME);
}};
List<String> expected = new ArrayList<String>() {{add(Polling.NAME);}};
assertThat(socket.filterUpgrades(upgrades), is(expected));
}
@Test
public void properlyParseHttpUriWithoutPort() throws URISyntaxException {
Socket client = new Socket("http://localhost");
assertThat(client.hostname, is("localhost"));
assertThat(client.port, is(80));
}
@Test
public void properlyParseHttpsUriWithoutPort() throws URISyntaxException {
Socket client = new Socket("https://localhost");
assertThat(client.hostname, is("localhost"));
assertThat(client.port, is(443));
}
@Test
public void properlyParseWssUriWithoutPort() throws URISyntaxException {
Socket client = new Socket("wss://localhost");
assertThat(client.hostname, is("localhost"));
assertThat(client.port, is(443));
}
@Test
public void properlyParseWssUriWithPort() throws URISyntaxException {
Socket client = new Socket("wss://localhost:2020");
assertThat(client.hostname, is("localhost"));
assertThat(client.port, is(2020));
}
@Test
public void properlyParseHostWithPort() {
Socket.Options opts = new Socket.Options();
opts.host = "localhost";
opts.port = 8080;
Socket client = new Socket(opts);
assertThat(client.hostname, is("localhost"));
assertThat(client.port, is(8080));
}
@Test
public void properlyParseIPv6UriWithoutPort() throws URISyntaxException {
Socket client = new Socket("http://[::1]");
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(80));
}
@Test
public void properlyParseIPv6UriWithPort() throws URISyntaxException {
Socket client = new Socket("http://[::1]:8080");
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(8080));
}
@Test
public void properlyParseIPv6HostWithoutPort1() {
Socket.Options opts = new Socket.Options();
opts.host = "[::1]";
Socket client = new Socket(opts);
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(80));
}
@Test
public void properlyParseIPv6HostWithoutPort2() {
Socket.Options opts = new Socket.Options();
opts.secure = true;
opts.host = "[::1]";
Socket client = new Socket(opts);
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(443));
}
@Test
public void properlyParseIPv6HostWithPort() {
Socket.Options opts = new Socket.Options();
opts.host = "[::1]";
opts.port = 8080;
Socket client = new Socket(opts);
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(8080));
}
@Test
public void properlyParseIPv6HostWithoutBrace() {
Socket.Options opts = new Socket.Options();
opts.host = "::1";
Socket client = new Socket(opts);
assertThat(client.hostname, is("::1"));
assertThat(client.port, is(80));
}
}