use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletInputStreamEarlyCloseTestCase method testServletInputStreamEarlyClose.
@Test
public void testServletInputStreamEarlyClose() throws Exception {
DeploymentUtils.setupServlet(new ServletInfo(SERVLET, EarlyCloseServlet.class).addMapping("/" + SERVLET));
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + SERVLET;
HttpPost post = new HttpPost(uri);
post.setEntity(new StringEntity("A non-empty request body"));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletOutputStreamTestCase method testResetBuffer.
@Test
public void testResetBuffer() throws Exception {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + RESET;
HttpGet get = new HttpGet(uri);
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("hello world", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletOutputStreamTestCase method testFlushAndCloseWithContentLength.
@Test
public void testFlushAndCloseWithContentLength() throws Exception {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + CONTENT_LENGTH_SERVLET;
HttpGet get = new HttpGet(uri);
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("a", response);
get = new HttpGet(uri);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("OK", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ParameterEchoTestCase method testPostInUrl.
@Test
public void testPostInUrl() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/servletContext/aaa?param1=1¶m2=2¶m3=3");
final List<NameValuePair> values = new ArrayList<>();
UrlEncodedFormEntity data = new UrlEncodedFormEntity(values, "UTF-8");
post.setEntity(data);
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(RESPONSE, response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class CrossContextClassLoaderTestCase method testCrossContextRequest.
@Test
public void testCrossContextRequest() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/includer/a");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("Including Servlet Class Loader: IncluderClassLoader\n" + "Including Servlet Context Path: /includer\n" + "Included Servlet Class Loader: IncludedClassLoader\n" + "Including Servlet Context Path: /included\n", response);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations