-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use appropriate schema in any case #1026
add unit test for schema check
- Loading branch information
yindex
authored and
宰祥顺
committed
May 23, 2020
1 parent
433935a
commit 38a7aed
Showing
3 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/org/java_websocket/client/SchemaCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.java_websocket.client; | ||
|
||
import org.java_websocket.handshake.ServerHandshake; | ||
import org.junit.Test; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class SchemaCheckTest { | ||
|
||
@Test | ||
public void testSchemaCheck() throws URISyntaxException { | ||
final String []invalidCase = { | ||
"http://localhost:80", | ||
"http://localhost:81", | ||
"http://localhost", | ||
"https://localhost:443", | ||
"https://localhost:444", | ||
"https://localhost", | ||
"any://localhost", | ||
"any://localhost:82", | ||
}; | ||
final Exception[] exs = new Exception[invalidCase.length]; | ||
for (int i = 0; i < invalidCase.length; i++) { | ||
final int finalI = i; | ||
new WebSocketClient(new URI(invalidCase[finalI])) { | ||
@Override | ||
public void onOpen(ServerHandshake handshakedata) { | ||
|
||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
|
||
} | ||
|
||
@Override | ||
public void onClose(int code, String reason, boolean remote) { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Exception ex) { | ||
exs[finalI] = ex; | ||
} | ||
}.run(); | ||
} | ||
for (Exception exception : exs) { | ||
assertTrue(exception instanceof IllegalArgumentException); | ||
} | ||
final String []validCase = { | ||
"ws://localhost", | ||
"ws://localhost:80", | ||
"ws://localhost:81", | ||
"wss://localhost", | ||
"wss://localhost:443", | ||
"wss://localhost:444" | ||
}; | ||
for (String s : validCase) { | ||
new WebSocketClient(new URI(s)) { | ||
@Override | ||
public void onOpen(ServerHandshake handshakedata) { | ||
|
||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
|
||
} | ||
|
||
@Override | ||
public void onClose(int code, String reason, boolean remote) { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Exception ex) { | ||
assertFalse(ex instanceof IllegalArgumentException); | ||
} | ||
}.run(); | ||
} | ||
} | ||
} |