mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-05 21:39:18 +00:00
Migrating websocket tests to junit5
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
62da301e19
commit
2d44cc3189
@ -19,9 +19,12 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -56,7 +59,7 @@ public abstract class AbstractTrackingEndpoint<T>
|
||||
{
|
||||
CloseInfo close = closeInfo.get();
|
||||
assertThat(prefix + " close info", close, Matchers.notNullValue());
|
||||
assertThat(prefix + " received close code", close.getStatusCode(), Matchers.is(expectedCloseStatusCode));
|
||||
assertThat(prefix + " received close code", close.getStatusCode(), is(expectedCloseStatusCode));
|
||||
assertThat(prefix + " received close reason", close.getReason(), reasonMatcher);
|
||||
}
|
||||
|
||||
@ -68,32 +71,32 @@ public abstract class AbstractTrackingEndpoint<T>
|
||||
|
||||
public void assertNoErrorEvents(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " error event should not have occurred", error.get() == null);
|
||||
assertThat(prefix + " error event should not have occurred", error.get(), is(nullValue()));
|
||||
}
|
||||
|
||||
|
||||
public void assertNotClosed(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " close event should not have occurred: got " + closeInfo.get(), closeLatch.getCount() > 0);
|
||||
assertThat(prefix + " close event should not have occurred: got " + closeInfo.get(), closeLatch.getCount(), greaterThan(0L));
|
||||
}
|
||||
|
||||
public void assertNotOpened(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " open event should not have occurred", openLatch.getCount() > 0);
|
||||
assertThat(prefix + " open event should not have occurred", openLatch.getCount(), greaterThan(0L));
|
||||
}
|
||||
|
||||
public void awaitCloseEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onClose event should have occurred", closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onClose event should have occurred");
|
||||
}
|
||||
|
||||
public void awaitOpenEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onOpen event should have occurred", openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onOpen event should have occurred");
|
||||
}
|
||||
|
||||
public void awaitErrorEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onError event should have occurred", errorLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(errorLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onError event should have occurred");
|
||||
}
|
||||
|
||||
protected void onWSOpen(T session)
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.eclipse.jetty.toolchain.test.matchers.RegexMatcher.matchesPattern;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@ -38,6 +38,7 @@ import org.eclipse.jetty.websocket.common.LogicalConnection;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class TrackingEndpoint extends AbstractTrackingEndpoint<WebSocketSession> implements WebSocketListener, WebSocketFrameListener
|
||||
{
|
||||
@ -47,7 +48,13 @@ public class TrackingEndpoint extends AbstractTrackingEndpoint<WebSocketSession>
|
||||
public BlockingQueue<WebSocketFrame> framesQueue = new LinkedBlockingDeque<>();
|
||||
public BlockingQueue<String> messageQueue = new LinkedBlockingDeque<>();
|
||||
public BlockingQueue<ByteBuffer> bufferQueue = new LinkedBlockingDeque<>();
|
||||
|
||||
|
||||
public TrackingEndpoint(TestInfo testInfo)
|
||||
{
|
||||
super(testInfo.getDisplayName());
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
public TrackingEndpoint(String id)
|
||||
{
|
||||
super(id);
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -46,7 +46,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.websocket.api.util.WSURI;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.BiConsumerServiceServlet;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class UntrustedWSServer extends ContainerLifeCycle implements UntrustedWSSessionFactory.Listener
|
||||
{
|
||||
@ -157,9 +157,9 @@ public class UntrustedWSServer extends ContainerLifeCycle implements UntrustedWS
|
||||
return wsUri;
|
||||
}
|
||||
|
||||
public URI getUntrustedWsUri(Class<?> clazz, TestName testname)
|
||||
public URI getUntrustedWsUri(Class<?> clazz, TestInfo testInfo)
|
||||
{
|
||||
return wsUri.resolve("/untrusted/" + clazz.getSimpleName() + "/" + testname.getMethodName());
|
||||
return wsUri.resolve("/untrusted/" + clazz.getSimpleName() + "/" + testInfo.getDisplayName());
|
||||
}
|
||||
|
||||
public void registerHttpService(String urlPattern, BiConsumer<HttpServletRequest, HttpServletResponse> serviceConsumer)
|
||||
|
@ -20,9 +20,9 @@ package org.eclipse.jetty.websocket.tests.jsr356;
|
||||
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@ -84,27 +84,27 @@ public abstract class AbstractJsrTrackingEndpoint extends Endpoint
|
||||
|
||||
public void assertNoErrorEvents(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " error event should not have occurred", error.get() == null);
|
||||
assertTrue(error.get() == null, prefix + " error event should not have occurred");
|
||||
}
|
||||
|
||||
public void assertNotClosed(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " close event should not have occurred", closeLatch.getCount() > 0);
|
||||
assertTrue(closeLatch.getCount() > 0, prefix + " close event should not have occurred");
|
||||
}
|
||||
|
||||
public void assertNotOpened(String prefix)
|
||||
{
|
||||
assertTrue(prefix + " open event should not have occurred", openLatch.getCount() > 0);
|
||||
assertTrue(openLatch.getCount() > 0, prefix + " open event should not have occurred");
|
||||
}
|
||||
|
||||
public void awaitCloseEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onClose event", closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onClose event");
|
||||
}
|
||||
|
||||
public void awaitOpenEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onOpen event", openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onOpen event");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -135,7 +135,7 @@ public abstract class AbstractJsrTrackingEndpoint extends Endpoint
|
||||
CloseInfo close = new CloseInfo(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase());
|
||||
boolean closeTracked = closeInfo.compareAndSet(null, close);
|
||||
this.closeLatch.countDown();
|
||||
assertTrue("Close only happened once", closeTracked);
|
||||
assertTrue(closeTracked, "Close only happened once");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,8 +20,9 @@ package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
@ -41,24 +42,15 @@ import org.eclipse.jetty.websocket.tests.sockets.annotations.MyEchoBinarySocket;
|
||||
import org.eclipse.jetty.websocket.tests.sockets.annotations.MyEchoSocket;
|
||||
import org.eclipse.jetty.websocket.tests.sockets.annotations.MyStatelessEchoSocket;
|
||||
import org.eclipse.jetty.websocket.tests.sockets.annotations.NoopSocket;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AnnotatedEndpointDiscoverTest
|
||||
{
|
||||
private WebSocketContainerScope containerScope = new SimpleContainerScope(WebSocketPolicy.newServerPolicy());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
public LocalWebSocketSession createSession(Object endpoint) throws Exception
|
||||
{
|
||||
LocalWebSocketSession session = new LocalWebSocketSession(containerScope, testname.getMethodName(), endpoint);
|
||||
LocalWebSocketSession session = new LocalWebSocketSession(containerScope, "test", endpoint);
|
||||
session.start();
|
||||
return session;
|
||||
}
|
||||
@ -67,48 +59,51 @@ public class AnnotatedEndpointDiscoverTest
|
||||
* Test Case for bad declaration (duplicate OnWebSocketBinary declarations)
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotatedBadDuplicateBinarySocket() throws Exception
|
||||
public void testAnnotatedBadDuplicateBinarySocket()
|
||||
{
|
||||
// Should toss exception
|
||||
thrown.expect(InvalidWebSocketException.class);
|
||||
thrown.expectMessage(allOf(containsString("Cannot replace previously assigned"), containsString("BINARY Handler")));
|
||||
createSession(new BadDuplicateBinarySocket());
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class, () ->
|
||||
createSession(new BadDuplicateBinarySocket())
|
||||
);
|
||||
assertThat(x.getMessage(), allOf(containsString("Cannot replace previously assigned"),
|
||||
containsString("BINARY Handler")));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Case for bad declaration (duplicate frame type methods)
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotatedBadDuplicateFrameSocket() throws Exception
|
||||
public void testAnnotatedBadDuplicateFrameSocket()
|
||||
{
|
||||
// Should toss exception
|
||||
thrown.expect(InvalidWebSocketException.class);
|
||||
thrown.expectMessage(containsString("Duplicate @OnWebSocketFrame"));
|
||||
createSession(new BadDuplicateFrameSocket());
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class, () ->
|
||||
createSession(new BadDuplicateFrameSocket()));
|
||||
assertThat(x.getMessage(), containsString("Duplicate @OnWebSocketFrame"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Case for bad declaration a method with a non-void return type
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotatedBadSignature_NonVoidReturn() throws Exception
|
||||
public void testAnnotatedBadSignature_NonVoidReturn()
|
||||
{
|
||||
// Should toss exception
|
||||
thrown.expect(InvalidWebSocketException.class);
|
||||
thrown.expectMessage(containsString("must be void"));
|
||||
createSession(new BadBinarySignatureSocket());
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class, () ->
|
||||
createSession(new BadBinarySignatureSocket()));
|
||||
assertThat(x.getMessage(), containsString("must be void"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Case for bad declaration a method with a public static method
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotatedBadSignature_Static() throws Exception
|
||||
public void testAnnotatedBadSignature_Static()
|
||||
{
|
||||
// Should toss exception
|
||||
thrown.expect(InvalidWebSocketException.class);
|
||||
thrown.expectMessage(containsString("must not be static"));
|
||||
createSession(new BadTextSignatureSocket());
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class, () ->
|
||||
createSession(new BadTextSignatureSocket()));
|
||||
assertThat(x.getMessage(), containsString("must not be static"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,10 +19,10 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.eclipse.jetty.websocket.common.AtomicConnectionState;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AtomicConnectionStateTest
|
||||
{
|
||||
|
@ -18,8 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -50,17 +51,12 @@ import org.eclipse.jetty.websocket.common.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.PongFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GeneratorTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(GeneratorTest.WindowHelper.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private static UnitGenerator unitGenerator = new UnitGenerator(WebSocketPolicy.newServerPolicy(), true);
|
||||
|
||||
/**
|
||||
@ -363,9 +359,9 @@ public class GeneratorTest
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
closeFrame.setPayload(Hex.asByteBuffer("00"));
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
unitGenerator.generate(closeFrame);
|
||||
|
||||
assertThrows(ProtocolException.class, ()->
|
||||
unitGenerator.generate(closeFrame));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -416,9 +412,9 @@ public class GeneratorTest
|
||||
bb.put(messageBytes);
|
||||
|
||||
BufferUtil.flipToFlush(bb,0);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
closeFrame.setPayload(bb);
|
||||
|
||||
assertThrows(ProtocolException.class, ()->
|
||||
closeFrame.setPayload(bb));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -656,10 +652,11 @@ public class GeneratorTest
|
||||
{
|
||||
byte[] bytes = new byte[126];
|
||||
Arrays.fill(bytes,(byte)0x00);
|
||||
|
||||
expectedException.expect(WebSocketException.class);
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
pingFrame.setPayload(ByteBuffer.wrap(bytes)); // should throw exception
|
||||
|
||||
assertThrows(WebSocketException.class, () -> {
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
pingFrame.setPayload(ByteBuffer.wrap(bytes)); // should throw exception
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -671,9 +668,10 @@ public class GeneratorTest
|
||||
byte[] bytes = new byte[126];
|
||||
Arrays.fill(bytes, (byte)0x00);
|
||||
|
||||
expectedException.expect(WebSocketException.class);
|
||||
PongFrame pingFrame = new PongFrame();
|
||||
pingFrame.setPayload(ByteBuffer.wrap(bytes)); // should throw exception
|
||||
assertThrows(WebSocketException.class, () ->{
|
||||
PongFrame pingFrame = new PongFrame();
|
||||
pingFrame.setPayload(ByteBuffer.wrap(bytes)); // should throw exception
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,9 @@ import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -55,16 +57,10 @@ import org.eclipse.jetty.websocket.common.frames.PongFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.common.util.MaskedByteBuffer;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ParserTest
|
||||
{
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private ParserCapture parse(WebSocketPolicy policy, ByteBuffer buffer)
|
||||
{
|
||||
ParserCapture capture = new ParserCapture();
|
||||
@ -100,7 +96,7 @@ public class ParserTest
|
||||
ParserCapture capture = parse(policy, expected);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame) capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +129,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.BINARY,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -165,7 +161,7 @@ public class ParserTest
|
||||
ParserCapture capture = parse(policy, expected);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame) capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// .assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -199,7 +195,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.BINARY,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +229,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.BINARY,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,7 +263,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.BINARY,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,7 +286,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.BINARY,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,9 +298,9 @@ public class ParserTest
|
||||
ByteBuffer expected = Hex.asByteBuffer("880100");
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(CoreMatchers.containsString("Invalid close frame payload length"));
|
||||
parse(policy, expected);
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Invalid close frame payload length"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -326,7 +322,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,9 +360,8 @@ public class ParserTest
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(CoreMatchers.containsString("Invalid control frame payload length"));
|
||||
parse(policy, expected);
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Invalid control frame payload length"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,7 +383,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(2));
|
||||
assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(2));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -424,7 +419,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(125));
|
||||
assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(125));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,7 +448,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(messageBytes.length + 2));
|
||||
assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(messageBytes.length + 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,8 +470,7 @@ public class ParserTest
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
ByteBuffer completeBuf = new UnitGenerator(policy).asBuffer(send);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
parse(policy, completeBuf);
|
||||
assertThrows(ProtocolException.class, ()-> parse(policy, completeBuf));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -590,9 +584,9 @@ public class ParserTest
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(containsString("Unknown opcode: 11"));
|
||||
parse(policy, expected);
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Unknown opcode: 11"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -608,10 +602,9 @@ public class ParserTest
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(containsString("Unknown opcode: 12"));
|
||||
parse(policy, expected);
|
||||
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Unknown opcode: 12"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -627,10 +620,9 @@ public class ParserTest
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(containsString("Unknown opcode: 3"));
|
||||
parse(policy, expected);
|
||||
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Unknown opcode: 3"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,10 +638,9 @@ public class ParserTest
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
expectedException.expectMessage(containsString("Unknown opcode: 4"));
|
||||
parse(policy, expected);
|
||||
|
||||
ProtocolException x = assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
assertThat(x.getMessage(), containsString("Unknown opcode: 4"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -683,8 +674,8 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
Assert.assertEquals("PingFrame.payload",bytes.length,pActual.getPayloadLength());
|
||||
assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
assertEquals(bytes.length,pActual.getPayloadLength(),"PingFrame.payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -703,7 +694,7 @@ public class ParserTest
|
||||
PingFrame ping = (PingFrame)capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
String actual = BufferUtil.toUTF8String(ping.getPayload());
|
||||
Assert.assertThat("PingFrame.payload",actual,is("Hello"));
|
||||
assertThat("PingFrame.payload",actual,is("Hello"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -732,8 +723,8 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
Assert.assertEquals("PingFrame.payload",bytes.length,pActual.getPayloadLength());
|
||||
assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
assertEquals(bytes.length,pActual.getPayloadLength(),"PingFrame.payload");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -755,8 +746,8 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
Assert.assertEquals("PingFrame.payload",0,pActual.getPayloadLength());
|
||||
assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
assertEquals(0,pActual.getPayloadLength(),"PingFrame.payload");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -786,8 +777,8 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(message.length()));
|
||||
Assert.assertEquals("PingFrame.payload",message.length(),pActual.getPayloadLength());
|
||||
assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(message.length()));
|
||||
assertEquals(message.length(),pActual.getPayloadLength(),"PingFrame.payload");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -825,8 +816,7 @@ public class ParserTest
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
parse(policy, expected);
|
||||
assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -889,8 +879,7 @@ public class ParserTest
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
parse(policy, expected);
|
||||
assertThrows(ProtocolException.class, () -> parse(policy, expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1154,7 +1143,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -1188,7 +1177,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -1222,7 +1211,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -1256,7 +1245,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
// .assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
|
||||
}
|
||||
|
||||
@ -1291,7 +1280,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1326,7 +1315,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1346,8 +1335,7 @@ public class ParserTest
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
ByteBuffer completeBuf = new UnitGenerator(policy).asBuffer(send);
|
||||
|
||||
expectedException.expect(ProtocolException.class);
|
||||
parse(policy, completeBuf);
|
||||
assertThrows(ProtocolException.class, () -> parse(policy, completeBuf));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1369,7 +1357,7 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
|
||||
Frame pActual = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1383,7 +1371,7 @@ public class ParserTest
|
||||
byte utf[] = new byte[2048];
|
||||
Arrays.fill(utf,(byte)'a');
|
||||
|
||||
Assert.assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 8);
|
||||
buf.put((byte)0x81); // text frame, fin = true
|
||||
@ -1393,8 +1381,7 @@ public class ParserTest
|
||||
MaskedByteBuffer.putPayload(buf,utf);
|
||||
buf.flip();
|
||||
|
||||
expectedException.expect(MessageTooLargeException.class);
|
||||
parse(policy, buf);
|
||||
assertThrows(MessageTooLargeException.class, () -> parse(policy, buf));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1410,7 +1397,7 @@ public class ParserTest
|
||||
String expectedText = sb.toString();
|
||||
byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
Assert.assertThat("Must be a long length payload",utf.length,greaterThan(0xFFFF));
|
||||
assertThat("Must be a long length payload",utf.length,greaterThan(0xFFFF));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 32);
|
||||
buf.put((byte)0x81); // text frame, fin = true
|
||||
@ -1426,7 +1413,7 @@ public class ParserTest
|
||||
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
WebSocketFrame txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1487,7 +1474,7 @@ public class ParserTest
|
||||
String expectedText = sb.toString();
|
||||
byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
Assert.assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 10);
|
||||
buf.put((byte)0x81);
|
||||
@ -1502,7 +1489,7 @@ public class ParserTest
|
||||
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
WebSocketFrame txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1523,7 +1510,7 @@ public class ParserTest
|
||||
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
WebSocketFrame txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1557,9 +1544,9 @@ public class ParserTest
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
capture.assertHasFrame(OpCode.CONTINUATION,1);
|
||||
WebSocketFrame txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame[0].data",txt.getPayloadAsUTF8(),is(part1));
|
||||
assertThat("TextFrame[0].data",txt.getPayloadAsUTF8(),is(part1));
|
||||
txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame[1].data",txt.getPayloadAsUTF8(),is(part2));
|
||||
assertThat("TextFrame[1].data",txt.getPayloadAsUTF8(),is(part2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1581,6 +1568,6 @@ public class ParserTest
|
||||
|
||||
capture.assertHasFrame(OpCode.TEXT,1);
|
||||
WebSocketFrame txt = capture.framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
Assert.assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
assertThat("TextFrame.data",txt.getPayloadAsUTF8(),is(expectedText));
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
@ -29,7 +29,7 @@ import org.eclipse.jetty.util.annotation.Name;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.common.reflect.Arg;
|
||||
import org.eclipse.jetty.websocket.common.reflect.UnorderedSignature;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UnorderedSignatureTest
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -38,9 +38,9 @@ import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UntrustedWSClientTest
|
||||
{
|
||||
@ -72,7 +72,7 @@ public class UntrustedWSClientTest
|
||||
private static Server server;
|
||||
private static URI wsServerURI;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new Server(0);
|
||||
@ -89,7 +89,7 @@ public class UntrustedWSClientTest
|
||||
wsServerURI = WSURI.toWebsocket(serverURI);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,11 +18,11 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -46,24 +46,20 @@ import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class ClientCloseHandshakeTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ClientCloseHandshakeTest.class);
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
HttpClient httpClient = new HttpClient();
|
||||
@ -72,7 +68,7 @@ public class ClientCloseHandshakeTest
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
@ -80,13 +76,13 @@ public class ClientCloseHandshakeTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
@ -113,18 +109,18 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testClientInitiated_NoData() throws Exception
|
||||
public void testClientInitiated_NoData(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Wait for client connect on via future
|
||||
@ -136,7 +132,7 @@ public class ClientCloseHandshakeTest
|
||||
clientSession.getRemote().setBatchMode(BatchMode.OFF);
|
||||
|
||||
// Wait for client connect via client websocket
|
||||
assertTrue("Client WebSocket is Open", clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client WebSocket is Open");
|
||||
|
||||
// client should not have received close message (yet)
|
||||
clientSocket.assertNotClosed("Client");
|
||||
@ -177,18 +173,18 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testClientInitiated_NoData_ChangeClose() throws Exception
|
||||
public void testClientInitiated_NoData_ChangeClose(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Server accepts connect
|
||||
@ -206,7 +202,7 @@ public class ClientCloseHandshakeTest
|
||||
clientSession.getRemote().setBatchMode(BatchMode.OFF);
|
||||
|
||||
// Wait for client connect via client websocket
|
||||
assertTrue("Client WebSocket is Open", clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client WebSocket is Open");
|
||||
|
||||
// client should not have received close message (yet)
|
||||
clientSocket.assertNotClosed("Client");
|
||||
@ -245,18 +241,18 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testServerInitiated_NoData() throws Exception
|
||||
public void testServerInitiated_NoData(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Wait for server connect
|
||||
@ -271,7 +267,7 @@ public class ClientCloseHandshakeTest
|
||||
clientSession.getRemote().setBatchMode(BatchMode.OFF);
|
||||
|
||||
// Wait for client connect via client websocket
|
||||
assertTrue("Client WebSocket is Open", clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client WebSocket is Open");
|
||||
|
||||
// client should not have received close message (yet)
|
||||
clientSocket.assertNotClosed("Client");
|
||||
@ -338,19 +334,19 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Needs review")
|
||||
public void testClient_IdleTimeout() throws Exception
|
||||
@Disabled("Needs review")
|
||||
public void testClient_IdleTimeout(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Server accepts connect
|
||||
@ -365,7 +361,7 @@ public class ClientCloseHandshakeTest
|
||||
clientSession.getRemote().setBatchMode(BatchMode.OFF);
|
||||
|
||||
// Wait for client connect via client websocket
|
||||
assertTrue("Client WebSocket is Open", clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client WebSocket is Open");
|
||||
|
||||
// client should not have received close message (yet)
|
||||
clientSocket.assertNotClosed("Client");
|
||||
@ -417,7 +413,7 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testClient_ProtocolViolation_Received() throws Exception
|
||||
public void testClient_ProtocolViolation_Received(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
@ -426,7 +422,7 @@ public class ClientCloseHandshakeTest
|
||||
URI wsUri = server.getWsUri().resolve("/badclose");
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Wait for client connect on via future
|
||||
@ -476,15 +472,15 @@ public class ClientCloseHandshakeTest
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Needs review")
|
||||
public void testWriteException() throws Exception
|
||||
@Disabled("Needs review")
|
||||
public void testWriteException(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
@ -513,6 +509,6 @@ public class ClientCloseHandshakeTest
|
||||
// client triggers close event on client ws-endpoint
|
||||
// assert - close code==1006 (abnormal)
|
||||
// assert - close reason message contains (write failure)
|
||||
assertTrue("Client onClose not called", clientSocket.closeLatch.getCount() > 0);
|
||||
assertTrue(clientSocket.closeLatch.getCount() > 0, "Client onClose not called");
|
||||
}
|
||||
}
|
||||
|
@ -57,19 +57,15 @@ import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class ClientCloseTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ClientCloseTest.class);
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@ -146,7 +142,7 @@ public class ClientCloseTest
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
HttpClient httpClient = new HttpClient(new TestClientTransportOverHTTP(), null);
|
||||
@ -155,38 +151,38 @@ public class ClientCloseTest
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkCongestion() throws Exception
|
||||
public void testNetworkCongestion(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
@ -227,8 +223,8 @@ public class ClientCloseTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000L)
|
||||
public void testStopLifecycle() throws Exception
|
||||
@Test
|
||||
public void testStopLifecycle(TestInfo testInfo) throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
@ -242,12 +238,12 @@ public class ClientCloseTest
|
||||
// Connect Multiple Clients
|
||||
for (int i = 0; i < clientCount; i++)
|
||||
{
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname).resolve(Integer.toString(i));
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo).resolve(Integer.toString(i));
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
// Client Request Upgrade
|
||||
clientSockets[i] = new TrackingEndpoint(testname.getMethodName() + "[" + i + "]");
|
||||
clientSockets[i] = new TrackingEndpoint(testInfo.getDisplayName() + "[" + i + "]");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSockets[i], wsUri);
|
||||
|
||||
// Server accepts connection
|
||||
|
@ -21,10 +21,11 @@ package org.eclipse.jetty.websocket.tests.client;
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -50,12 +51,10 @@ import org.eclipse.jetty.websocket.tests.UntrustedWSEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
/**
|
||||
* Various connect condition testing
|
||||
@ -64,9 +63,6 @@ public class ClientConnectTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ClientConnectTest.class);
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
public LeakTrackingByteBufferPool bufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool());
|
||||
|
||||
private final int timeout = 500;
|
||||
@ -89,7 +85,7 @@ public class ClientConnectTest
|
||||
assertThat("UpgradeException message", actualCause.getMessage(), messageMatcher);
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
@ -98,7 +94,7 @@ public class ClientConnectTest
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
@ -106,13 +102,13 @@ public class ClientConnectTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LOG.info("Ignore the stop thread warnings (this is expected for these tests)");
|
||||
@ -120,11 +116,11 @@ public class ClientConnectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeRequest() throws Exception
|
||||
public void testUpgradeRequest(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
Session sess = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
@ -138,10 +134,10 @@ public class ClientConnectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltConnect() throws Exception
|
||||
public void testAltConnect(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.start();
|
||||
@ -160,10 +156,10 @@ public class ClientConnectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeWithAuthorizationHeader() throws Exception
|
||||
public void testUpgradeWithAuthorizationHeader(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<UntrustedWSSession>()
|
||||
{
|
||||
@Override
|
||||
@ -195,9 +191,9 @@ public class ClientConnectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake() throws Exception
|
||||
public void testBadHandshake(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/empty-404", (req, resp) ->
|
||||
{
|
||||
resp.setStatus(404);
|
||||
@ -207,23 +203,16 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 404 Not Found"));
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 404 Not Found"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake_GetOK() throws Exception
|
||||
public void testBadHandshake_GetOK(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/empty-200", (req, resp) ->
|
||||
{
|
||||
resp.setStatus(200);
|
||||
@ -234,23 +223,16 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 200 OK"));
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 200 OK"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake_GetOK_WithSecWebSocketAccept() throws Exception
|
||||
public void testBadHandshake_GetOK_WithSecWebSocketAccept(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/bad-accept-200", (req, resp) ->
|
||||
{
|
||||
// Simulate a bad server that doesn't follow RFC6455 completely.
|
||||
@ -264,24 +246,16 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException -> UpgradeException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 200 OK"));
|
||||
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("Not a 101 Switching Protocols Response: 200 OK"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake_SwitchingProtocols_InvalidConnectionHeader() throws Exception
|
||||
public void testBadHandshake_SwitchingProtocols_InvalidConnectionHeader(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/bad-connection-header", (req, resp) ->
|
||||
{
|
||||
// Simulate a bad server that doesn't follow RFC6455 completely.
|
||||
@ -295,23 +269,16 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException -> UpgradeException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("101 Switching Protocols without Connection: Upgrade not supported"));
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("101 Switching Protocols without Connection: Upgrade not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake_SwitchingProtocols_NoConnectionHeader() throws Exception
|
||||
public void testBadHandshake_SwitchingProtocols_NoConnectionHeader(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/bad-switching-protocols-no-connection-header", (req, resp) ->
|
||||
{
|
||||
// Simulate a bad server that doesn't follow RFC6455 completely.
|
||||
@ -325,23 +292,16 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("101 Switching Protocols without Connection: Upgrade not supported"));
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("101 Switching Protocols without Connection: Upgrade not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadHandshake_InvalidWsAccept() throws Exception
|
||||
public void testBadHandshake_InvalidWsAccept(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/bad-switching-protocols-invalid-ws-accept", (req, resp) ->
|
||||
{
|
||||
// Simulate a bad server that doesn't follow RFC6455 completely.
|
||||
@ -355,17 +315,10 @@ public class ClientConnectTest
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
try
|
||||
{
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
// Expected Path
|
||||
assertExecutionException(e, instanceOf(HttpResponseException.class),
|
||||
containsString("Invalid Sec-WebSocket-Accept hash"));
|
||||
}
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertExecutionException(x, instanceOf(HttpResponseException.class),
|
||||
containsString("Invalid Sec-WebSocket-Accept hash"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -378,9 +331,9 @@ public class ClientConnectTest
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testHandshakeQuirk_TransferEncoding() throws Exception
|
||||
public void testHandshakeQuirk_TransferEncoding(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerWebSocket("/quirk/tomcat", (upgradeRequest, upgradeResponse) ->
|
||||
{
|
||||
// Extra header that Tomcat 7.x returns
|
||||
@ -403,41 +356,38 @@ public class ClientConnectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnection_Refused() throws Exception
|
||||
public void testConnection_Refused(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
// This should be a ws:// uri to a machine that exists, but to a port
|
||||
// that isn't listening.
|
||||
// Intentionally bad port with nothing listening on it
|
||||
URI wsUri = new URI("ws://127.0.0.1:1");
|
||||
|
||||
try
|
||||
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
{
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
|
||||
// The attempt to get upgrade response future should throw error
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
assertExecutionException(e,
|
||||
anyOf(
|
||||
instanceOf(java.net.SocketTimeoutException.class), // seen on windows
|
||||
instanceOf(java.net.ConnectException.class) // seen everywhere else
|
||||
),
|
||||
anyOf(
|
||||
containsString("Connect"),
|
||||
containsString("Timeout")
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
assertExecutionException(x,
|
||||
anyOf(
|
||||
instanceOf(java.net.SocketTimeoutException.class), // seen on windows
|
||||
instanceOf(java.net.ConnectException.class) // seen everywhere else
|
||||
),
|
||||
anyOf(
|
||||
containsString("Connect"),
|
||||
containsString("Timeout")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionTimeout_AcceptNoUpgradeResponse() throws Exception
|
||||
public void testConnectionTimeout_AcceptNoUpgradeResponse(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
server.registerHttpService("/accept-no-upgrade-timeout", (req, resp) ->
|
||||
{
|
||||
// Intentionally take a long time here
|
||||
@ -455,16 +405,11 @@ public class ClientConnectTest
|
||||
client.setMaxIdleTimeout(500); // we do connect, just sit idle for the upgrade step
|
||||
Future<Session> future = client.connect(clientSocket, wsUri);
|
||||
|
||||
try
|
||||
{
|
||||
// The attempt to get upgrade response future should throw error
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
Assert.fail("Expected ExecutionException");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
assertUpgradeException(e, instanceOf(java.util.concurrent.TimeoutException.class), containsString("timeout"));
|
||||
}
|
||||
// The attempt to get upgrade response future should throw error
|
||||
ExecutionException x = assertThrows(ExecutionException.class, ()->
|
||||
future.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertUpgradeException(x, instanceOf(java.util.concurrent.TimeoutException.class),
|
||||
containsString("timeout"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ package org.eclipse.jetty.websocket.tests.client;
|
||||
import static org.hamcrest.CoreMatchers.anything;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -38,7 +39,6 @@ import org.eclipse.jetty.util.log.StacklessLogging;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketTimeoutException;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
@ -52,13 +52,10 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
/**
|
||||
* Tests various early disconnected connection situations
|
||||
@ -217,36 +214,30 @@ public class ClientDisconnectedTest
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private SimpleServletServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new EarlyCloseServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
@ -258,20 +249,21 @@ public class ClientDisconnectedTest
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void immediateDrop() throws Exception
|
||||
public void immediateDrop(TestInfo testInfo) throws Exception
|
||||
{
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("openclose");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
|
||||
URI wsUri = server.getServerUri().resolve("/");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
||||
expectedException.expect(ExecutionException.class);
|
||||
expectedException.expectCause(instanceOf(HttpResponseException.class));
|
||||
expectedException.expectMessage(containsString("503 Endpoint Creation Failed"));
|
||||
clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
ExecutionException ee = assertThrows(ExecutionException.class, () -> {
|
||||
clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
});
|
||||
assertThat(ee, instanceOf(HttpResponseException.class));
|
||||
assertThat(ee.getMessage(), containsString("503 Endpoint Creation Failed"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,12 +272,12 @@ public class ClientDisconnectedTest
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void remoteOpenFailure() throws Exception
|
||||
public void remoteOpenFailure(TestInfo testInfo) throws Exception
|
||||
{
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("openfail");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
|
||||
URI wsUri = server.getServerUri().resolve("/");
|
||||
|
||||
@ -312,130 +304,4 @@ public class ClientDisconnectedTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection has performed handshake successfully.
|
||||
* <p>
|
||||
* Send of message to remote results in dropped connection on server side.
|
||||
* </p>
|
||||
*
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Needs review")
|
||||
public void messageDrop() throws Exception
|
||||
{
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("msgdrop");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
|
||||
URI wsUri = server.getServerUri().resolve("/");
|
||||
client.setMaxIdleTimeout(3000);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
||||
Session session = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
try
|
||||
{
|
||||
clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertThat("OnOpen.UpgradeRequest", clientSocket.openUpgradeRequest, notNullValue());
|
||||
assertThat("OnOpen.UpgradeResponse", clientSocket.openUpgradeResponse, notNullValue());
|
||||
assertThat("Negotiated SubProtocol", clientSocket.openUpgradeResponse.getAcceptedSubProtocol(), is("msgdrop"));
|
||||
|
||||
session.getRemote().sendString("drop-me");
|
||||
|
||||
clientSocket.awaitErrorEvent("Client");
|
||||
clientSocket.assertErrorEvent("Client", instanceOf(WebSocketTimeoutException.class), containsString("Connection Idle Timeout"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection has performed handshake successfully.
|
||||
* <p>
|
||||
* Client sends close handshake, remote drops connection with no reply
|
||||
* </p>
|
||||
*
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Needs review")
|
||||
public void closeDrop() throws Exception
|
||||
{
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("closedrop");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
|
||||
URI wsUri = server.getServerUri().resolve("/");
|
||||
client.setMaxIdleTimeout(3000);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
||||
Session session = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
try
|
||||
{
|
||||
clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertThat("OnOpen.UpgradeRequest", clientSocket.openUpgradeRequest, notNullValue());
|
||||
assertThat("OnOpen.UpgradeResponse", clientSocket.openUpgradeResponse, notNullValue());
|
||||
assertThat("Negotiated SubProtocol", clientSocket.openUpgradeResponse.getAcceptedSubProtocol(), is("closedrop"));
|
||||
|
||||
clientSocket.close(StatusCode.NORMAL, "All Done");
|
||||
|
||||
clientSocket.awaitErrorEvent("Client");
|
||||
clientSocket.assertErrorEvent("Client", instanceOf(WebSocketTimeoutException.class), containsString("Connection Idle Timeout"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection has performed handshake successfully.
|
||||
* <p>
|
||||
* Client sends close handshake, remote never replies (but leaves connection open)
|
||||
* </p>
|
||||
*
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Needs review")
|
||||
public void closeNoReply() throws Exception
|
||||
{
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("closenoreply");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
|
||||
URI wsUri = server.getServerUri().resolve("/");
|
||||
client.setMaxIdleTimeout(3000);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
||||
Session session = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
try
|
||||
{
|
||||
clientSocket.openLatch.await(Defaults.OPEN_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertThat("OnOpen.UpgradeRequest", clientSocket.openUpgradeRequest, notNullValue());
|
||||
assertThat("OnOpen.UpgradeResponse", clientSocket.openUpgradeResponse, notNullValue());
|
||||
assertThat("Negotiated SubProtocol", clientSocket.openUpgradeResponse.getAcceptedSubProtocol(), is("closenoreply"));
|
||||
|
||||
clientSocket.close(StatusCode.NORMAL, "All Done");
|
||||
|
||||
clientSocket.awaitErrorEvent("Client");
|
||||
clientSocket.assertErrorEvent("Client", instanceOf(WebSocketTimeoutException.class), containsString("Connection Idle Timeout"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.CookieManager;
|
||||
import java.net.HttpCookie;
|
||||
@ -40,53 +40,49 @@ import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class CookieTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(CookieTest.class);
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViaCookieManager() throws Exception
|
||||
public void testViaCookieManager(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
@ -119,10 +115,10 @@ public class CookieTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViaServletUpgradeRequest() throws Exception
|
||||
public void testViaServletUpgradeRequest(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.Future;
|
||||
@ -33,22 +33,18 @@ import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class SlowClientTest
|
||||
{
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
@ -56,33 +52,33 @@ public class SlowClientTest
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Not working yet")
|
||||
public void testClientSlowToSend() throws Exception
|
||||
@Disabled("Not working yet")
|
||||
public void testClientSlowToSend(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
client.getPolicy().setIdleTimeout(60000);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri);
|
||||
@ -113,7 +109,7 @@ public class SlowClientTest
|
||||
|
||||
// Close
|
||||
clientSession.close();
|
||||
assertTrue("Client close event", clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client close event");
|
||||
clientEndpoint.assertCloseInfo("Client", StatusCode.NORMAL, is("Done"));
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.Future;
|
||||
@ -33,23 +33,19 @@ import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
@Ignore("Not working yet")
|
||||
@Disabled("Not working yet")
|
||||
public class SlowServerTest
|
||||
{
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
@ -57,33 +53,33 @@ public class SlowServerTest
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerSlowToRead() throws Exception
|
||||
public void testServerSlowToRead(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
// client.setMasker(new ZeroMasker());
|
||||
client.setMaxIdleTimeout(60000);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
@ -119,18 +115,18 @@ public class SlowServerTest
|
||||
|
||||
// Close
|
||||
clientSession.close();
|
||||
assertTrue("Client close event", clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client close event");
|
||||
clientEndpoint.assertCloseInfo("Client", StatusCode.NORMAL, is("Done"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testServerSlowToSend() throws Exception
|
||||
public void testServerSlowToSend(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
// client.setMasker(new ZeroMasker());
|
||||
client.setMaxIdleTimeout(60000);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
@ -165,7 +161,7 @@ public class SlowServerTest
|
||||
|
||||
// Close
|
||||
clientSession.close();
|
||||
assertTrue("Client close event", clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(clientEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), "Client close event");
|
||||
clientEndpoint.assertCloseInfo("Client", StatusCode.NORMAL, is("Done"));
|
||||
|
||||
}
|
||||
|
@ -18,12 +18,13 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -51,213 +52,204 @@ import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class WebSocketClientTest
|
||||
{
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddExtension_NotInstalled() throws Exception
|
||||
public void testAddExtension_NotInstalled(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
|
||||
client.getPolicy().setIdleTimeout(10000);
|
||||
|
||||
|
||||
URI wsUri = server.getWsUri();
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.setSubProtocols("echo");
|
||||
request.addExtensions("x-bad"); // extension that doesn't exist
|
||||
|
||||
|
||||
// Should trigger failure on bad extension
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage(containsString("x-bad"));
|
||||
client.connect(clientEndpoint, wsUri, request);
|
||||
IllegalArgumentException x = assertThrows(IllegalArgumentException.class, () ->
|
||||
client.connect(clientEndpoint, wsUri, request));
|
||||
assertThat(x.getMessage(), containsString("x-bad"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicEcho() throws IOException, InterruptedException, ExecutionException, TimeoutException
|
||||
public void testBasicEcho(TestInfo testInfo) throws IOException, InterruptedException, ExecutionException, TimeoutException
|
||||
{
|
||||
// Set client timeout
|
||||
final int timeout = 1000;
|
||||
client.setMaxIdleTimeout(timeout);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
|
||||
server.registerOnOpenFuture(wsUri, serverSessionFut);
|
||||
|
||||
|
||||
// Client connects
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest clientUpgradeRequest = new ClientUpgradeRequest();
|
||||
clientUpgradeRequest.setSubProtocols("echo");
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri, clientUpgradeRequest);
|
||||
|
||||
|
||||
// Verify Client Session
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
assertThat("Client Session", clientSession, notNullValue());
|
||||
assertThat("Client Session.open", clientSession.isOpen(), is(true));
|
||||
assertThat("Client Session.upgradeRequest", clientSession.getUpgradeRequest(), notNullValue());
|
||||
assertThat("Client Session.upgradeRequest", clientSession.getUpgradeResponse(), notNullValue());
|
||||
|
||||
|
||||
// Verify Client Session Tracking
|
||||
Collection<WebSocketSession> sessions = client.getBeans(WebSocketSession.class);
|
||||
Assert.assertThat("client.beans[session].size", sessions.size(), is(1));
|
||||
|
||||
assertThat("client.beans[session].size", sessions.size(), is(1));
|
||||
|
||||
// Server accepts connect
|
||||
UntrustedWSSession serverSession = serverSessionFut.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
UntrustedWSEndpoint serverEndpoint = serverSession.getUntrustedEndpoint();
|
||||
|
||||
|
||||
// client confirms connection via echo
|
||||
clientEndpoint.awaitOpenEvent("Client");
|
||||
|
||||
|
||||
// client sends message
|
||||
clientEndpoint.getRemote().sendString("Hello Echo");
|
||||
|
||||
|
||||
// Wait for response to echo
|
||||
String message = clientEndpoint.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
assertThat("message", message, is("Hello Echo"));
|
||||
|
||||
|
||||
// client closes
|
||||
clientEndpoint.close(StatusCode.NORMAL, "Normal Close");
|
||||
|
||||
|
||||
// Server close event
|
||||
serverEndpoint.awaitCloseEvent("Server");
|
||||
serverEndpoint.assertCloseInfo("Server", StatusCode.NORMAL, containsString("Normal Close"));
|
||||
|
||||
|
||||
// client triggers close event on client ws-endpoint
|
||||
clientEndpoint.awaitCloseEvent("Client");
|
||||
clientEndpoint.assertCloseInfo("Client", StatusCode.NORMAL, containsString("Normal Close"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicEcho_UsingCallback() throws Exception
|
||||
public void testBasicEcho_UsingCallback(TestInfo testInfo) throws Exception
|
||||
{
|
||||
client.setMaxIdleTimeout(160000);
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.setSubProtocols("echo");
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri, request);
|
||||
|
||||
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
assertThat("Client session", clientSession, notNullValue());
|
||||
|
||||
|
||||
FutureWriteCallback callback = new FutureWriteCallback();
|
||||
clientEndpoint.session.getRemote().sendString("Hello World!", callback);
|
||||
callback.get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLocalRemoteAddress() throws Exception
|
||||
public void testLocalRemoteAddress(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri);
|
||||
|
||||
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
|
||||
InetSocketAddress local = clientSession.getLocalAddress();
|
||||
InetSocketAddress remote = clientSession.getRemoteAddress();
|
||||
|
||||
Assert.assertThat("Local Socket Address", local, notNullValue());
|
||||
Assert.assertThat("Remote Socket Address", remote, notNullValue());
|
||||
|
||||
|
||||
assertThat("Local Socket Address", local, notNullValue());
|
||||
assertThat("Remote Socket Address", remote, notNullValue());
|
||||
|
||||
// Hard to validate (in a portable unit test) the local address that was used/bound in the low level Jetty Endpoint
|
||||
Assert.assertThat("Local Socket Address / Host", local.getAddress().getHostAddress(), notNullValue());
|
||||
Assert.assertThat("Local Socket Address / Port", local.getPort(), greaterThan(0));
|
||||
|
||||
Assert.assertThat("Remote Socket Address / Host", remote.getAddress().getHostAddress(), is(wsUri.getHost()));
|
||||
Assert.assertThat("Remote Socket Address / Port", remote.getPort(), greaterThan(0));
|
||||
assertThat("Local Socket Address / Host", local.getAddress().getHostAddress(), notNullValue());
|
||||
assertThat("Local Socket Address / Port", local.getPort(), greaterThan(0));
|
||||
|
||||
assertThat("Remote Socket Address / Host", remote.getAddress().getHostAddress(), is(wsUri.getHost()));
|
||||
assertThat("Remote Socket Address / Port", remote.getPort(), greaterThan(0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensure that <code>@WebSocket(maxTextMessageSize = 100*1024)</code> behaves as expected.
|
||||
*
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testMaxMessageSize() throws Exception
|
||||
public void testMaxMessageSize(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
client.getPolicy().setMaxTextMessageSize(100 * 1024);
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri, upgradeRequest);
|
||||
|
||||
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
|
||||
// Create string that is larger than default size of 64k
|
||||
// but smaller than maxMessageSize of 100k
|
||||
byte buf[] = new byte[80 * 1024];
|
||||
Arrays.fill(buf, (byte) 'x');
|
||||
String outgoingMessage = StringUtil.toUTF8String(buf, 0, buf.length);
|
||||
|
||||
|
||||
clientSession.getRemote().sendStringByFuture(outgoingMessage);
|
||||
|
||||
|
||||
String incomingMessage = clientEndpoint.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
assertThat("Message received", incomingMessage, is(outgoingMessage));
|
||||
clientSession.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParameterMap() throws Exception
|
||||
public void testParameterMap(TestInfo testInfo) throws Exception
|
||||
{
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname).resolve("?snack=cashews&amount=handful&brand=off");
|
||||
TrackingEndpoint clientEndpoint = new TrackingEndpoint(testInfo);
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo).resolve("?snack=cashews&amount=handful&brand=off");
|
||||
assertThat("wsUri has query", wsUri.getQuery(), notNullValue());
|
||||
Future<Session> clientConnectFuture = client.connect(clientEndpoint, wsUri);
|
||||
|
||||
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
|
||||
UpgradeRequest req = clientSession.getUpgradeRequest();
|
||||
Assert.assertThat("Upgrade Request", req, notNullValue());
|
||||
|
||||
assertThat("Upgrade Request", req, notNullValue());
|
||||
|
||||
Map<String, List<String>> parameterMap = req.getParameterMap();
|
||||
Assert.assertThat("Parameter Map", parameterMap, notNullValue());
|
||||
|
||||
Assert.assertThat("Parameter[snack]", parameterMap.get("snack"), is(Arrays.asList(new String[]{"cashews"})));
|
||||
Assert.assertThat("Parameter[amount]", parameterMap.get("amount"), is(Arrays.asList(new String[]{"handful"})));
|
||||
Assert.assertThat("Parameter[brand]", parameterMap.get("brand"), is(Arrays.asList(new String[]{"off"})));
|
||||
Assert.assertThat("Parameter[cost]", parameterMap.get("cost"), nullValue());
|
||||
assertThat("Parameter Map", parameterMap, notNullValue());
|
||||
|
||||
assertThat("Parameter[snack]", parameterMap.get("snack"), is(Arrays.asList(new String[]{"cashews"})));
|
||||
assertThat("Parameter[amount]", parameterMap.get("amount"), is(Arrays.asList(new String[]{"handful"})));
|
||||
assertThat("Parameter[brand]", parameterMap.get("brand"), is(Arrays.asList(new String[]{"off"})));
|
||||
assertThat("Parameter[cost]", parameterMap.get("cost"), nullValue());
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,8 @@ import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.jsr356.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.jsr356.encoders.AvailableEncoders;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public abstract class AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
@ -45,7 +43,7 @@ public abstract class AbstractJsrEndpointFunctionsTest
|
||||
protected static SimpleContainerScope containerScope;
|
||||
protected static ClientContainer container;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void initContainer() throws Exception
|
||||
{
|
||||
containerScope = new SimpleContainerScope(clientPolicy);
|
||||
@ -54,16 +52,13 @@ public abstract class AbstractJsrEndpointFunctionsTest
|
||||
container.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopClientContainer() throws Exception
|
||||
{
|
||||
container.stop();
|
||||
containerScope.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
protected AvailableEncoders encoders;
|
||||
protected AvailableDecoders decoders;
|
||||
protected Map<String, String> uriParams = new HashMap<>();
|
||||
|
@ -31,7 +31,7 @@ import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class AnnotatedEchoTest
|
||||
{
|
||||
|
@ -21,7 +21,8 @@ package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -45,24 +46,19 @@ import org.eclipse.jetty.websocket.tests.jsr356.coders.DateEncoder;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.DateTimeEncoder;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.TimeEncoder;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.ValidDualEncoder;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AvailableEncodersTest
|
||||
{
|
||||
private static EndpointConfig testConfig;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void initConfig()
|
||||
{
|
||||
testConfig = new EmptyClientEndpointConfig();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private AvailableEncoders encoders = new AvailableEncoders(testConfig);
|
||||
|
||||
public <T> void assertTextEncoder(Class<T> type, T value, String expectedEncoded) throws IllegalAccessException, InstantiationException, EncodeException
|
||||
@ -288,9 +284,9 @@ public class AvailableEncodersTest
|
||||
public void testCustomEncoder_Register_Duplicate()
|
||||
{
|
||||
// has duplicated support for the same target Type
|
||||
expectedException.expect(InvalidWebSocketException.class);
|
||||
expectedException.expectMessage(containsString("Duplicate"));
|
||||
encoders.register(BadDualEncoder.class);
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class,
|
||||
() -> encoders.register(BadDualEncoder.class));
|
||||
assertThat(x.getMessage(), containsString("Duplicate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -300,8 +296,8 @@ public class AvailableEncodersTest
|
||||
encoders.register(DateEncoder.class);
|
||||
|
||||
// Register TimeEncoder (which also wants to decode java.util.Date)
|
||||
expectedException.expect(InvalidWebSocketException.class);
|
||||
expectedException.expectMessage(containsString("Duplicate"));
|
||||
encoders.register(TimeEncoder.class);
|
||||
InvalidWebSocketException x = assertThrows(InvalidWebSocketException.class,
|
||||
() -> encoders.register(TimeEncoder.class));
|
||||
assertThat(x.getMessage(), containsString("Duplicate"));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -45,12 +48,10 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.AbstractJsrTrackingSocket;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class DecoderReaderManySmallTest
|
||||
{
|
||||
@ -91,10 +92,10 @@ public class DecoderReaderManySmallTest
|
||||
public static class EventIdSocket extends AbstractJsrTrackingSocket
|
||||
{
|
||||
public BlockingQueue<EventId> messageQueue = new LinkedBlockingDeque<>();
|
||||
|
||||
public EventIdSocket(String id)
|
||||
|
||||
public EventIdSocket(TestInfo testInfo)
|
||||
{
|
||||
super(id);
|
||||
super(testInfo.getDisplayName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -144,38 +145,35 @@ public class DecoderReaderManySmallTest
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketContainer client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initClient()
|
||||
{
|
||||
client = ContainerProvider.getWebSocketContainer();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyIds() throws Exception
|
||||
public void testManyIds(TestInfo testInfo) throws Exception
|
||||
{
|
||||
server.registerWebSocket("/eventids", new EventIdServerCreator());
|
||||
|
||||
URI wsUri = server.getWsUri().resolve("/eventids");
|
||||
EventIdSocket clientSocket = new EventIdSocket(testname.getMethodName());
|
||||
EventIdSocket clientSocket = new EventIdSocket(testInfo);
|
||||
Session clientSession = client.connectToServer(clientSocket, wsUri);
|
||||
|
||||
final int from = 1000;
|
||||
@ -189,14 +187,14 @@ public class DecoderReaderManySmallTest
|
||||
{
|
||||
// validate that ids don't repeat.
|
||||
EventId receivedId = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertFalse("Already saw ID: " + receivedId.eventId, seen.contains(receivedId.eventId));
|
||||
assertFalse(seen.contains(receivedId.eventId),"Already saw ID: " + receivedId.eventId);
|
||||
seen.add(receivedId.eventId);
|
||||
}
|
||||
|
||||
// validate that all expected ids have been seen (order is irrelevant here)
|
||||
for (int expected = from; expected < to; expected++)
|
||||
{
|
||||
Assert.assertTrue("Has expected id:" + expected, seen.contains(expected));
|
||||
assertTrue(seen.contains(expected), "Has expected id:" + expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -41,15 +41,15 @@ import org.eclipse.jetty.websocket.common.io.CompletableFutureFrameCallback;
|
||||
import org.eclipse.jetty.websocket.common.io.FutureFrameCallback;
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.messages.DecodedReaderMessageSink;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DecoderReaderMessageSinkTest
|
||||
{
|
||||
private static ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>());
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopExecutor()
|
||||
{
|
||||
executor.shutdown();
|
||||
|
@ -19,8 +19,8 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -34,22 +34,22 @@ import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.AbstractJsrTrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoServlet;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class EndpointEchoTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new EchoServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.CloseReason;
|
||||
@ -29,7 +31,7 @@ import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.websocket.common.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_BadSignaturesTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
@ -45,9 +47,9 @@ public class JsrEndpointFunctions_BadSignaturesTest extends AbstractJsrEndpointF
|
||||
endpointConfig
|
||||
);
|
||||
|
||||
expectedException.expect(InvalidSignatureException.class);
|
||||
expectedException.expectMessage(containsString(expectedString));
|
||||
functions.start();
|
||||
InvalidSignatureException x = assertThrows(InvalidSignatureException.class,
|
||||
() -> functions.start());
|
||||
assertThat(x.getMessage(), containsString(expectedString));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnCloseTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -29,7 +29,7 @@ import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnErrorTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -36,7 +36,7 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.common.function.EndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnMessage_BinaryStreamTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -19,7 +19,8 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -35,7 +36,7 @@ import org.eclipse.jetty.websocket.common.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnMessage_BinaryTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
@ -78,8 +79,9 @@ public class JsrEndpointFunctions_OnMessage_BinaryTest extends AbstractJsrEndpoi
|
||||
@Test
|
||||
public void testInvokeMessage() throws Exception
|
||||
{
|
||||
expectedException.expect(InvalidSignatureException.class);
|
||||
assertOnMessageInvocation(new MessageSocket(), "onMessage()");
|
||||
assertThrows(InvalidSignatureException.class, ()->
|
||||
assertOnMessageInvocation(new MessageSocket(), "onMessage()")
|
||||
);
|
||||
}
|
||||
|
||||
@ClientEndpoint
|
||||
@ -112,10 +114,10 @@ public class JsrEndpointFunctions_OnMessage_BinaryTest extends AbstractJsrEndpoi
|
||||
@Test
|
||||
public void testInvokeMessageSession() throws Exception
|
||||
{
|
||||
expectedException.expect(InvalidSignatureException.class);
|
||||
assertThrows(InvalidSignatureException.class, ()->
|
||||
assertOnMessageInvocation(new MessageSessionSocket(),
|
||||
"onMessage(JsrSession[CLIENT,%s,DummyConnection])",
|
||||
MessageSessionSocket.class.getName());
|
||||
MessageSessionSocket.class.getName()));
|
||||
}
|
||||
|
||||
@ClientEndpoint
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.common.function.EndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnMessage_TextStreamTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -19,8 +19,9 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -36,7 +37,7 @@ import org.eclipse.jetty.websocket.common.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnMessage_TextTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
@ -81,12 +82,12 @@ public class JsrEndpointFunctions_OnMessage_TextTest extends AbstractJsrEndpoint
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmbiguousEmptyMessage() throws Exception
|
||||
public void testAmbiguousEmptyMessage()
|
||||
{
|
||||
MessageSocket socket = new MessageSocket();
|
||||
expectedException.expect(InvalidSignatureException.class);
|
||||
expectedException.expectMessage(containsString("@OnMessage public void onMessage"));
|
||||
onText(socket, "Hello World");
|
||||
InvalidSignatureException x = assertThrows(InvalidSignatureException.class, ()->
|
||||
onText(socket, "Hello World"));
|
||||
assertThat(x.getMessage(),containsString("@OnMessage public void onMessage"));
|
||||
}
|
||||
|
||||
@ClientEndpoint
|
||||
@ -119,13 +120,14 @@ public class JsrEndpointFunctions_OnMessage_TextTest extends AbstractJsrEndpoint
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmbiguousMessageSession() throws Exception
|
||||
public void testAmbiguousMessageSession()
|
||||
{
|
||||
MessageSessionSocket socket = new MessageSessionSocket();
|
||||
|
||||
expectedException.expect(InvalidSignatureException.class);
|
||||
expectedException.expectMessage(containsString("@OnMessage public void onMessage"));
|
||||
onText(socket, "Hello World");
|
||||
InvalidSignatureException x = assertThrows(InvalidSignatureException.class, ()->
|
||||
onText(socket, "Hello World"));
|
||||
assertThat(x.getMessage(), containsString("@OnMessage public void onMessage"));
|
||||
|
||||
}
|
||||
|
||||
@ClientEndpoint
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -29,7 +29,7 @@ import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.websocket.jsr356.function.JsrEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrEndpointFunctions_OnOpenTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -50,9 +50,9 @@ import org.eclipse.jetty.websocket.tests.jsr356.handlers.ByteBufferPartialHandle
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.handlers.LongMessageHandler;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.handlers.StringWholeHandler;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.endpoints.DummyEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrSessionTest
|
||||
{
|
||||
@ -62,7 +62,7 @@ public class JsrSessionTest
|
||||
private ClientContainer container;
|
||||
private JsrSession session;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initSession() throws Exception
|
||||
{
|
||||
String id = JsrSessionTest.class.getSimpleName();
|
||||
@ -84,7 +84,7 @@ public class JsrSessionTest
|
||||
session.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopSession() throws Exception
|
||||
{
|
||||
session.stop();
|
||||
|
@ -20,8 +20,8 @@ package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -60,11 +60,11 @@ import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* This class tests receiving of messages by different types of {@link MessageHandler}
|
||||
@ -185,7 +185,7 @@ public class MessageReceivingTest
|
||||
private static URI serverUri;
|
||||
private WebSocketContainer container;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new Server();
|
||||
@ -204,19 +204,19 @@ public class MessageReceivingTest
|
||||
serverUri = WSURI.toWebsocket(server.getURI()).resolve("/");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initClient()
|
||||
{
|
||||
container = ContainerProvider.getWebSocketContainer();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
((LifeCycle) container).stop();
|
||||
|
@ -18,17 +18,17 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
|
||||
@ -47,91 +47,79 @@ import org.eclipse.jetty.websocket.tests.client.jsr356.samples.CloseSessionReaso
|
||||
import org.eclipse.jetty.websocket.tests.client.jsr356.samples.CloseSessionSocket;
|
||||
import org.eclipse.jetty.websocket.tests.client.jsr356.samples.CloseSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class OnCloseTest
|
||||
{
|
||||
private static class Case
|
||||
private static class Scenario
|
||||
{
|
||||
public static Case add(List<Case[]> data, Class<?> closeClass)
|
||||
public static Scenario add(List<Arguments> data, Class<?> closeClass)
|
||||
{
|
||||
Case tcase = new Case();
|
||||
tcase.closeClass = closeClass;
|
||||
data.add(new Case[]
|
||||
{tcase});
|
||||
return tcase;
|
||||
Scenario scenario = new Scenario();
|
||||
scenario.closeClass = closeClass;
|
||||
data.add(Arguments.of(scenario));
|
||||
return scenario;
|
||||
}
|
||||
|
||||
|
||||
Class<?> closeClass;
|
||||
String expectedCloseEvent;
|
||||
|
||||
public Case expect(String expectedEvent)
|
||||
|
||||
public Scenario expect(String expectedEvent)
|
||||
{
|
||||
this.expectedCloseEvent = expectedEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return closeClass.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
private static ClientContainer container = new ClientContainer();
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Collection<Case[]> data() throws Exception
|
||||
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Case[]> data = new ArrayList<>();
|
||||
|
||||
Case.add(data, CloseSocket.class).expect("onClose()");
|
||||
Case.add(data, CloseReasonSocket.class).expect("onClose(CloseReason)");
|
||||
Case.add(data, CloseSessionSocket.class).expect("onClose(Session)");
|
||||
Case.add(data, CloseReasonSessionSocket.class).expect("onClose(CloseReason,Session)");
|
||||
Case.add(data, CloseSessionReasonSocket.class).expect("onClose(Session,CloseReason)");
|
||||
|
||||
return data;
|
||||
List<Arguments> data = new ArrayList<>();
|
||||
|
||||
Scenario.add(data, CloseSocket.class).expect("onClose()");
|
||||
Scenario.add(data, CloseReasonSocket.class).expect("onClose(CloseReason)");
|
||||
Scenario.add(data, CloseSessionSocket.class).expect("onClose(Session)");
|
||||
Scenario.add(data, CloseReasonSessionSocket.class).expect("onClose(CloseReason,Session)");
|
||||
Scenario.add(data, CloseSessionReasonSocket.class).expect("onClose(Session,CloseReason)");
|
||||
|
||||
return data.stream();
|
||||
}
|
||||
|
||||
private final Case testcase;
|
||||
|
||||
public OnCloseTest(Case testcase)
|
||||
{
|
||||
this.testcase = testcase;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCloseCall() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testOnCloseCall(Scenario scenario) throws Exception
|
||||
{
|
||||
// Build up EventDriver
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
TrackingSocket endpoint = (TrackingSocket) testcase.closeClass.newInstance();
|
||||
|
||||
TrackingSocket endpoint = (TrackingSocket) scenario.closeClass.newInstance();
|
||||
|
||||
Executor executor = new QueuedThreadPool();
|
||||
ClientEndpointConfig config = new EmptyClientEndpointConfig();
|
||||
AvailableEncoders encoders = new AvailableEncoders(config);
|
||||
AvailableDecoders decoders = new AvailableDecoders(config);
|
||||
Map<String, String> uriParams = new HashMap<>();
|
||||
|
||||
|
||||
JsrEndpointFunctions jsrFunctions = new JsrEndpointFunctions(endpoint, policy,
|
||||
executor, encoders, decoders, uriParams, config);
|
||||
try
|
||||
{
|
||||
jsrFunctions.start();
|
||||
|
||||
|
||||
// Execute onClose call
|
||||
jsrFunctions.onClose(new CloseInfo(StatusCode.NORMAL, "normal"));
|
||||
|
||||
|
||||
// Test captured event
|
||||
BlockingQueue<String> events = endpoint.events;
|
||||
assertThat("Number of Events Captured", events.size(), is(1));
|
||||
String closeEvent = events.poll(1, TimeUnit.SECONDS);
|
||||
assertThat("Close Event", closeEvent, is(testcase.expectedCloseEvent));
|
||||
assertThat("Close Event", closeEvent, is(scenario.expectedCloseEvent));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
@ -44,11 +44,10 @@ import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.Quotes;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.QuotesUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class QuotesDecoderTest
|
||||
{
|
||||
@ -93,38 +92,35 @@ public class QuotesDecoderTest
|
||||
|
||||
private static final Logger LOG = Log.getLogger(QuotesDecoderTest.class);
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketContainer client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initClient()
|
||||
{
|
||||
client = ContainerProvider.getWebSocketContainer();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleQuotes() throws Exception
|
||||
public void testSingleQuotes(TestInfo testInfo) throws Exception
|
||||
{
|
||||
server.registerWebSocket("/quoter", new QuoteServingCreator());
|
||||
|
||||
URI wsUri = server.getWsUri().resolve("/quoter");
|
||||
QuotesSocket clientSocket = new QuotesSocket(testname.getMethodName());
|
||||
QuotesSocket clientSocket = new QuotesSocket(testInfo.getDisplayName());
|
||||
Session clientSession = client.connectToServer(clientSocket, wsUri);
|
||||
|
||||
clientSession.getAsyncRemote().sendText("quotes-ben.txt");
|
||||
@ -136,12 +132,12 @@ public class QuotesDecoderTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoQuotes() throws Exception
|
||||
public void testTwoQuotes(TestInfo testInfo) throws Exception
|
||||
{
|
||||
server.registerWebSocket("/quoter", new QuoteServingCreator());
|
||||
|
||||
URI wsUri = server.getWsUri().resolve("/quoter");
|
||||
QuotesSocket clientSocket = new QuotesSocket(testname.getMethodName());
|
||||
QuotesSocket clientSocket = new QuotesSocket(testInfo.getDisplayName());
|
||||
Session clientSession = client.connectToServer(clientSocket, wsUri);
|
||||
|
||||
clientSession.getAsyncRemote().sendText("quotes-ben.txt");
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -41,12 +42,10 @@ import org.eclipse.jetty.websocket.tests.jsr356.AbstractJsrTrackingSocket;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.Quotes;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.QuotesEncoder;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class QuotesEncoderTest
|
||||
{
|
||||
@ -75,26 +74,23 @@ public class QuotesEncoderTest
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSServer server;
|
||||
private WebSocketContainer client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initClient()
|
||||
{
|
||||
client = ContainerProvider.getWebSocketContainer();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
@ -102,10 +98,10 @@ public class QuotesEncoderTest
|
||||
|
||||
private void assertReceivedQuotes(String result, Quotes quotes)
|
||||
{
|
||||
Assert.assertThat("Quote Author", result, containsString("Author: " + quotes.getAuthor()));
|
||||
assertThat("Quote Author", result, containsString("Author: " + quotes.getAuthor()));
|
||||
for (String quote : quotes.getQuotes())
|
||||
{
|
||||
Assert.assertThat("Quote", result, containsString("Quote: " + quote));
|
||||
assertThat("Quote", result, containsString("Quote: " + quote));
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,10 +141,10 @@ public class QuotesEncoderTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleQuotes() throws Exception
|
||||
public void testSingleQuotes(TestInfo testInfo) throws Exception
|
||||
{
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
QuotesSocket quoter = new QuotesSocket(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
QuotesSocket quoter = new QuotesSocket(testInfo.getDisplayName());
|
||||
|
||||
Session session = null;
|
||||
try
|
||||
@ -168,10 +164,10 @@ public class QuotesEncoderTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoQuotes() throws Exception
|
||||
public void testTwoQuotes(TestInfo testInfo) throws Exception
|
||||
{
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
|
||||
QuotesSocket quoter = new QuotesSocket(testname.getMethodName());
|
||||
URI wsUri = server.getUntrustedWsUri(this.getClass(), testInfo);
|
||||
QuotesSocket quoter = new QuotesSocket(testInfo.getDisplayName());
|
||||
|
||||
Session session = null;
|
||||
try
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.client.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -40,8 +40,8 @@ import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.common.io.FutureFrameCallback;
|
||||
import org.eclipse.jetty.websocket.common.message.ReaderMessageSink;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ReaderMessageSinkTest
|
||||
{
|
||||
@ -49,7 +49,7 @@ public class ReaderMessageSinkTest
|
||||
private static ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>());
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopExecutor()
|
||||
{
|
||||
executor.shutdown();
|
||||
|
@ -18,11 +18,12 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.jsr356.coders;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Instant;
|
||||
@ -39,24 +40,19 @@ import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.jsr356.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.jsr356.decoders.IntegerDecoder;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AvailableDecodersTest
|
||||
{
|
||||
private static EndpointConfig testConfig;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void initConfig()
|
||||
{
|
||||
testConfig = new EmptyClientEndpointConfig();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private AvailableDecoders decoders = new AvailableDecoders(testConfig);
|
||||
|
||||
private <T> void assertTextDecoder(Class<T> type, String value, T expectedDecoded) throws IllegalAccessException, InstantiationException, DecodeException
|
||||
@ -303,9 +299,9 @@ public class AvailableDecodersTest
|
||||
public void testCustomDecoder_Register_Duplicate()
|
||||
{
|
||||
// has duplicated support for the same target Type
|
||||
expectedException.expect(InvalidWebSocketException.class);
|
||||
expectedException.expectMessage(containsString("Duplicate"));
|
||||
decoders.register(BadDualDecoder.class);
|
||||
InvalidWebSocketException iwe = assertThrows(InvalidWebSocketException.class, ()->
|
||||
decoders.register(BadDualDecoder.class));
|
||||
assertThat(iwe.getMessage(), containsString("Duplicate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -315,8 +311,8 @@ public class AvailableDecodersTest
|
||||
decoders.register(DateDecoder.class);
|
||||
|
||||
// Register TimeDecoder (which also wants to decode java.util.Date)
|
||||
expectedException.expect(InvalidWebSocketException.class);
|
||||
expectedException.expectMessage(containsString("Duplicate"));
|
||||
decoders.register(TimeDecoder.class);
|
||||
InvalidWebSocketException iwe = assertThrows(InvalidWebSocketException.class, ()->
|
||||
decoders.register(TimeDecoder.class));
|
||||
assertThat(iwe.getMessage(), containsString("Duplicate"));
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.tests.jsr356.coders;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
@ -41,8 +41,8 @@ import org.eclipse.jetty.websocket.common.io.CompletableFutureFrameCallback;
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.messages.DecodedReaderMessageSink;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.DummyJsrEndpointFunctions;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Decoder.TextStream} scenarios
|
||||
@ -52,7 +52,7 @@ public class DecoderTextStreamTest
|
||||
private static ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>());
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopExecutor()
|
||||
{
|
||||
executor.shutdown();
|
||||
|
@ -21,7 +21,7 @@ package org.eclipse.jetty.websocket.tests.jsr356.coders;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Encoder.Text} scenarios
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.jsr356.endpoints;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -59,7 +59,7 @@ public abstract class AbstractStringEndpoint extends Endpoint implements Message
|
||||
|
||||
public void awaitCloseEvent(String prefix) throws InterruptedException
|
||||
{
|
||||
assertTrue(prefix + " onClose event", closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
assertTrue(closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS), prefix + " onClose event");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +81,7 @@ public abstract class AbstractStringEndpoint extends Endpoint implements Message
|
||||
CloseInfo close = new CloseInfo(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase());
|
||||
boolean closeTracked = closeInfo.compareAndSet(null, close);
|
||||
this.closeLatch.countDown();
|
||||
assertTrue("Close only happened once", closeTracked);
|
||||
assertTrue(closeTracked, "Close only happened once");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.anything;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ -46,14 +47,12 @@ import org.eclipse.jetty.websocket.server.WebSocketHandler;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class AnnotatedMaxMessageSizeTest
|
||||
{
|
||||
@ -94,7 +93,7 @@ public class AnnotatedMaxMessageSizeTest
|
||||
private static Server server;
|
||||
private static URI serverUri;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new Server();
|
||||
@ -116,36 +115,33 @@ public class AnnotatedMaxMessageSizeTest
|
||||
serverUri = WSURI.toWebsocket(server.getURI()).resolve("/");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoGood() throws Exception
|
||||
public void testEchoGood(TestInfo testInfo) throws Exception
|
||||
{
|
||||
URI wsUri = serverUri.resolve("/");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -158,17 +154,17 @@ public class AnnotatedMaxMessageSizeTest
|
||||
|
||||
// Read message
|
||||
String incomingMsg = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertThat("Incoming Message", incomingMsg, is(msg));
|
||||
assertThat("Incoming Message", incomingMsg, is(msg));
|
||||
|
||||
clientSession.close();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testEchoTooBig() throws Exception
|
||||
@Test
|
||||
public void testEchoTooBig(TestInfo testInfo) throws Exception
|
||||
{
|
||||
URI wsUri = serverUri.resolve("/");
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("echo");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.tests.server;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.StacklessLogging;
|
||||
@ -32,39 +33,35 @@ import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.BadFrame;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test various bad / forbidden opcodes (per spec)
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class BadOpCodesTest extends AbstractLocalServerCase
|
||||
{
|
||||
@Parameterized.Parameters(name = "opcode={0}")
|
||||
public static List<Object[]> data()
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
data.add(new Object[]{3}); // From Autobahn WebSocket Server Testcase 4.1.1
|
||||
data.add(new Object[]{4}); // From Autobahn WebSocket Server Testcase 4.1.2
|
||||
data.add(new Object[]{5}); // From Autobahn WebSocket Server Testcase 4.1.3
|
||||
data.add(new Object[]{6}); // From Autobahn WebSocket Server Testcase 4.1.4
|
||||
data.add(new Object[]{7}); // From Autobahn WebSocket Server Testcase 4.1.5
|
||||
data.add(new Object[]{11}); // From Autobahn WebSocket Server Testcase 4.2.1
|
||||
data.add(new Object[]{12}); // From Autobahn WebSocket Server Testcase 4.2.2
|
||||
data.add(new Object[]{13}); // From Autobahn WebSocket Server Testcase 4.2.3
|
||||
data.add(new Object[]{14}); // From Autobahn WebSocket Server Testcase 4.2.4
|
||||
data.add(new Object[]{15}); // From Autobahn WebSocket Server Testcase 4.2.5
|
||||
List<Arguments> data = new ArrayList<>();
|
||||
data.add(Arguments.of(3)); // From Autobahn WebSocket Server Testcase 4.1.1
|
||||
data.add(Arguments.of(4)); // From Autobahn WebSocket Server Testcase 4.1.2
|
||||
data.add(Arguments.of(5)); // From Autobahn WebSocket Server Testcase 4.1.3
|
||||
data.add(Arguments.of(6)); // From Autobahn WebSocket Server Testcase 4.1.4
|
||||
data.add(Arguments.of(7)); // From Autobahn WebSocket Server Testcase 4.1.5
|
||||
data.add(Arguments.of(11)); // From Autobahn WebSocket Server Testcase 4.2.1
|
||||
data.add(Arguments.of(12)); // From Autobahn WebSocket Server Testcase 4.2.2
|
||||
data.add(Arguments.of(13)); // From Autobahn WebSocket Server Testcase 4.2.3
|
||||
data.add(Arguments.of(14)); // From Autobahn WebSocket Server Testcase 4.2.4
|
||||
data.add(Arguments.of(15)); // From Autobahn WebSocket Server Testcase 4.2.5
|
||||
|
||||
return data;
|
||||
return data.stream();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public int opcode;
|
||||
|
||||
@Test
|
||||
public void testBadOpCode() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testBadOpCode(int opcode) throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new BadFrame((byte) opcode)); // intentionally bad
|
||||
@ -79,9 +76,10 @@ public class BadOpCodesTest extends AbstractLocalServerCase
|
||||
session.expect(expect);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testText_BadOpCode_Ping() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testText_BadOpCode_Ping(int opcode) throws Exception
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.wrap(StringUtil.getUtf8Bytes("bad"));
|
||||
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
@ -35,60 +35,56 @@ import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoServlet;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
public class ChromeTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new EchoServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeWithWebkitDeflateExtension() throws Exception
|
||||
public void testUpgradeWithWebkitDeflateExtension(TestInfo testInfo) throws Exception
|
||||
{
|
||||
Assume.assumeTrue("Server has x-webkit-deflate-frame registered",
|
||||
server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame"));
|
||||
Assumptions.assumeTrue(
|
||||
server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame"),
|
||||
"Server has x-webkit-deflate-frame registered");
|
||||
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.addExtensions("x-webkit-deflate-frame");
|
||||
upgradeRequest.setSubProtocols("chat");
|
||||
@ -105,7 +101,7 @@ public class ChromeTest
|
||||
|
||||
// Read message
|
||||
String incomingMsg = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertThat("Incoming Message", incomingMsg, is(msg));
|
||||
assertThat("Incoming Message", incomingMsg, is(msg));
|
||||
|
||||
clientSession.close();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -38,7 +38,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.ParserCapture;
|
||||
import org.eclipse.jetty.websocket.tests.UpgradeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test simulating a client that talks too quickly.
|
||||
@ -53,7 +53,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class ConnectionUpgradeToBufferTest extends AbstractLocalServerCase
|
||||
{
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
public void testUpgradeWithSmallFrames() throws Exception
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocate(4096);
|
||||
|
@ -19,16 +19,16 @@
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@ -50,15 +50,14 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test the {@link Decorator} features of the WebSocketServer
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DecoratorsTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(DecoratorsTest.class);
|
||||
@ -156,20 +155,18 @@ public class DecoratorsTest
|
||||
}
|
||||
}
|
||||
|
||||
private interface Case
|
||||
private interface ContextCustomizer
|
||||
{
|
||||
void customize(ServletContextHandler context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Object[]> data()
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Object[]> cases = new ArrayList<>();
|
||||
|
||||
cases.add(new Object[] {
|
||||
"Legacy Usage",
|
||||
(Case) (context) -> {
|
||||
(ContextCustomizer) (context) -> {
|
||||
context.getObjectFactory().clear();
|
||||
// Add decorator in the legacy way
|
||||
context.addDecorator(new DummyLegacyDecorator());
|
||||
@ -179,7 +176,7 @@ public class DecoratorsTest
|
||||
|
||||
cases.add(new Object[] {
|
||||
"Recommended Usage",
|
||||
(Case) (context) -> {
|
||||
(ContextCustomizer) (context) -> {
|
||||
// Add decorator in the new util way
|
||||
context.getObjectFactory().clear();
|
||||
context.getObjectFactory().addDecorator(new DummyUtilDecorator());
|
||||
@ -187,16 +184,22 @@ public class DecoratorsTest
|
||||
DummyUtilDecorator.class
|
||||
});
|
||||
|
||||
return cases;
|
||||
return cases.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
private SimpleServletServer server;
|
||||
private Class<?> expectedDecoratorClass;
|
||||
|
||||
public DecoratorsTest(String testId, Case testcase, Class<?> expectedDecoratorClass) throws Exception
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testAccessRequestCookies(String testId, ContextCustomizer testcase, Class<?> expectedDecoratorClass) throws Exception
|
||||
{
|
||||
LOG.debug("Testing {}", testId);
|
||||
this.expectedDecoratorClass = expectedDecoratorClass;
|
||||
server = new SimpleServletServer(new DecoratorsRequestServlet(new DecoratorsCreator()))
|
||||
{
|
||||
@Override
|
||||
@ -207,17 +210,7 @@ public class DecoratorsTest
|
||||
}
|
||||
};
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessRequestCookies() throws Exception
|
||||
{
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
@ -233,7 +226,7 @@ public class DecoratorsTest
|
||||
String payload = frame.getPayloadAsUTF8();
|
||||
assertThat("Text - DecoratedObjectFactory", payload, containsString("Object is a DecoratedObjectFactory"));
|
||||
assertThat("Text - decorators.size", payload, containsString("Decorators.size = [1]"));
|
||||
assertThat("Text - decorator type", payload, containsString("decorator[] = " + this.expectedDecoratorClass.getName()));
|
||||
assertThat("Text - decorator type", payload, containsString("decorator[] = " + expectedDecoratorClass.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.UpgradeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FirefoxTest extends AbstractLocalServerCase
|
||||
{
|
||||
|
@ -18,10 +18,10 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -40,24 +40,23 @@ import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.UnitExtensionStack;
|
||||
import org.eclipse.jetty.websocket.tests.UpgradeUtils;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoServlet;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FragmentExtensionTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new EchoServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
@ -82,7 +81,8 @@ public class FragmentExtensionTest
|
||||
{
|
||||
ExtensionFactory extensionFactory = server.getWebSocketServletFactory().getExtensionFactory();
|
||||
assertThat("Extension Factory", extensionFactory, notNullValue());
|
||||
Assume.assumeTrue("Server has fragment registered", extensionFactory.isAvailable("fragment"));
|
||||
Assumptions.assumeTrue(extensionFactory.isAvailable("fragment"),
|
||||
"Server has fragment registered");
|
||||
|
||||
int fragSize = 4;
|
||||
|
||||
@ -113,7 +113,7 @@ public class FragmentExtensionTest
|
||||
for (int i = 0; i < parts.length; i++)
|
||||
{
|
||||
WebSocketFrame frame = incomingFrames.poll();
|
||||
Assert.assertThat("text[" + i + "].payload", frame.getPayloadAsUTF8(), is(parts[i]));
|
||||
assertThat("text[" + i + "].payload", frame.getPayloadAsUTF8(), is(parts[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ package org.eclipse.jetty.websocket.tests.server;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -41,35 +42,33 @@ import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.UnitExtensionStack;
|
||||
import org.eclipse.jetty.websocket.tests.UpgradeUtils;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoServlet;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IdentityExtensionTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new EchoServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
@Test
|
||||
public void testIdentityExtension() throws Exception
|
||||
{
|
||||
ExtensionFactory extensionFactory = server.getWebSocketServletFactory().getExtensionFactory();
|
||||
assertThat("Extension Factory", extensionFactory, notNullValue());
|
||||
Assume.assumeTrue("Server has identity registered", extensionFactory.isAvailable("identity"));
|
||||
assumeTrue(extensionFactory.isAvailable("identity"), "Server has identity registered");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new TextFrame().setPayload("Hello Identity"));
|
||||
@ -94,8 +93,8 @@ public class IdentityExtensionTest
|
||||
BlockingQueue<WebSocketFrame> incomingFrames = extensionStack.processIncoming(framesQueue);
|
||||
|
||||
WebSocketFrame frame = incomingFrames.poll();
|
||||
Assert.assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
Assert.assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), is("Hello Identity"));
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), is("Hello Identity"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -35,11 +35,9 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IdleTimeoutTest
|
||||
{
|
||||
@ -60,17 +58,14 @@ public class IdleTimeoutTest
|
||||
|
||||
protected static SimpleServletServer server;
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new TimeoutServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.anything;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
@ -49,13 +49,12 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
/**
|
||||
* Tests various close scenarios that should result in Open Session cleanup
|
||||
@ -225,32 +224,29 @@ public class ManyConnectionsCleanupTest
|
||||
private static SimpleServletServer server;
|
||||
private static AbstractCloseSocket closeSocket;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new CloseServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
@ -262,7 +258,7 @@ public class ManyConnectionsCleanupTest
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testOpenSessionCleanup() throws Exception
|
||||
public void testOpenSessionCleanup(TestInfo testInfo) throws Exception
|
||||
{
|
||||
int iterationCount = 100;
|
||||
|
||||
@ -270,15 +266,15 @@ public class ManyConnectionsCleanupTest
|
||||
{
|
||||
for (int requests = 0; requests < iterationCount; requests++)
|
||||
{
|
||||
fastFail();
|
||||
fastClose();
|
||||
dropConnection();
|
||||
fastFail(testInfo);
|
||||
fastClose(testInfo);
|
||||
dropConnection(testInfo);
|
||||
}
|
||||
}
|
||||
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("container");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -300,12 +296,12 @@ public class ManyConnectionsCleanupTest
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void fastClose() throws Exception
|
||||
private void fastClose(TestInfo testInfo) throws Exception
|
||||
{
|
||||
client.setMaxIdleTimeout(1000);
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("fastclose");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -318,12 +314,12 @@ public class ManyConnectionsCleanupTest
|
||||
clientSession.close();
|
||||
}
|
||||
|
||||
private void fastFail() throws Exception
|
||||
private void fastFail(TestInfo testInfo) throws Exception
|
||||
{
|
||||
client.setMaxIdleTimeout(1000);
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("fastfail");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -337,12 +333,12 @@ public class ManyConnectionsCleanupTest
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void dropConnection() throws Exception
|
||||
private void dropConnection(TestInfo testInfo) throws Exception
|
||||
{
|
||||
client.setMaxIdleTimeout(1000);
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo.getDisplayName());
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("container");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
@ -44,13 +44,12 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
/**
|
||||
* Testing badly behaving Socket class implementations to get the best
|
||||
@ -173,7 +172,7 @@ public class MisbehavingClassTest
|
||||
private static SimpleServletServer server;
|
||||
private static BadSocketsServlet badSocketsServlet;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
badSocketsServlet = new BadSocketsServlet();
|
||||
@ -181,32 +180,29 @@ public class MisbehavingClassTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListenerRuntimeOnConnect() throws Exception
|
||||
public void testListenerRuntimeOnConnect(TestInfo testInfo) throws Exception
|
||||
{
|
||||
try (StacklessLogging ignored = new StacklessLogging(ListenerRuntimeOnConnectSocket.class))
|
||||
{
|
||||
@ -216,7 +212,7 @@ public class MisbehavingClassTest
|
||||
client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(1));
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("listener-runtime-connect");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -231,7 +227,7 @@ public class MisbehavingClassTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotatedRuntimeOnConnect() throws Exception
|
||||
public void testAnnotatedRuntimeOnConnect(TestInfo testInfo) throws Exception
|
||||
{
|
||||
try (StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class))
|
||||
{
|
||||
@ -241,7 +237,7 @@ public class MisbehavingClassTest
|
||||
client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(1));
|
||||
URI wsUri = server.getServerUri();
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testInfo);
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols("annotated-runtime-connect");
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
|
@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
@ -30,37 +31,35 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class PayloadLengthTest extends AbstractLocalServerCase
|
||||
{
|
||||
@Parameterized.Parameters(name = "{0} bytes")
|
||||
public static List<Object[]> data()
|
||||
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Object[]> cases = new ArrayList<>();
|
||||
List<Arguments> cases = new ArrayList<>();
|
||||
|
||||
// Uses small 7-bit payload length format
|
||||
cases.add(new Object[]{0}); // From Autobahn WebSocket Server Testcase 1.1.1
|
||||
cases.add(new Object[]{1});
|
||||
cases.add(new Object[]{125}); // From Autobahn WebSocket Server Testcase 1.1.2
|
||||
cases.add(Arguments.of(0)); // From Autobahn WebSocket Server Testcase 1.1.1
|
||||
cases.add(Arguments.of(1));
|
||||
cases.add(Arguments.of(125)); // From Autobahn WebSocket Server Testcase 1.1.2
|
||||
// Uses medium 2 byte payload length format
|
||||
cases.add(new Object[]{126}); // From Autobahn WebSocket Server Testcase 1.1.3
|
||||
cases.add(new Object[]{127}); // From Autobahn WebSocket Server Testcase 1.1.4
|
||||
cases.add(new Object[]{128}); // From Autobahn WebSocket Server Testcase 1.1.5
|
||||
cases.add(new Object[]{65535}); // From Autobahn WebSocket Server Testcase 1.1.6
|
||||
cases.add(Arguments.of(126)); // From Autobahn WebSocket Server Testcase 1.1.3
|
||||
cases.add(Arguments.of(127)); // From Autobahn WebSocket Server Testcase 1.1.4
|
||||
cases.add(Arguments.of(128)); // From Autobahn WebSocket Server Testcase 1.1.5
|
||||
cases.add(Arguments.of(65535)); // From Autobahn WebSocket Server Testcase 1.1.6
|
||||
// Uses large 8 byte payload length
|
||||
cases.add(new Object[]{65536}); // From Autobahn WebSocket Server Testcase 1.1.7
|
||||
cases.add(new Object[]{500 * 1024});
|
||||
return cases;
|
||||
cases.add(Arguments.of(65536)); // From Autobahn WebSocket Server Testcase 1.1.7
|
||||
cases.add(Arguments.of(500 * 1024));
|
||||
return cases.stream();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public int size;
|
||||
|
||||
@Test
|
||||
public void testTextPayloadLength() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testTextPayloadLength(int size) throws Exception
|
||||
{
|
||||
byte payload[] = new byte[size];
|
||||
Arrays.fill(payload, (byte) 'x');
|
||||
@ -80,9 +79,10 @@ public class PayloadLengthTest extends AbstractLocalServerCase
|
||||
session.expect(expect);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextPayloadLength_SmallBuffers() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testTextPayloadLength_SmallBuffers(int size) throws Exception
|
||||
{
|
||||
byte payload[] = new byte[size];
|
||||
Arrays.fill(payload, (byte) 'x');
|
||||
@ -102,9 +102,10 @@ public class PayloadLengthTest extends AbstractLocalServerCase
|
||||
session.expect(expect);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinaryPayloadLength() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testBinaryPayloadLength(int size) throws Exception
|
||||
{
|
||||
byte payload[] = new byte[size];
|
||||
Arrays.fill(payload, (byte) 0xFE);
|
||||
@ -124,9 +125,10 @@ public class PayloadLengthTest extends AbstractLocalServerCase
|
||||
session.expect(expect);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinaryPayloadLength_SmallBuffers() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testBinaryPayloadLength_SmallBuffers(int size) throws Exception
|
||||
{
|
||||
byte payload[] = new byte[size];
|
||||
Arrays.fill(payload, (byte) 0xFE);
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@ -28,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.Sha1Sum;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
@ -43,15 +45,14 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoServlet;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class PerMessageDeflateExtensionTest
|
||||
{
|
||||
@WebSocket
|
||||
@ -83,56 +84,32 @@ public class PerMessageDeflateExtensionTest
|
||||
}
|
||||
}
|
||||
|
||||
private enum TestCaseMessageSize
|
||||
public static Stream<Arguments> modes()
|
||||
{
|
||||
TINY(10),
|
||||
SMALL(1024),
|
||||
MEDIUM(10 * 1024),
|
||||
LARGE(100 * 1024),
|
||||
HUGE(1024 * 1024);
|
||||
List<Scenario> modes = new ArrayList<>();
|
||||
|
||||
private int size;
|
||||
|
||||
TestCaseMessageSize(int size)
|
||||
for(Sizes size: Sizes.values())
|
||||
{
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
@Parameters(name = "{0} ({3}) (Input Buffer Size: {4} bytes)")
|
||||
public static List<Object[]> modes()
|
||||
{
|
||||
List<Object[]> modes = new ArrayList<>();
|
||||
|
||||
for (TestCaseMessageSize size : TestCaseMessageSize.values())
|
||||
{
|
||||
modes.add(new Object[]{"Normal HTTP/WS", false, "ws", size, -1});
|
||||
modes.add(new Object[]{"Encrypted HTTPS/WSS", true, "wss", size, -1});
|
||||
int altInputBufSize = 15 * 1024;
|
||||
modes.add(new Object[]{"Normal HTTP/WS", false, "ws", size, altInputBufSize});
|
||||
modes.add(new Object[]{"Encrypted HTTPS/WSS", true, "wss", size, altInputBufSize});
|
||||
modes.add(new Scenario("Normal HTTP/WS", false, "ws", size, -1 ));
|
||||
modes.add(new Scenario( "Encrypted HTTPS/WSS", true, "wss", size, -1 ));
|
||||
int altInputBufSize = 15*1024;
|
||||
modes.add(new Scenario( "Normal HTTP/WS", false, "ws", size, altInputBufSize ));
|
||||
modes.add(new Scenario( "Encrypted HTTPS/WSS", true, "wss", size, altInputBufSize ));
|
||||
}
|
||||
|
||||
return modes;
|
||||
return modes.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
private SimpleServletServer server;
|
||||
private String scheme;
|
||||
private int msgSize;
|
||||
private int inputBufferSize;
|
||||
|
||||
public PerMessageDeflateExtensionTest(String testId, boolean sslMode, String scheme, TestCaseMessageSize msgSize, int bufferSize) throws Exception
|
||||
private void startServer(Scenario scenario) throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new BinaryHashServlet());
|
||||
server.enableSsl(sslMode);
|
||||
server = new SimpleServletServer(new EchoServlet());
|
||||
server.enableSsl(scenario.sslMode);
|
||||
server.start();
|
||||
|
||||
this.scheme = scheme;
|
||||
this.msgSize = msgSize.size;
|
||||
this.inputBufferSize = bufferSize;
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
@ -140,33 +117,38 @@ public class PerMessageDeflateExtensionTest
|
||||
|
||||
/**
|
||||
* Default configuration for permessage-deflate
|
||||
*
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testPerMessageDeflateDefault() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("modes")
|
||||
public void testPerMessageDeflateDefault(Scenario scenario) throws Exception
|
||||
{
|
||||
Assume.assumeTrue("Server has permessage-deflate registered",
|
||||
server.getWebSocketServletFactory().getExtensionFactory().isAvailable("permessage-deflate"));
|
||||
startServer(scenario);
|
||||
|
||||
Assert.assertThat("server scheme", server.getServerUri().getScheme(), is(scheme));
|
||||
assumeTrue(server.getWebSocketServletFactory().getExtensionFactory().isAvailable("permessage-deflate"),
|
||||
"Server has permessage-deflate registered");
|
||||
|
||||
int binBufferSize = (int) (msgSize * 1.5);
|
||||
assertThat("server scheme",server.getServerUri().getScheme(),is(scenario.scheme));
|
||||
|
||||
int binBufferSize = (int) (scenario.msgSize.size * 1.5);
|
||||
|
||||
WebSocketPolicy serverPolicy = server.getWebSocketServletFactory().getPolicy();
|
||||
|
||||
// Ensure binBufferSize is sane (not smaller then other buffers)
|
||||
binBufferSize = Math.max(binBufferSize, serverPolicy.getMaxBinaryMessageSize());
|
||||
binBufferSize = Math.max(binBufferSize, this.inputBufferSize);
|
||||
binBufferSize = Math.max(binBufferSize,serverPolicy.getMaxBinaryMessageSize());
|
||||
binBufferSize = Math.max(binBufferSize,serverPolicy.getMaxBinaryMessageBufferSize());
|
||||
binBufferSize = Math.max(binBufferSize,scenario.inputBufferSize);
|
||||
|
||||
serverPolicy.setMaxBinaryMessageSize(binBufferSize);
|
||||
serverPolicy.setMaxBinaryMessageBufferSize(binBufferSize);
|
||||
|
||||
WebSocketClient client = new WebSocketClient(server.getSslContextFactory());
|
||||
WebSocketPolicy clientPolicy = client.getPolicy();
|
||||
clientPolicy.setMaxBinaryMessageSize(binBufferSize);
|
||||
if (inputBufferSize > 0)
|
||||
clientPolicy.setMaxBinaryMessageBufferSize(binBufferSize);
|
||||
if (scenario.inputBufferSize > 0)
|
||||
{
|
||||
clientPolicy.setInputBufferSize(inputBufferSize);
|
||||
clientPolicy.setInputBufferSize(scenario.inputBufferSize);
|
||||
}
|
||||
|
||||
try
|
||||
@ -175,20 +157,20 @@ public class PerMessageDeflateExtensionTest
|
||||
// Make sure the read times out if there are problems with the implementation
|
||||
client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(15));
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint("Client");
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(scenario.toString());
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.addExtensions("permessage-deflate");
|
||||
request.setSubProtocols("echo");
|
||||
|
||||
Future<Session> fut = client.connect(clientSocket, server.getServerUri(), request);
|
||||
Future<Session> fut = client.connect(clientSocket,server.getServerUri(),request);
|
||||
|
||||
// Wait for connect
|
||||
Session session = fut.get(30, TimeUnit.SECONDS);
|
||||
Session session = fut.get(30,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Response.extensions", getNegotiatedExtensionList(session), containsString("permessage-deflate"));
|
||||
assertThat("Response.extensions",getNegotiatedExtensionList(session),containsString("permessage-deflate"));
|
||||
|
||||
// Create message
|
||||
byte msg[] = new byte[msgSize];
|
||||
byte msg[] = new byte[scenario.msgSize.size];
|
||||
Random rand = new Random();
|
||||
rand.setSeed(8080);
|
||||
rand.nextBytes(msg);
|
||||
@ -200,7 +182,7 @@ public class PerMessageDeflateExtensionTest
|
||||
session.getRemote().sendBytes(ByteBuffer.wrap(msg));
|
||||
|
||||
String echoMsg = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertThat("Echo'd Message", echoMsg, is("binary[sha1=" + sha1 + "]"));
|
||||
assertThat("Echo'd Message", echoMsg, is("binary[sha1=" + sha1 + "]"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -225,4 +207,44 @@ public class PerMessageDeflateExtensionTest
|
||||
|
||||
return actual.toString();
|
||||
}
|
||||
|
||||
public enum Sizes
|
||||
{
|
||||
TINY(10),
|
||||
SMALL(1024),
|
||||
MEDIUM(10*1024),
|
||||
LARGE(100*1024),
|
||||
HUGE(1024*1024);
|
||||
|
||||
private int size;
|
||||
|
||||
Sizes(int size)
|
||||
{
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Scenario
|
||||
{
|
||||
public final String mode;
|
||||
public final boolean sslMode;
|
||||
public final String scheme;
|
||||
public final Sizes msgSize;
|
||||
public final int inputBufferSize;
|
||||
|
||||
public Scenario(String mode, boolean sslMode, String scheme, Sizes msgSize, int bufferSize)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.sslMode = sslMode;
|
||||
this.scheme = scheme;
|
||||
this.msgSize = msgSize;
|
||||
this.inputBufferSize = bufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s (%s) (Input Buffer Size: %,d bytes)", mode, scheme, msgSize.size);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import java.net.URI;
|
||||
@ -38,14 +39,11 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.Defaults;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.eclipse.jetty.websocket.tests.TrackingEndpoint;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SubProtocolTest
|
||||
{
|
||||
@ -99,32 +97,29 @@ public class SubProtocolTest
|
||||
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new ProtocolServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private WebSocketClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
@ -147,7 +142,7 @@ public class SubProtocolTest
|
||||
URI wsUri = server.getServerUri();
|
||||
client.setMaxIdleTimeout(1000);
|
||||
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
TrackingEndpoint clientSocket = new TrackingEndpoint("testSubProtocol");
|
||||
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
|
||||
upgradeRequest.setSubProtocols(requestProtocols);
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri, upgradeRequest);
|
||||
@ -159,7 +154,7 @@ public class SubProtocolTest
|
||||
|
||||
// Read message
|
||||
String incomingMsg = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertThat("Incoming Message", incomingMsg, is("acceptedSubprotocol=" + acceptedSubProtocols));
|
||||
assertThat("Incoming Message", incomingMsg, is("acceptedSubprotocol=" + acceptedSubProtocols));
|
||||
|
||||
clientSession.close();
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SuspendResumeTest
|
||||
{
|
||||
@ -71,7 +70,7 @@ public class SuspendResumeTest
|
||||
@Override
|
||||
public void writeFailed(Throwable t)
|
||||
{
|
||||
Assert.fail(t.getMessage());
|
||||
fail(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -99,20 +98,20 @@ public class SuspendResumeTest
|
||||
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new BackPressureServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
public void testSuspendResume_Bulk() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
@ -132,7 +131,7 @@ public class SuspendResumeTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
public void testSuspendResume_SmallBuffers() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
@ -152,7 +151,7 @@ public class SuspendResumeTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
public void testSuspendResume_AsFrames() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
|
@ -39,7 +39,7 @@ import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.servlets.EchoSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* UTF-8 Tests
|
||||
|
@ -20,8 +20,8 @@ package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.Hex;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
@ -30,21 +30,18 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Tests of Known Good UTF8 sequences.
|
||||
* <p>
|
||||
* Should be preserved / echoed back, with normal close code.
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class Text_GoodUtf8Test extends AbstractLocalServerCase
|
||||
{
|
||||
@Parameters(name = "{0} - {1}")
|
||||
public static Collection<String[]> data()
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
// The various Good UTF8 sequences as a String (hex form)
|
||||
List<String[]> data = new ArrayList<>();
|
||||
@ -114,20 +111,15 @@ public class Text_GoodUtf8Test extends AbstractLocalServerCase
|
||||
data.add(new String[]{"6.23.1", "EFBFBD"});
|
||||
// @formatter:on
|
||||
|
||||
return data;
|
||||
return data.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
private final ByteBuffer msg;
|
||||
|
||||
public Text_GoodUtf8Test(String testId, String hexMsg)
|
||||
{
|
||||
LOG.debug("Test ID: {}", testId);
|
||||
this.msg = Hex.asByteBuffer(hexMsg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEchoTextMessage() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void assertEchoTextMessage(String testId, String hexMsg) throws Exception
|
||||
{
|
||||
ByteBuffer msg = Hex.asByteBuffer(hexMsg);
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new TextFrame().setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.MappedByteBufferPool;
|
||||
@ -32,7 +32,7 @@ import org.eclipse.jetty.util.log.StdErrLog;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class WebSocketServerFactoryTest
|
||||
{
|
||||
|
@ -26,9 +26,9 @@ import org.eclipse.jetty.websocket.common.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Testing various aspects of the server side support for WebSocket {@link org.eclipse.jetty.websocket.api.Session}
|
||||
@ -37,14 +37,14 @@ public class WebSocketServerSessionTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new SessionServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,9 +18,11 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.anything;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -51,14 +53,11 @@ import org.eclipse.jetty.websocket.tests.UntrustedWSClient;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSConnection;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test various <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a> specified requirements placed on {@link WebSocketServlet}
|
||||
@ -67,7 +66,7 @@ public class WebSocketServletRFCTest
|
||||
{
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new WebSocketServlet()
|
||||
@ -81,25 +80,22 @@ public class WebSocketServletRFCTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private UntrustedWSClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
client = new UntrustedWSClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
@ -182,7 +178,7 @@ public class WebSocketServletRFCTest
|
||||
ccCount++;
|
||||
break;
|
||||
default:
|
||||
Assert.fail(String.format("Encountered invalid byte 0x%02X", (byte) (0xFF & b)));
|
||||
fail(String.format("Encountered invalid byte 0x%02X", (byte) (0xFF & b)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,14 +189,16 @@ public class WebSocketServletRFCTest
|
||||
clientSession.close();
|
||||
}
|
||||
|
||||
@Test(expected = NotUtf8Exception.class)
|
||||
@Test
|
||||
public void testDetectBadUTF8()
|
||||
{
|
||||
byte buf[] = new byte[]
|
||||
{(byte) 0xC2, (byte) 0xC3};
|
||||
|
||||
Utf8StringBuilder utf = new Utf8StringBuilder();
|
||||
utf.append(buf, 0, buf.length);
|
||||
|
||||
assertThrows(NotUtf8Exception.class, ()->{
|
||||
Utf8StringBuilder utf = new Utf8StringBuilder();
|
||||
utf.append(buf, 0, buf.length);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,117 +18,238 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class WebSocketUpgradeFilterEmbeddedTest extends WebSocketUpgradeFilterTest
|
||||
public class WebSocketUpgradeFilterEmbeddedTest
|
||||
{
|
||||
private interface Case
|
||||
private static AtomicInteger uniqTestDirId = new AtomicInteger(0);
|
||||
private LocalServer server;
|
||||
|
||||
protected static File getNewTestDir()
|
||||
{
|
||||
void customize(ServletContextHandler context) throws Exception;
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
FS.ensureDirExists(testDir);
|
||||
return testDir;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static List<Object[]> data()
|
||||
|
||||
public static Stream<Arguments> scenarios()
|
||||
{
|
||||
final WebSocketCreator infoCreator = (req, resp) -> new InfoSocket();
|
||||
|
||||
List<Object[]> cases = new ArrayList<>();
|
||||
|
||||
|
||||
List<Arguments> cases = new ArrayList<>();
|
||||
|
||||
// Embedded WSUF.configureContext(), directly app-ws configuration
|
||||
|
||||
cases.add(new Object[]
|
||||
{"wsuf.configureContext/Direct configure", (Case) (context) ->
|
||||
{
|
||||
WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
|
||||
// direct configuration via WSUF
|
||||
wsuf.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||
wsuf.addMapping("/info/*", infoCreator);
|
||||
}});
|
||||
|
||||
// Embedded WSUF.configureContext(), apply app-ws configuration via attribute
|
||||
|
||||
cases.add(new Object[]{
|
||||
"wsuf.configureContext/Attribute based configure", (Case) (context) ->
|
||||
|
||||
cases.add(Arguments.of("wsuf.configureContext/Direct configure", (ContextProvider) (server1) ->
|
||||
{
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server1.setHandler(context);
|
||||
|
||||
WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
|
||||
|
||||
// direct configuration via WSUF
|
||||
wsuf.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||
wsuf.addMapping("/info/*", infoCreator);
|
||||
|
||||
return context;
|
||||
}));
|
||||
|
||||
// Embedded WSUF.configureContext(), apply app-ws configuration via attribute
|
||||
|
||||
cases.add(Arguments.of("wsuf.configureContext/Attribute based configure", (ContextProvider) (server12) ->
|
||||
{
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server12.setHandler(context);
|
||||
|
||||
WebSocketUpgradeFilter.configureContext(context);
|
||||
|
||||
|
||||
// configuration via attribute
|
||||
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||
assertThat("NativeWebSocketConfiguration", configuration, notNullValue());
|
||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||
configuration.addMapping("/info/*", infoCreator);
|
||||
}});
|
||||
|
||||
|
||||
return context;
|
||||
}));
|
||||
|
||||
// Embedded WSUF, added as filter, apply app-ws configuration via attribute
|
||||
|
||||
cases.add(new Object[]{
|
||||
"wsuf/addFilter/Attribute based configure", (Case) (context) ->
|
||||
|
||||
cases.add(Arguments.of("wsuf/addFilter/Attribute based configure", (ContextProvider) (server13) ->
|
||||
{
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server13.setHandler(context);
|
||||
context.addFilter(WebSocketUpgradeFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
|
||||
|
||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||
configuration.addMapping("/info/*", infoCreator);
|
||||
context.setAttribute(NativeWebSocketConfiguration.class.getName(), configuration);
|
||||
}});
|
||||
|
||||
|
||||
return context;
|
||||
}));
|
||||
|
||||
// Embedded WSUF, added as filter, apply app-ws configuration via wsuf constructor
|
||||
|
||||
cases.add(new Object[]{
|
||||
"wsuf/addFilter/WSUF Constructor configure", (Case) (context) ->
|
||||
{
|
||||
|
||||
cases.add(Arguments.of("wsuf/addFilter/WSUF Constructor configure", (ContextProvider) (server) -> {
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||
configuration.addMapping("/info/*", infoCreator);
|
||||
context.addBean(configuration, true);
|
||||
|
||||
|
||||
FilterHolder wsufHolder = new FilterHolder(new WebSocketUpgradeFilter(configuration));
|
||||
context.addFilter(wsufHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
}});
|
||||
|
||||
|
||||
return context;
|
||||
}));
|
||||
|
||||
// Embedded WSUF, added as filter, apply app-ws configuration via ServletContextListener
|
||||
|
||||
cases.add(new Object[]{
|
||||
"wsuf.configureContext/ServletContextListener configure", (Case) (context) ->
|
||||
|
||||
cases.add(Arguments.of("wsuf.configureContext/ServletContextListener configure", (ContextProvider) (server14) ->
|
||||
{
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server14.setHandler(context);
|
||||
context.addFilter(WebSocketUpgradeFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
context.addEventListener(new InfoContextListener());
|
||||
}});
|
||||
|
||||
return cases;
|
||||
|
||||
return context;
|
||||
}));
|
||||
|
||||
return cases.stream();
|
||||
}
|
||||
|
||||
public WebSocketUpgradeFilterEmbeddedTest(String testid, Case testcase) throws Exception
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
super(newServer(testcase));
|
||||
server.stop();
|
||||
}
|
||||
|
||||
private static LocalServer newServer(Case testcase)
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testNormalConfiguration(String testId, ContextProvider serverProvider) throws Exception
|
||||
{
|
||||
return new LocalServer()
|
||||
startServer(serverProvider);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testStopStartOfHandler(String testId, ContextProvider serverProvider) throws Exception
|
||||
{
|
||||
startServer(serverProvider);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 1"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
|
||||
server.getServletContextHandler().stop();
|
||||
server.getServletContextHandler().start();
|
||||
|
||||
// Make request again (server should have retained websocket configuration)
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 2"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
|
||||
private void startServer(ContextProvider contextProvider) throws Exception
|
||||
{
|
||||
this.server = new LocalServer()
|
||||
{
|
||||
@Override
|
||||
protected void configureServletContextHandler(ServletContextHandler context) throws Exception
|
||||
protected Handler createRootHandler(Server server) throws Exception
|
||||
{
|
||||
testcase.customize(context);
|
||||
return contextProvider.configureRootHandler(server);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
interface ContextProvider
|
||||
{
|
||||
Handler configureRootHandler(Server server) throws Exception;
|
||||
}
|
||||
}
|
||||
|
@ -1,135 +0,0 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
public abstract class WebSocketUpgradeFilterTest
|
||||
{
|
||||
private static AtomicInteger uniqTestDirId = new AtomicInteger(0);
|
||||
|
||||
protected static File getNewTestDir()
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
FS.ensureDirExists(testDir);
|
||||
return testDir;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestName testname = new TestName();
|
||||
|
||||
private LocalServer server;
|
||||
|
||||
public WebSocketUpgradeFilterTest(LocalServer server) throws Exception
|
||||
{
|
||||
this.server = server;
|
||||
this.server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalConfiguration() throws Exception
|
||||
{
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopStartOfHandler() throws Exception
|
||||
{
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 1"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
|
||||
server.getServletContextHandler().stop();
|
||||
server.getServletContextHandler().start();
|
||||
|
||||
// Make request again (server should have retained websocket configuration)
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 2"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
}
|
@ -18,47 +18,128 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.WSServer;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class WebSocketUpgradeFilterWebappTest extends WebSocketUpgradeFilterTest
|
||||
public class WebSocketUpgradeFilterWebappTest
|
||||
{
|
||||
private interface Case
|
||||
private static AtomicInteger uniqTestDirId = new AtomicInteger(0);
|
||||
|
||||
private static File getNewTestDir()
|
||||
{
|
||||
void customize(WSServer server) throws Exception;
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
FS.ensureDirExists(testDir);
|
||||
return testDir;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static List<Object[]> data()
|
||||
|
||||
interface ServerConfiguration
|
||||
{
|
||||
List<Object[]> cases = new ArrayList<>();
|
||||
void configure(WSServer server) throws Exception;
|
||||
}
|
||||
|
||||
public static Stream<Arguments> scenarios()
|
||||
{
|
||||
List<Arguments> cases = new ArrayList<>();
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener with WEB-INF/lib/jetty-http.jar
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener/jetty-http.jar", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
// Add a jetty-http.jar to ensure that the classloader constraints
|
||||
// and the WebAppClassloader setup is sane and correct
|
||||
// The odd version string is present to capture bad regex behavior in Jetty
|
||||
server.copyLib(PathSpec.class, "jetty-http-9.99.999.jar");
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via Servlet.init
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/Servlet.init", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-servlet-init.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoServlet.class);
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// xml based, wsuf, on alternate url-pattern and config attribute location
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener/alt-config", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-alt-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAltAttributeListener.class);
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener
|
||||
|
||||
cases.add(new Object[]{
|
||||
cases.add(Arguments.of(
|
||||
"From ServletContextListener",
|
||||
(Case) (server) ->
|
||||
(ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
server.start();
|
||||
}
|
||||
});
|
||||
));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener with WEB-INF/lib/jetty-http.jar
|
||||
|
||||
cases.add(new Object[]{
|
||||
cases.add(Arguments.of(
|
||||
"From ServletContextListener with jar scanning",
|
||||
(Case) (server) ->
|
||||
(ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
@ -66,46 +147,95 @@ public class WebSocketUpgradeFilterWebappTest extends WebSocketUpgradeFilterTest
|
||||
// Add a jetty-http.jar to ensure that the classloader constraints
|
||||
// and the WebAppClassloader setup is sane and correct
|
||||
// The odd version string is present to capture bad regex behavior in Jetty
|
||||
server.copyLib(org.eclipse.jetty.http.pathmap.PathSpec.class, "jetty-http-9.99.999.jar");
|
||||
server.copyLib(PathSpec.class, "jetty-http-9.99.999.jar");
|
||||
server.start();
|
||||
}
|
||||
});
|
||||
|
||||
return cases;
|
||||
));
|
||||
|
||||
return cases.stream();
|
||||
}
|
||||
|
||||
public WebSocketUpgradeFilterWebappTest(String testid, Case testcase) throws Exception
|
||||
private void startServer(ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
super(newServer(testcase));
|
||||
WSServer server = new WSServer(getNewTestDir(), "/");
|
||||
serverConfiguration.configure(server);
|
||||
}
|
||||
|
||||
private static WSServer newServer(Case testcase)
|
||||
|
||||
private WSServer server;
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
return new WSServer(getNewTestDir(), "")
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testNormalConfiguration(String testId, ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
startServer(serverConfiguration);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
private WebAppContext webapp;
|
||||
|
||||
@Override
|
||||
protected Handler createRootHandler(Server server) throws Exception
|
||||
{
|
||||
Handler handler = super.createRootHandler(server);
|
||||
testcase.customize(this);
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContextHandler getServletContextHandler()
|
||||
{
|
||||
return this.webapp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
super.doStart();
|
||||
|
||||
this.webapp = createWebAppContext();
|
||||
deployWebapp(webapp);
|
||||
}
|
||||
};
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testStopStartOfHandler(String testId, ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
startServer(serverConfiguration);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 1"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
|
||||
server.getServletContextHandler().stop();
|
||||
server.getServletContextHandler().start();
|
||||
|
||||
// Make request again (server should have retained websocket configuration)
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 2"),
|
||||
new CloseInfo(StatusCode.NORMAL).asFrame()
|
||||
);
|
||||
|
||||
BlockingQueue<WebSocketFrame> framesQueue = session.getOutputFrames();
|
||||
WebSocketFrame frame = framesQueue.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Frame.opCode", frame.getOpCode(), is(OpCode.TEXT));
|
||||
|
||||
// If we can connect and send a text message, we know that the endpoint was
|
||||
// added properly, and the response will help us verify the policy configuration too
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,8 @@ import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.jsr356.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.jsr356.encoders.AvailableEncoders;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public abstract class AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
@ -45,7 +43,7 @@ public abstract class AbstractJsrEndpointFunctionsTest
|
||||
protected static SimpleContainerScope containerScope;
|
||||
protected static ClientContainer container;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void initContainer() throws Exception
|
||||
{
|
||||
containerScope = new SimpleContainerScope(clientPolicy);
|
||||
@ -54,16 +52,13 @@ public abstract class AbstractJsrEndpointFunctionsTest
|
||||
container.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopClientContainer() throws Exception
|
||||
{
|
||||
container.stop();
|
||||
containerScope.stop();
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
protected AvailableEncoders encoders;
|
||||
protected AvailableDecoders decoders;
|
||||
protected Map<String, String> uriParams = new HashMap<>();
|
||||
|
@ -39,9 +39,9 @@ import org.eclipse.jetty.websocket.tests.jsr356.coders.DateDecoder;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.TimeEncoder;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.configs.EchoSocketConfigurator;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.sockets.ConfiguredEchoSocket;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Example of an annotated echo server discovered via annotation scanning.
|
||||
@ -52,7 +52,7 @@ public class AnnotatedServerEndpointTest
|
||||
|
||||
private static WSServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
Path testdir = MavenTestingUtils.getTargetTestingPath(AnnotatedServerEndpointTest.class.getName());
|
||||
@ -69,7 +69,7 @@ public class AnnotatedServerEndpointTest
|
||||
server.deployWebapp(webapp);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -45,9 +45,9 @@ import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainer
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BinaryStreamTest
|
||||
{
|
||||
@ -56,7 +56,7 @@ public class BinaryStreamTest
|
||||
private static LocalServer server;
|
||||
private static ServerContainer container;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -72,7 +72,7 @@ public class BinaryStreamTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
@ -30,6 +31,8 @@ import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidCloseIntSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidErrorErrorSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidErrorExceptionSocket;
|
||||
@ -37,56 +40,42 @@ import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidErrorIntSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidOpenCloseReasonSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidOpenIntSocket;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.InvalidOpenSessionIntSocket;
|
||||
import org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Deploy various {@link ServerEndpoint} annotated classes with invalid signatures,
|
||||
* check for {@link DeploymentException}
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DeploymentExceptionTest
|
||||
{
|
||||
@Parameters(name = "{0}")
|
||||
public static Collection<Class<?>[]> data()
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Class<?>[]> data = new ArrayList<>();
|
||||
|
||||
data.add(new Class<?>[]{InvalidCloseIntSocket.class});
|
||||
data.add(new Class<?>[]{InvalidErrorErrorSocket.class});
|
||||
data.add(new Class<?>[]{InvalidErrorExceptionSocket.class});
|
||||
data.add(new Class<?>[]{InvalidErrorIntSocket.class});
|
||||
data.add(new Class<?>[]{InvalidOpenCloseReasonSocket.class});
|
||||
data.add(new Class<?>[]{InvalidOpenIntSocket.class});
|
||||
data.add(new Class<?>[]{InvalidOpenSessionIntSocket.class});
|
||||
|
||||
Class<?> invalidSockets[] = new Class[] {
|
||||
InvalidCloseIntSocket.class,
|
||||
InvalidErrorErrorSocket.class,
|
||||
InvalidErrorExceptionSocket.class,
|
||||
InvalidErrorIntSocket.class,
|
||||
InvalidOpenCloseReasonSocket.class,
|
||||
InvalidOpenIntSocket.class,
|
||||
InvalidOpenSessionIntSocket.class
|
||||
};
|
||||
|
||||
// TODO: invalid return types
|
||||
// TODO: static methods
|
||||
// TODO: private or protected methods
|
||||
// TODO: abstract methods
|
||||
|
||||
return data;
|
||||
return Arrays.stream(invalidSockets).map(Arguments::of);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
/** The pojo to test */
|
||||
@Parameterized.Parameter(0)
|
||||
public Class<?> pojo;
|
||||
|
||||
private Server server;
|
||||
private HandlerCollection contexts;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = new Server(0);
|
||||
@ -95,14 +84,15 @@ public class DeploymentExceptionTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeploy_InvalidSignature() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testDeploy_InvalidSignature(Class<?> pojo) throws Exception
|
||||
{
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
|
||||
@ -116,8 +106,7 @@ public class DeploymentExceptionTest
|
||||
try
|
||||
{
|
||||
context.start();
|
||||
expectedException.expect(DeploymentException.class);
|
||||
container.addEndpoint(pojo);
|
||||
assertThrows(DeploymentException.class, () -> container.addEndpoint(pojo));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -19,8 +19,8 @@
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -36,15 +36,15 @@ import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.WSServer;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.sockets.IdleTimeoutOnOpenEndpoint;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.sockets.IdleTimeoutOnOpenSocket;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IdleTimeoutTest
|
||||
{
|
||||
private static WSServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setupServer() throws Exception
|
||||
{
|
||||
server = new WSServer(MavenTestingUtils.getTargetTestingPath(IdleTimeoutTest.class.getName()), "app");
|
||||
@ -63,7 +63,7 @@ public class IdleTimeoutTest
|
||||
// wsb.dump();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -41,9 +41,9 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Decoder.BinaryStream Decoder.BinaryStream} echo behavior of Java InputStreams
|
||||
@ -89,7 +89,7 @@ public class InputStreamEchoTest
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -105,7 +105,7 @@ public class InputStreamEchoTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnMessage;
|
||||
@ -38,16 +39,15 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Tests various ways to echo with JSR356
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class JsrEchoTest
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
@ -158,22 +158,15 @@ public class JsrEchoTest
|
||||
EchoAsyncStatelessSocket.class,
|
||||
EchoReturnTextSocket.class);
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static List<Object[]> data()
|
||||
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : TESTCLASSES)
|
||||
{
|
||||
data.add(new Object[]{clazz.getSimpleName(), clazz});
|
||||
}
|
||||
|
||||
return data;
|
||||
return TESTCLASSES.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -192,20 +185,15 @@ public class JsrEchoTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String endpointClassname;
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public Class<?> endpointClass;
|
||||
|
||||
@Test
|
||||
public void testTextEcho() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testTextEcho(Class<?> endpointClass) throws Exception
|
||||
{
|
||||
String requestPath = endpointClass.getAnnotation(ServerEndpoint.class).value();
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -36,7 +36,7 @@ import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.common.function.EndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.JsrServerEndpointFunctions;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.sockets.TrackingSocket;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsrServerEndpointFunctions_OnMessage_TextStreamTest extends AbstractJsrEndpointFunctionsTest
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
* Test Echo of Large messages, targeting the {@link javax.websocket.Session#setMaxTextMessageBufferSize(int)} functionality
|
||||
|
@ -18,11 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
|
@ -42,7 +42,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
@ExtendWith( WorkDirExtension.class)
|
||||
public class OnMessageReturnTest
|
||||
|
@ -40,9 +40,9 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Sends raw TEXT or BINARY messages to server.
|
||||
@ -108,7 +108,7 @@ public class PartialEchoTest
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -124,7 +124,7 @@ public class PartialEchoTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -19,8 +19,8 @@
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -54,9 +54,9 @@ import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.tests.WSServer;
|
||||
import org.eclipse.jetty.websocket.tests.client.jsr356.JsrClientEchoTrackingSocket;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PingPongTest
|
||||
{
|
||||
@ -145,7 +145,7 @@ public class PingPongTest
|
||||
private static URI serverUri;
|
||||
private static WebSocketContainer client;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
Path testdir = MavenTestingUtils.getTargetTestingPath(PingPongTest.class.getName());
|
||||
@ -163,13 +163,13 @@ public class PingPongTest
|
||||
server.deployWebapp(webapp);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startClient() throws Exception
|
||||
{
|
||||
client = ContainerProvider.getWebSocketContainer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
@ -207,7 +207,7 @@ public class PingPongTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 6000)
|
||||
@Test
|
||||
public void testPongEndpoint() throws Exception
|
||||
{
|
||||
assertEcho("/app/pong", (session) -> {
|
||||
@ -222,7 +222,7 @@ public class PingPongTest
|
||||
}, "PongMessageEndpoint.onMessage(PongMessage):[/pong]:hello");
|
||||
}
|
||||
|
||||
@Test(timeout = 6000)
|
||||
@Test
|
||||
public void testPongSocket() throws Exception
|
||||
{
|
||||
assertEcho("/app/pong-socket", (session) -> {
|
||||
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
@ -39,20 +40,19 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Decoder.Binary Decoder.Binary} / {@link javax.websocket.Encoder.Binary Encoder.Binary} echo behavior of Java Primitives
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class PrimitivesBinaryEchoTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(PrimitivesBinaryEchoTest.class);
|
||||
|
||||
|
||||
public static class BaseSocket
|
||||
{
|
||||
@OnError
|
||||
@ -61,7 +61,7 @@ public class PrimitivesBinaryEchoTest
|
||||
LOG.warn("Error", cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ServerEndpoint("/echo/bytebuffer")
|
||||
public static class ByteBufferEchoSocket extends BaseSocket
|
||||
{
|
||||
@ -75,7 +75,7 @@ public class PrimitivesBinaryEchoTest
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ServerEndpoint("/echo/bytearray")
|
||||
public static class ByteArrayEchoSocket extends BaseSocket
|
||||
{
|
||||
@ -88,31 +88,25 @@ public class PrimitivesBinaryEchoTest
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addCase(List<Object[]> data, Class<?> endpointClass, String sendHex, String expectHex)
|
||||
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
data.add(new Object[]{endpointClass.getSimpleName(), endpointClass, sendHex, expectHex});
|
||||
List<Arguments> data = new ArrayList<>();
|
||||
|
||||
data.add(Arguments.of(ByteBufferEchoSocket.class, "00", "FF00"));
|
||||
data.add(Arguments.of(ByteBufferEchoSocket.class, "001133445566778899AA", "FF001133445566778899AA"));
|
||||
data.add(Arguments.of(ByteBufferEchoSocket.class, "11112222333344445555", "FF11112222333344445555"));
|
||||
|
||||
data.add(Arguments.of(ByteArrayEchoSocket.class, "00", "FE00"));
|
||||
data.add(Arguments.of(ByteArrayEchoSocket.class, "001133445566778899AA", "FE001133445566778899AA"));
|
||||
data.add(Arguments.of(ByteArrayEchoSocket.class, "11112222333344445555", "FE11112222333344445555"));
|
||||
|
||||
return data.stream();
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}: {2}")
|
||||
public static List<Object[]> data()
|
||||
{
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
|
||||
addCase(data, ByteBufferEchoSocket.class, "00", "FF00");
|
||||
addCase(data, ByteBufferEchoSocket.class, "001133445566778899AA", "FF001133445566778899AA");
|
||||
addCase(data, ByteBufferEchoSocket.class, "11112222333344445555", "FF11112222333344445555");
|
||||
|
||||
addCase(data, ByteArrayEchoSocket.class, "00", "FE00");
|
||||
addCase(data, ByteArrayEchoSocket.class, "001133445566778899AA", "FE001133445566778899AA");
|
||||
addCase(data, ByteArrayEchoSocket.class, "11112222333344445555", "FE11112222333344445555");
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -121,45 +115,34 @@ public class PrimitivesBinaryEchoTest
|
||||
protected void configureServletContextHandler(ServletContextHandler context) throws Exception
|
||||
{
|
||||
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
|
||||
|
||||
|
||||
container.addEndpoint(ByteBufferEchoSocket.class);
|
||||
container.addEndpoint(ByteArrayEchoSocket.class);
|
||||
}
|
||||
};
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String endpointClassname;
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public Class<?> endpointClass;
|
||||
|
||||
@Parameterized.Parameter(2)
|
||||
public String sendHex;
|
||||
|
||||
@Parameterized.Parameter(3)
|
||||
public String expectHex;
|
||||
|
||||
@Test
|
||||
public void testPrimitiveEcho() throws Exception
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testPrimitiveEcho(Class<?> endpointClass, String sendHex, String expectHex) throws Exception
|
||||
{
|
||||
String requestPath = endpointClass.getAnnotation(ServerEndpoint.class).value();
|
||||
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new BinaryFrame().setPayload(Hex.asByteBuffer(sendHex)));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new BinaryFrame().setPayload(Hex.asByteBuffer(expectHex)));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer(requestPath))
|
||||
{
|
||||
session.sendBulk(send);
|
||||
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
@ -37,16 +38,14 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Decoder.Text Decoder.Text} / {@link javax.websocket.Encoder.Text Encoder.Text} echo behavior of Java Primitives
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class PrimitivesTextEchoTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(PrimitivesTextEchoTest.class);
|
||||
@ -235,8 +234,7 @@ public class PrimitivesTextEchoTest
|
||||
data.add(new Object[]{endpointClass.getSimpleName(), endpointClass, sendText, expectText});
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}: {2}")
|
||||
public static List<Object[]> data()
|
||||
public static Stream<Arguments> data()
|
||||
{
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
|
||||
@ -341,12 +339,13 @@ public class PrimitivesTextEchoTest
|
||||
addCase(data, LongObjEchoSocket.class, Long.toString(Long.MIN_VALUE), Long.toString(Long.MIN_VALUE));
|
||||
|
||||
addCase(data, StringEchoSocket.class, "Hello World", "Hello World");
|
||||
return data;
|
||||
|
||||
return data.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -378,26 +377,14 @@ public class PrimitivesTextEchoTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String endpointClassname;
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public Class<?> endpointClass;
|
||||
|
||||
@Parameterized.Parameter(2)
|
||||
public String sendText;
|
||||
|
||||
@Parameterized.Parameter(3)
|
||||
public String expectText;
|
||||
|
||||
@Test
|
||||
public void testPrimitiveEcho() throws Exception
|
||||
public void testPrimitiveEcho(String endpointClassname, Class<?> endpointClass, String sendText, String expectText) throws Exception
|
||||
{
|
||||
String requestPath = endpointClass.getAnnotation(ServerEndpoint.class).value();
|
||||
|
||||
|
@ -21,7 +21,7 @@ package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@ -42,9 +42,9 @@ import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.Quotes;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.QuotesDecoder;
|
||||
import org.eclipse.jetty.websocket.tests.jsr356.coders.QuotesUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests a {@link javax.websocket.Decoder.TextStream} automatic decoding to a Socket onMessage parameter
|
||||
@ -70,7 +70,7 @@ public class QuotesDecoderTextStreamTest
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -85,7 +85,7 @@ public class QuotesDecoderTextStreamTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -40,9 +40,9 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test various {@link javax.websocket.Decoder.TextStream Decoder.TextStream} and {@link javax.websocket.Encoder.TextStream Encoder.TextStream} echo behavior of Java Readers
|
||||
@ -88,7 +88,7 @@ public class ReaderEchoTest
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -104,7 +104,7 @@ public class ReaderEchoTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -18,351 +18,251 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356;
|
||||
|
||||
import java.io.IOException;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.tests.WSServer;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.sockets.SessionAltConfig;
|
||||
import org.eclipse.jetty.websocket.tests.server.jsr356.sockets.SessionInfoSocket;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SessionTest
|
||||
{
|
||||
@ServerEndpoint(value = "/info/")
|
||||
public static class SessionInfoSocket
|
||||
public static Stream<Arguments> scenarios()
|
||||
{
|
||||
@OnMessage
|
||||
public String onMessage(javax.websocket.Session session, String message)
|
||||
{
|
||||
if ("pathParams".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("pathParams");
|
||||
Map<String, String> pathParams = session.getPathParameters();
|
||||
if (pathParams == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append('[').append(pathParams.size()).append(']');
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String key : pathParams.keySet())
|
||||
{
|
||||
keys.add(key);
|
||||
}
|
||||
Collections.sort(keys);
|
||||
for (String key : keys)
|
||||
{
|
||||
String value = pathParams.get(key);
|
||||
ret.append(": '").append(key).append("'=").append(value);
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
if ("requestUri".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("requestUri=");
|
||||
URI uri = session.getRequestURI();
|
||||
if (uri == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append(uri.toASCIIString());
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
// simple echo
|
||||
return "echo:'" + message + "'";
|
||||
}
|
||||
}
|
||||
|
||||
public static class SessionInfoEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
private javax.websocket.Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(javax.websocket.Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.session.addMessageHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ("pathParams".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("pathParams");
|
||||
Map<String, String> pathParams = session.getPathParameters();
|
||||
if (pathParams == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append('[').append(pathParams.size()).append(']');
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String key : pathParams.keySet())
|
||||
{
|
||||
keys.add(key);
|
||||
}
|
||||
Collections.sort(keys);
|
||||
for (String key : keys)
|
||||
{
|
||||
String value = pathParams.get(key);
|
||||
ret.append(": '").append(key).append("'=").append(value);
|
||||
}
|
||||
}
|
||||
session.getBasicRemote().sendText(ret.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if ("requestUri".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("requestUri=");
|
||||
URI uri = session.getRequestURI();
|
||||
if (uri == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append(uri.toASCIIString());
|
||||
}
|
||||
session.getBasicRemote().sendText(ret.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
// simple echo
|
||||
session.getBasicRemote().sendText("echo:'" + message + "'");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface Case
|
||||
{
|
||||
void customize(ServletContextHandler context);
|
||||
List<Scenario> cases = new ArrayList<>();
|
||||
|
||||
cases.add(new Scenario("no customization", (context) -> {
|
||||
// no customization here
|
||||
}));
|
||||
|
||||
cases.add(new Scenario("with DefaultServlet only",
|
||||
(context) -> context.addServlet(DefaultServlet.class, "/")
|
||||
));
|
||||
|
||||
|
||||
cases.add(new Scenario("with Servlet mapped to root-glob",
|
||||
(context) -> context.addServlet(DefaultServlet.class, "/*")
|
||||
));
|
||||
|
||||
cases.add(new Scenario("with Servlet mapped to info-glob",
|
||||
// this tests the overlap of websocket paths and servlet paths
|
||||
// the SessionInfoSocket below is also mapped to "/info/"
|
||||
(context) -> context.addServlet(DefaultServlet.class, "/info/*")
|
||||
));
|
||||
|
||||
return cases.stream().map(Arguments::of);
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Case[]> data()
|
||||
private final static AtomicInteger ID = new AtomicInteger(0);
|
||||
private WSServer server;
|
||||
private URI serverUri;
|
||||
|
||||
public void startServer(Scenario scenario) throws Exception
|
||||
{
|
||||
List<Case[]> cases = new ArrayList<>();
|
||||
cases.add(new Case[]
|
||||
{context ->
|
||||
{
|
||||
// no customization
|
||||
}});
|
||||
cases.add(new Case[]
|
||||
{context ->
|
||||
{
|
||||
// Test with DefaultServlet only
|
||||
context.addServlet(DefaultServlet.class,"/");
|
||||
}});
|
||||
cases.add(new Case[]
|
||||
{context ->
|
||||
{
|
||||
// Test with Servlet mapped to "/*"
|
||||
context.addServlet(DefaultServlet.class,"/*");
|
||||
}});
|
||||
cases.add(new Case[]
|
||||
{context ->
|
||||
{
|
||||
// Test with Servlet mapped to "/info/*"
|
||||
context.addServlet(DefaultServlet.class,"/info/*");
|
||||
}});
|
||||
return cases;
|
||||
server = new WSServer(MavenTestingUtils.getTargetTestingDir(
|
||||
SessionTest.class.getSimpleName() + "-" + ID.incrementAndGet()),"app");
|
||||
server.copyWebInf("empty-web.xml");
|
||||
server.copyClass(SessionInfoSocket.class);
|
||||
server.copyClass(SessionAltConfig.class);
|
||||
server.start();
|
||||
serverUri = server.getServerUri().resolve("/");
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
scenario.customizer.accept(webapp);
|
||||
server.deployWebapp(webapp);
|
||||
}
|
||||
|
||||
private LocalServer server;
|
||||
|
||||
@After
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
public SessionTest(final Case testcase) throws Exception
|
||||
private void assertResponse(String requestPath, String requestMessage, String expectedResponse) throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
try
|
||||
{
|
||||
@Override
|
||||
protected void configureServletContextHandler(ServletContextHandler context) throws Exception
|
||||
{
|
||||
testcase.customize(context);
|
||||
|
||||
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
|
||||
|
||||
container.addEndpoint(SessionInfoSocket.class); // default behavior
|
||||
Class<?> endpointClass = SessionInfoSocket.class;
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/{c}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/{c}/{d}/").build());
|
||||
endpointClass = SessionInfoEndpoint.class;
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/{c}/").build());
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/{c}/{d}/").build());
|
||||
}
|
||||
};
|
||||
server.start();
|
||||
}
|
||||
|
||||
private void assertResponse(String requestPath, String requestMessage,
|
||||
String expectedResponse) throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new TextFrame().setPayload(requestMessage));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new TextFrame().setPayload(expectedResponse));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer(requestPath))
|
||||
client.start();
|
||||
ClientEchoSocket clientEcho = new ClientEchoSocket();
|
||||
Future<Session> future = client.connect(clientEcho,serverUri.resolve(requestPath));
|
||||
Session session = future.get(1, TimeUnit.SECONDS);
|
||||
session.getRemote().sendString(requestMessage);
|
||||
String msg = clientEcho.messages.poll(5, TimeUnit.SECONDS);
|
||||
assertThat("Expected message",msg,is(expectedResponse));
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.sendBulk(send);
|
||||
session.expect(expect);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Annotated_Empty() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Annotated_Empty(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/","pathParams",
|
||||
"pathParams[0]");
|
||||
startServer(scenario);
|
||||
assertResponse("info/","pathParams","pathParams[0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Annotated_Single() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Annotated_Single(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/apple/","pathParams",
|
||||
"pathParams[1]: 'a'=apple");
|
||||
startServer(scenario);
|
||||
assertResponse("info/apple/","pathParams","pathParams[1]: 'a'=apple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Annotated_Double() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Annotated_Double(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/apple/pear/","pathParams",
|
||||
"pathParams[2]: 'a'=apple: 'b'=pear");
|
||||
startServer(scenario);
|
||||
assertResponse("info/apple/pear/","pathParams","pathParams[2]: 'a'=apple: 'b'=pear");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Annotated_Triple() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Annotated_Triple(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/apple/pear/cherry/","pathParams",
|
||||
"pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
|
||||
startServer(scenario);
|
||||
assertResponse("info/apple/pear/cherry/","pathParams","pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Endpoint_Empty() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Endpoint_Empty(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/","pathParams",
|
||||
"pathParams[0]");
|
||||
startServer(scenario);
|
||||
assertResponse("einfo/","pathParams","pathParams[0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Endpoint_Single() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Endpoint_Single(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/apple/","pathParams",
|
||||
"pathParams[1]: 'a'=apple");
|
||||
startServer(scenario);
|
||||
assertResponse("einfo/apple/","pathParams","pathParams[1]: 'a'=apple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Endpoint_Double() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Endpoint_Double(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/apple/pear/","pathParams",
|
||||
"pathParams[2]: 'a'=apple: 'b'=pear");
|
||||
startServer(scenario);
|
||||
assertResponse("einfo/apple/pear/","pathParams","pathParams[2]: 'a'=apple: 'b'=pear");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParams_Endpoint_Triple() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testPathParams_Endpoint_Triple(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/apple/pear/cherry/","pathParams",
|
||||
"pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
|
||||
startServer(scenario);
|
||||
assertResponse("einfo/apple/pear/cherry/","pathParams","pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Annotated_Basic() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Annotated_Basic(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/","requestUri",
|
||||
"requestUri=ws://local/info/");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("info/");
|
||||
assertResponse("info/","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Annotated_WithPathParam() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Annotated_WithPathParam(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/apple/banana/","requestUri",
|
||||
"requestUri=ws://local/info/apple/banana/");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("info/apple/banana/");
|
||||
assertResponse("info/apple/banana/","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Annotated_WithPathParam_WithQuery() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Annotated_WithPathParam_WithQuery(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/info/apple/banana/?fruit=fresh&store=grandmasfarm",
|
||||
"requestUri",
|
||||
"requestUri=ws://local/info/apple/banana/?fruit=fresh&store=grandmasfarm");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("info/apple/banana/?fruit=fresh&store=grandmasfarm");
|
||||
assertResponse("info/apple/banana/?fruit=fresh&store=grandmasfarm","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Endpoint_Basic() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Endpoint_Basic(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/","requestUri",
|
||||
"requestUri=ws://local/einfo/");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("einfo/");
|
||||
assertResponse("einfo/","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Endpoint_WithPathParam() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Endpoint_WithPathParam(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/apple/banana/","requestUri",
|
||||
"requestUri=ws://local/einfo/apple/banana/");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("einfo/apple/banana/");
|
||||
assertResponse("einfo/apple/banana/","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestUri_Endpoint_WithPathParam_WithQuery() throws Exception
|
||||
@ParameterizedTest
|
||||
@MethodSource("scenarios")
|
||||
public void testRequestUri_Endpoint_WithPathParam_WithQuery(Scenario scenario) throws Exception
|
||||
{
|
||||
assertResponse("/einfo/apple/banana/?fruit=fresh&store=grandmasfarm",
|
||||
"requestUri",
|
||||
"requestUri=ws://local/einfo/apple/banana/?fruit=fresh&store=grandmasfarm");
|
||||
startServer(scenario);
|
||||
URI expectedUri = serverUri.resolve("einfo/apple/banana/?fruit=fresh&store=grandmasfarm");
|
||||
assertResponse("einfo/apple/banana/?fruit=fresh&store=grandmasfarm","requestUri","requestUri=" + expectedUri.toASCIIString());
|
||||
}
|
||||
|
||||
@WebSocket
|
||||
public static class ClientEchoSocket
|
||||
{
|
||||
public LinkedBlockingQueue<String> messages = new LinkedBlockingQueue<>();
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onText(String msg)
|
||||
{
|
||||
messages.offer(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Scenario
|
||||
{
|
||||
public final String description;
|
||||
public final Consumer<WebAppContext> customizer;
|
||||
|
||||
public Scenario(String desc, Consumer<WebAppContext> consumer)
|
||||
{
|
||||
this.description = desc;
|
||||
this.customizer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SessionTrackingTest
|
||||
{
|
||||
@ -98,14 +98,14 @@ public class SessionTrackingTest
|
||||
|
||||
private static SimpleServletServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new SimpleServletServer(new SessionTrackingServlet());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -43,9 +43,9 @@ import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainer
|
||||
import org.eclipse.jetty.websocket.tests.DataUtils;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TextStreamTest
|
||||
{
|
||||
@ -55,7 +55,7 @@ public class TextStreamTest
|
||||
private static LocalServer server;
|
||||
private static ServerContainer container;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -71,7 +71,7 @@ public class TextStreamTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -38,9 +38,9 @@ import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalFuzzer;
|
||||
import org.eclipse.jetty.websocket.tests.LocalServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UriTemplateParameterTest
|
||||
{
|
||||
@ -64,7 +64,7 @@ public class UriTemplateParameterTest
|
||||
|
||||
private static LocalServer server;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
server = new LocalServer()
|
||||
@ -79,7 +79,7 @@ public class UriTemplateParameterTest
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
|
@ -0,0 +1,55 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356.sockets;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.server.ServerApplicationConfig;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
public class SessionAltConfig implements ServerApplicationConfig
|
||||
{
|
||||
@Override
|
||||
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses)
|
||||
{
|
||||
Set<ServerEndpointConfig> configs = new HashSet<>();
|
||||
Class<?> endpointClass = SessionInfoSocket.class;
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/{c}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/info/{a}/{b}/{c}/{d}/").build());
|
||||
endpointClass = SessionInfoEndpoint.class;
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/{c}/").build());
|
||||
configs.add(ServerEndpointConfig.Builder.create(endpointClass,"/einfo/{a}/{b}/{c}/{d}/").build());
|
||||
return configs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned)
|
||||
{
|
||||
Set<Class<?>> annotated = new HashSet<>();
|
||||
annotated.add(SessionInfoSocket.class);
|
||||
return annotated;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356.sockets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.Session;
|
||||
|
||||
public class SessionInfoEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.session.addMessageHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ("pathParams".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("pathParams");
|
||||
Map<String, String> pathParams = session.getPathParameters();
|
||||
if (pathParams == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append('[').append(pathParams.size()).append(']');
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String key : pathParams.keySet())
|
||||
{
|
||||
keys.add(key);
|
||||
}
|
||||
Collections.sort(keys);
|
||||
for (String key : keys)
|
||||
{
|
||||
String value = pathParams.get(key);
|
||||
ret.append(": '").append(key).append("'=").append(value);
|
||||
}
|
||||
}
|
||||
session.getBasicRemote().sendText(ret.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if ("requestUri".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("requestUri=");
|
||||
URI uri = session.getRequestURI();
|
||||
if (uri == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append(uri.toASCIIString());
|
||||
}
|
||||
session.getBasicRemote().sendText(ret.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
// simple echo
|
||||
session.getBasicRemote().sendText("echo:'" + message + "'");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.server.jsr356.sockets;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@ServerEndpoint(value = "/info/")
|
||||
public class SessionInfoSocket
|
||||
{
|
||||
@OnMessage
|
||||
public String onMessage(Session session, String message)
|
||||
{
|
||||
if ("pathParams".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("pathParams");
|
||||
Map<String, String> pathParams = session.getPathParameters();
|
||||
if (pathParams == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append('[').append(pathParams.size()).append(']');
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String key : pathParams.keySet())
|
||||
{
|
||||
keys.add(key);
|
||||
}
|
||||
Collections.sort(keys);
|
||||
for (String key : keys)
|
||||
{
|
||||
String value = pathParams.get(key);
|
||||
ret.append(": '").append(key).append("'=").append(value);
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
if ("requestUri".equalsIgnoreCase(message))
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("requestUri=");
|
||||
URI uri = session.getRequestURI();
|
||||
if (uri == null)
|
||||
{
|
||||
ret.append("=<null>");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append(uri.toASCIIString());
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
// simple echo
|
||||
return "echo:'" + message + "'";
|
||||
}
|
||||
}
|
@ -18,8 +18,8 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.tests.sockets.annotations;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user