Add test coverage for core server components: annotation scanning, routing, rate limiting, CORS, and JSON handling
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package dev.coph.nextusweb.server.websocket;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class WebSocketConfigTest {
|
||||
|
||||
@Test
|
||||
void defaultsHasExpectedValues() {
|
||||
WebSocketConfig c = WebSocketConfig.defaults();
|
||||
assertEquals(65_536, c.maxFramePayloadLength());
|
||||
assertEquals(1_048_576, c.maxAggregatedMessageSize());
|
||||
assertEquals(Duration.ofSeconds(60), c.idleTimeout());
|
||||
assertFalse(c.allowAnyOrigin());
|
||||
assertTrue(c.allowedOrigins().isEmpty());
|
||||
assertNull(c.subprotocolsCsv());
|
||||
assertTrue(c.compression());
|
||||
assertFalse(c.checkStartsWith());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isOriginAllowedRespectsList() {
|
||||
WebSocketConfig c = WebSocketConfig.builder()
|
||||
.allowedOrigins("https://a", "https://b")
|
||||
.build();
|
||||
assertTrue(c.isOriginAllowed("https://a"));
|
||||
assertTrue(c.isOriginAllowed("https://b"));
|
||||
assertFalse(c.isOriginAllowed("https://c"));
|
||||
assertFalse(c.isOriginAllowed(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anyOriginAllowsEverythingExceptNullCheck() {
|
||||
WebSocketConfig c = WebSocketConfig.builder().anyOrigin().build();
|
||||
assertTrue(c.allowAnyOrigin());
|
||||
assertTrue(c.isOriginAllowed("https://anything"));
|
||||
assertTrue(c.isOriginAllowed(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidFramePayloadLengthRejected() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> WebSocketConfig.builder().maxFramePayloadLength(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidAggregatedMessageSizeRejected() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> WebSocketConfig.builder().maxAggregatedMessageSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noIdleTimeoutSetsNull() {
|
||||
WebSocketConfig c = WebSocketConfig.builder().noIdleTimeout().build();
|
||||
assertNull(c.idleTimeout());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subprotocolsCsvJoins() {
|
||||
WebSocketConfig c = WebSocketConfig.builder().subprotocols("a", "b").build();
|
||||
String csv = c.subprotocolsCsv();
|
||||
assertNotNull(csv);
|
||||
assertTrue(csv.contains("a"));
|
||||
assertTrue(csv.contains("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void compressionAndCheckStartsWithFlags() {
|
||||
WebSocketConfig c = WebSocketConfig.builder()
|
||||
.compression(false)
|
||||
.checkStartsWith(true)
|
||||
.build();
|
||||
assertFalse(c.compression());
|
||||
assertTrue(c.checkStartsWith());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user