parent
cd12583e13
commit
ae5913f3b6
|
@ -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.
|
||||
|
@ -412,15 +412,15 @@ public abstract class AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
protected void testConditionalCacheUpdate(CacheableService<?> service) {
|
||||
Integer one = 1;
|
||||
Integer three = 3;
|
||||
int one = 1;
|
||||
int three = 3;
|
||||
|
||||
Cache cache = this.cm.getCache("testCache");
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
|
||||
assertThat(cache.get(one)).isNull();
|
||||
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
|
||||
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three);
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
|
||||
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
|
||||
}
|
||||
|
||||
protected void testMultiCache(CacheableService<?> service) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -407,15 +407,15 @@ public abstract class AbstractCacheAnnotationTests {
|
|||
}
|
||||
|
||||
protected void testConditionalCacheUpdate(CacheableService<?> service) {
|
||||
Integer one = 1;
|
||||
Integer three = 3;
|
||||
int one = 1;
|
||||
int three = 3;
|
||||
|
||||
Cache cache = this.cm.getCache("testCache");
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
|
||||
assertThat(cache.get(one)).isNull();
|
||||
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
|
||||
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three);
|
||||
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
|
||||
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
|
||||
}
|
||||
|
||||
protected void testMultiCache(CacheableService<?> service) {
|
||||
|
|
|
@ -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;
|
|||
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;
|
|||
* 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();
|
||||
|
|
Loading…
Reference in New Issue