use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleBlockingServerTestCase method testHeadRequests.
@Test
public void testHeadRequests() throws IOException {
message = "My HTTP Request!";
TestHttpClient client = new TestHttpClient();
HttpHead head = new HttpHead(DefaultServer.getDefaultServerURL() + "/path");
try {
for (int i = 0; i < 3; ++i) {
//WFLY-1540 run a few requests to make sure persistent re
HttpResponse result = client.execute(head);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("", HttpClientUtils.readResponse(result));
Assert.assertEquals(message.length() + "", result.getFirstHeader(Headers.CONTENT_LENGTH_STRING).getValue());
}
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleBlockingServerTestCase method testDeleteRequests.
@Test
public void testDeleteRequests() throws IOException {
message = "My HTTP Request!";
TestHttpClient client = new TestHttpClient();
HttpDelete delete = new HttpDelete(DefaultServer.getDefaultServerURL() + "/path");
try {
for (int i = 0; i < 3; ++i) {
//WFLY-1540 run a few requests to make sure persistent re
HttpResponse result = client.execute(delete);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
}
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleBlockingServerTestCase method testLargeResponse.
@Test
public void testLargeResponse() throws IOException {
final StringBuilder messageBuilder = new StringBuilder(6919638);
for (int i = 0; i < 6919638; ++i) {
messageBuilder.append("*");
}
message = messageBuilder.toString();
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String resultString = HttpClientUtils.readResponse(result);
Assert.assertEquals(message.length(), resultString.length());
Assert.assertTrue(message.equals(resultString));
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path?useSender");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String resultBody = HttpClientUtils.readResponse(result);
Assert.assertTrue(message.equals(resultBody));
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path?useFragmentedSender");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
resultBody = HttpClientUtils.readResponse(result);
Assert.assertTrue(message.equals(resultBody));
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class InMemorySessionTestCase method inMemorySessionTest.
@Test
public void inMemorySessionTest() throws IOException {
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new BasicCookieStore());
try {
final SessionCookieConfig sessionConfig = new SessionCookieConfig();
final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), sessionConfig);
handler.setNext(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
Session session = manager.getSession(exchange, sessionConfig);
if (session == null) {
session = manager.createSession(exchange, sessionConfig);
session.setAttribute(COUNT, 0);
}
Integer count = (Integer) session.getAttribute(COUNT);
exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
session.setAttribute(COUNT, ++count);
}
});
DefaultServer.setRootHandler(handler);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
Header[] header = result.getHeaders(COUNT);
Assert.assertEquals("0", header[0].getValue());
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assert.assertEquals("1", header[0].getValue());
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
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 SenderTestCase method testSyncTransfer.
@Test
public void testSyncTransfer() throws Exception {
StringBuilder sb = new StringBuilder(TXS);
for (int i = 0; i < TXS; ++i) {
sb.append("a");
}
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/transfer?blocking=true");
TestHttpClient client = new TestHttpClient();
try {
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Path file = Paths.get(SenderTestCase.class.getResource(SenderTestCase.class.getSimpleName() + ".class").toURI());
long length = Files.size(file);
byte[] data = new byte[(int) length * TXS];
for (int i = 0; i < TXS; i++) {
try (DataInputStream is = new DataInputStream(Files.newInputStream(file))) {
is.readFully(data, (int) (i * length), (int) length);
}
}
Assert.assertArrayEquals(data, HttpClientUtils.readRawResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations