@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(); } }
@Test public void testNoExtensionsConfigurator() throws Exception { URI uri = baseServerUri.resolve("/no-extensions"); try (BlockheadClient client = new BlockheadClient(uri)) { client.addExtensions("identity"); client.connect(); client.sendStandardRequest(); HttpResponse response = client.readResponseHeader(); Assert.assertThat("response.extensions", response.getExtensionsHeader(), nullValue()); } }
@Test public void testCaptureRequestHeadersConfigurator() throws Exception { URI uri = baseServerUri.resolve("/capture-request-headers"); try (BlockheadClient client = new BlockheadClient(uri)) { client.addHeader("X-Dummy: Bogus\r\n"); client.connect(); client.sendStandardRequest(); client.expectUpgradeResponse(); client.write(new TextFrame().setPayload("X-Dummy")); IncomingFramesCapture capture = client.readFrames(1, TimeUnit.SECONDS, 1); WebSocketFrame frame = capture.getFrames().poll(); Assert.assertThat( "Frame Response", frame.getPayloadAsUTF8(), is("Request Header [X-Dummy]: \"Bogus\"")); } }