use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletAndResourceWelcomeFileTestCase method testWelcomeFileRedirect.
@Test
public void testWelcomeFileRedirect() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("pathInfo:null queryString:null servletPath:/index.html requestUri:/servletContext/", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleServletTestCase method testSimpleHttpServlet.
@Test
public void testSimpleHttpServlet() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final 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 SimpleAsyncTestCase method testErrorServletWithPostData.
@Test
public void testErrorServletWithPostData() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/servletContext/error");
post.setEntity(new StringEntity("Post body stuff"));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("500", response);
post = new HttpPost(DefaultServer.getDefaultServerURL() + "/servletContext/error");
post.setEntity(new StringEntity("Post body stuff"));
result = client.execute(post);
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("500", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleAsyncTestCase method testSimpleHttpServlet.
@Test
public void testSimpleHttpServlet() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final 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 ParameterCharacterEncodingTestCase method testFormDataCharacterEncoding.
@Test
public void testFormDataCharacterEncoding() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String message = "abcčšž";
String charset = "UTF-8";
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/servletContext");
final List<NameValuePair> values = new ArrayList<>();
values.add(new BasicNameValuePair("charset", charset));
values.add(new BasicNameValuePair("message", message));
UrlEncodedFormEntity data = new UrlEncodedFormEntity(values, "UTF-8");
post.setEntity(data);
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(message, response);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations