use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class DecoratorsLegacyTest method testAccessRequestCookies.
@Test
public void testAccessRequestCookies() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.setTimeout(1, TimeUnit.SECONDS);
try {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("info"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame resp = frames.poll();
String textMsg = resp.getPayloadAsUTF8();
assertThat("DecoratedObjectFactory", textMsg, containsString("Object is a DecoratedObjectFactory"));
assertThat("decorators.size", textMsg, containsString("Decorators.size = [1]"));
assertThat("decorator type", textMsg, containsString("decorator[] = " + DummyLegacyDecorator.class.getName()));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class FragmentExtensionTest method testFragmentExtension.
@Test
public void testFragmentExtension() throws Exception {
int fragSize = 4;
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.clearExtensions();
client.addExtensions("fragment;maxLength=" + fragSize);
client.setProtocols("onConnect");
try {
// Make sure the read times out if there are problems with the implementation
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
HttpResponse resp = client.expectUpgradeResponse();
Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("fragment"));
String msg = "Sent as a long message that should be split";
client.write(new TextFrame().setPayload(msg));
String[] parts = split(msg, fragSize);
EventQueue<WebSocketFrame> frames = client.readFrames(parts.length, 1000, TimeUnit.MILLISECONDS);
for (int i = 0; i < parts.length; i++) {
WebSocketFrame frame = frames.poll();
Assert.assertThat("text[" + i + "].payload", frame.getPayloadAsUTF8(), is(parts[i]));
}
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class IdentityExtensionTest method testIdentityExtension.
@Test
public void testIdentityExtension() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.clearExtensions();
client.addExtensions("identity;param=0");
client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '");
client.setProtocols("onConnect");
try {
// Make sure the read times out if there are problems with the implementation
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
HttpResponse resp = client.expectUpgradeResponse();
Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("identity"));
client.write(new TextFrame().setPayload("Hello"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("TEXT.payload", frame.getPayloadAsUTF8(), is("Hello"));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class ConfiguratorTest method testUniqueUserPropsConfigurator.
@Test
public void testUniqueUserPropsConfigurator() throws Exception {
URI uri = baseServerUri.resolve("/unique-user-props");
// First request
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("apple"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [apple] = \"fruit from tree\""));
}
// Second request
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("apple"));
client.write(new TextFrame().setPayload("blueberry"));
EventQueue<WebSocketFrame> frames = client.readFrames(2, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
// should have no value
Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [apple] = <null>"));
frame = frames.poll();
Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested User Property: [blueberry] = \"fruit from bush\""));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class ConfiguratorTest method testNoExtensionsConfigurator.
@Test
public void testNoExtensionsConfigurator() throws Exception {
URI uri = baseServerUri.resolve("/no-extensions");
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.addExtensions("identity");
client.connect();
client.sendStandardRequest();
HttpResponse response = client.expectUpgradeResponse();
assertThat("response.extensions", response.getExtensionsHeader(), nullValue());
client.write(new TextFrame().setPayload("NegoExts"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("Frame Response", frame.getPayloadAsUTF8(), is("negotiatedExtensions=[]"));
}
}
Aggregations