|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -19,6 +19,8 @@ package org.springframework.web.socket.sockjs.client;
@@ -19,6 +19,8 @@ package org.springframework.web.socket.sockjs.client;
|
|
|
|
|
import java.net.URI; |
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
import org.junit.jupiter.params.provider.CsvSource; |
|
|
|
|
|
|
|
|
|
import org.springframework.web.socket.sockjs.transport.TransportType; |
|
|
|
|
|
|
|
|
|
@ -28,52 +30,47 @@ import static org.assertj.core.api.Assertions.assertThat;
@@ -28,52 +30,47 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
* Unit tests for {@code SockJsUrlInfo}. |
|
|
|
|
* |
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
*/ |
|
|
|
|
public class SockJsUrlInfoTests { |
|
|
|
|
class SockJsUrlInfoTests { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void serverId() throws Exception { |
|
|
|
|
void serverId() throws Exception { |
|
|
|
|
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); |
|
|
|
|
int serverId = Integer.parseInt(info.getServerId()); |
|
|
|
|
assertThat(serverId >= 0 && serverId < 1000).as("Invalid serverId: " + serverId).isTrue(); |
|
|
|
|
assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sessionId() throws Exception { |
|
|
|
|
void sessionId() throws Exception { |
|
|
|
|
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); |
|
|
|
|
assertThat(info.getSessionId().length()).as("Invalid sessionId: " + info.getSessionId()).isEqualTo(32); |
|
|
|
|
assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void infoUrl() throws Exception { |
|
|
|
|
testInfoUrl("http", "http"); |
|
|
|
|
testInfoUrl("http", "http"); |
|
|
|
|
testInfoUrl("https", "https"); |
|
|
|
|
testInfoUrl("https", "https"); |
|
|
|
|
testInfoUrl("ws", "http"); |
|
|
|
|
testInfoUrl("ws", "http"); |
|
|
|
|
testInfoUrl("wss", "https"); |
|
|
|
|
testInfoUrl("wss", "https"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void testInfoUrl(String scheme, String expectedScheme) throws Exception { |
|
|
|
|
@ParameterizedTest |
|
|
|
|
@CsvSource( { |
|
|
|
|
"http, http", |
|
|
|
|
"https, https", |
|
|
|
|
"ws, http", |
|
|
|
|
"wss, https", |
|
|
|
|
}) |
|
|
|
|
void infoUrl(String scheme, String expectedScheme) throws Exception { |
|
|
|
|
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); |
|
|
|
|
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void transportUrl() throws Exception { |
|
|
|
|
testTransportUrl("http", "http", TransportType.XHR_STREAMING); |
|
|
|
|
testTransportUrl("http", "ws", TransportType.WEBSOCKET); |
|
|
|
|
testTransportUrl("https", "https", TransportType.XHR_STREAMING); |
|
|
|
|
testTransportUrl("https", "wss", TransportType.WEBSOCKET); |
|
|
|
|
testTransportUrl("ws", "http", TransportType.XHR_STREAMING); |
|
|
|
|
testTransportUrl("ws", "ws", TransportType.WEBSOCKET); |
|
|
|
|
testTransportUrl("wss", "https", TransportType.XHR_STREAMING); |
|
|
|
|
testTransportUrl("wss", "wss", TransportType.WEBSOCKET); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { |
|
|
|
|
@ParameterizedTest |
|
|
|
|
@CsvSource( { |
|
|
|
|
"http, http, XHR_STREAMING", |
|
|
|
|
"http, ws, WEBSOCKET", |
|
|
|
|
"https, https, XHR_STREAMING", |
|
|
|
|
"https, wss, WEBSOCKET", |
|
|
|
|
"ws, http, XHR_STREAMING", |
|
|
|
|
"ws, ws, WEBSOCKET", |
|
|
|
|
"wss, https, XHR_STREAMING", |
|
|
|
|
"wss, wss, WEBSOCKET" |
|
|
|
|
}) |
|
|
|
|
void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { |
|
|
|
|
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); |
|
|
|
|
String serverId = info.getServerId(); |
|
|
|
|
String sessionId = info.getSessionId(); |
|
|
|
|
|