use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class URLRewritingSessionTestCase method testURLRewriting.
@Test
public void testURLRewriting() throws IOException {
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new BasicCookieStore());
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath;foo=bar");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String url = HttpClientUtils.readResponse(result);
Header[] header = result.getHeaders(COUNT);
Assert.assertEquals("0", header[0].getValue());
get = new HttpGet(url);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
url = HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assert.assertEquals("1", header[0].getValue());
get = new HttpGet(url);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
url = HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assert.assertEquals("2", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServerSentEventTestCase method testRetry.
@Test
public void testRetry() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
DefaultServer.setRootHandler(new ServerSentEventHandler(new ServerSentEventConnectionCallback() {
@Override
public void connected(ServerSentEventConnection connection, String lastEventId) {
connection.sendRetry(1000, new ServerSentEventConnection.EventCallback() {
@Override
public void done(ServerSentEventConnection connection, String data, String event, String id) {
connection.shutdown();
}
@Override
public void failed(ServerSentEventConnection connection, String data, String event, String id, IOException e) {
e.printStackTrace();
IoUtils.safeClose(connection);
}
});
}
}));
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("retry:1000\n\n", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServerSentEventTestCase method testLargeMessage.
@Test
public void testLargeMessage() throws IOException {
TestHttpClient client = new TestHttpClient();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; ++i) {
sb.append("hello world ");
}
try {
DefaultServer.setRootHandler(new ServerSentEventHandler(new ServerSentEventConnectionCallback() {
@Override
public void connected(ServerSentEventConnection connection, String lastEventId) {
connection.send(sb.toString(), new ServerSentEventConnection.EventCallback() {
@Override
public void done(ServerSentEventConnection connection, String data, String event, String id) {
connection.shutdown();
}
@Override
public void failed(ServerSentEventConnection connection, String data, String event, String id, IOException e) {
e.printStackTrace();
IoUtils.safeClose(connection);
}
});
}
}));
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("data:" + sb.toString() + "\n\n", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ContentOverrunTestCase method testContentPastContentLength.
@Test
public void testContentPastContentLength() throws Exception {
final TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/long");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("Overly lon", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ContentOverrunTestCase method testContentOn204.
@Test
public void testContentOn204() throws Exception {
final TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/204");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.NO_CONTENT, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("", response);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations