use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class GetCookiesTestCase method testGetCookiesWithOnlyValidCookie.
@Test
public void testGetCookiesWithOnlyValidCookie() throws Exception {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aaa");
get.setHeader(Headers.COOKIE_STRING, "testcookie=works");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("Only one valid cookie", "name='testcookie'value='works'", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ParameterEchoTestCase method testPostBoth.
@Test
public void testPostBoth() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/servletContext/aaa?param1=1¶m2=2");
final List<NameValuePair> values = new ArrayList<>();
values.add(new BasicNameValuePair("param3", "3"));
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 GetResourceTestCase method testGetResource.
@Test
public void testGetResource() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/file?file=/file.txt");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("File Contents", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SslUpgradeTestCase method runTest.
public void runTest(final String url) throws IOException {
TestHttpClient client = new TestHttpClient();
try {
final Socket socket = DefaultServer.getClientSSLContext().getSocketFactory().createSocket(new Socket(DefaultServer.getHostAddress("default"), DefaultServer.getHostSSLPort("default")), DefaultServer.getHostAddress("default"), DefaultServer.getHostSSLPort("default"), true);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
out.write(("GET " + url + " HTTP/1.1\r\nHost: default\r\nConnection: upgrade\r\nUpgrade:servlet\r\n\r\n").getBytes());
out.flush();
String bytes = readBytes(in);
Assert.assertTrue(bytes, bytes.startsWith("HTTP/1.1 101 Switching Protocols\r\n"));
out.write("Echo Messages\r\n\r\n".getBytes());
out.flush();
Assert.assertEquals("Echo Messages\r\n\r\n", readBytes(in));
out.write("Echo Messages2\r\n\r\n".getBytes());
out.flush();
Assert.assertEquals("Echo Messages2\r\n\r\n", readBytes(in));
out.write("exit\r\n\r\n".getBytes());
out.flush();
socket.close();
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class AbstractResponseWrapperTestCase method testStandardWrapper.
@Test
public void testStandardWrapper() throws IOException, ServletException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/standard");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(StandardRequestWrapper.class.getName() + "\n" + StandardResponseWrapper.class.getName(), response);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations