|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.net.URI;
|
20 | 20 |
|
21 | 21 | import org.junit.jupiter.api.Test;
|
| 22 | +import org.junit.jupiter.params.ParameterizedTest; |
| 23 | +import org.junit.jupiter.params.provider.CsvSource; |
22 | 24 |
|
23 | 25 | import org.springframework.web.socket.sockjs.transport.TransportType;
|
24 | 26 |
|
|
28 | 30 | * Unit tests for {@code SockJsUrlInfo}.
|
29 | 31 | *
|
30 | 32 | * @author Rossen Stoyanchev
|
| 33 | + * @author Sam Brannen |
31 | 34 | */
|
32 |
| -public class SockJsUrlInfoTests { |
| 35 | +class SockJsUrlInfoTests { |
33 | 36 |
|
34 | 37 | @Test
|
35 |
| - public void serverId() throws Exception { |
| 38 | + void serverId() throws Exception { |
36 | 39 | SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
37 | 40 | int serverId = Integer.parseInt(info.getServerId());
|
38 |
| - assertThat(serverId >= 0 && serverId < 1000).as("Invalid serverId: " + serverId).isTrue(); |
| 41 | + assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000); |
39 | 42 | }
|
40 | 43 |
|
41 | 44 | @Test
|
42 |
| - public void sessionId() throws Exception { |
| 45 | + void sessionId() throws Exception { |
43 | 46 | SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
44 |
| - assertThat(info.getSessionId().length()).as("Invalid sessionId: " + info.getSessionId()).isEqualTo(32); |
| 47 | + assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32); |
45 | 48 | }
|
46 | 49 |
|
47 |
| - @Test |
48 |
| - public void infoUrl() throws Exception { |
49 |
| - testInfoUrl("http", "http"); |
50 |
| - testInfoUrl("http", "http"); |
51 |
| - testInfoUrl("https", "https"); |
52 |
| - testInfoUrl("https", "https"); |
53 |
| - testInfoUrl("ws", "http"); |
54 |
| - testInfoUrl("ws", "http"); |
55 |
| - testInfoUrl("wss", "https"); |
56 |
| - testInfoUrl("wss", "https"); |
57 |
| - } |
58 |
| - |
59 |
| - private void testInfoUrl(String scheme, String expectedScheme) throws Exception { |
| 50 | + @ParameterizedTest |
| 51 | + @CsvSource( { |
| 52 | + "http, http", |
| 53 | + "https, https", |
| 54 | + "ws, http", |
| 55 | + "wss, https", |
| 56 | + }) |
| 57 | + void infoUrl(String scheme, String expectedScheme) throws Exception { |
60 | 58 | SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
|
61 | 59 | assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
|
62 | 60 | }
|
63 | 61 |
|
64 |
| - @Test |
65 |
| - public void transportUrl() throws Exception { |
66 |
| - testTransportUrl("http", "http", TransportType.XHR_STREAMING); |
67 |
| - testTransportUrl("http", "ws", TransportType.WEBSOCKET); |
68 |
| - testTransportUrl("https", "https", TransportType.XHR_STREAMING); |
69 |
| - testTransportUrl("https", "wss", TransportType.WEBSOCKET); |
70 |
| - testTransportUrl("ws", "http", TransportType.XHR_STREAMING); |
71 |
| - testTransportUrl("ws", "ws", TransportType.WEBSOCKET); |
72 |
| - testTransportUrl("wss", "https", TransportType.XHR_STREAMING); |
73 |
| - testTransportUrl("wss", "wss", TransportType.WEBSOCKET); |
74 |
| - } |
75 |
| - |
76 |
| - private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { |
| 62 | + @ParameterizedTest |
| 63 | + @CsvSource( { |
| 64 | + "http, http, XHR_STREAMING", |
| 65 | + "http, ws, WEBSOCKET", |
| 66 | + "https, https, XHR_STREAMING", |
| 67 | + "https, wss, WEBSOCKET", |
| 68 | + "ws, http, XHR_STREAMING", |
| 69 | + "ws, ws, WEBSOCKET", |
| 70 | + "wss, https, XHR_STREAMING", |
| 71 | + "wss, wss, WEBSOCKET" |
| 72 | + }) |
| 73 | + void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { |
77 | 74 | SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
|
78 | 75 | String serverId = info.getServerId();
|
79 | 76 | String sessionId = info.getSessionId();
|
|
0 commit comments