use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ChangeSessionIdTestCase method testChangeSessionId.
@Test
public void testChangeSessionId() 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());
String response = HttpClientUtils.readResponse(result);
String oldId = testResponse(response, null);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
oldId = testResponse(response, oldId);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
oldId = testResponse(response, oldId);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class CrossContextServletSessionTestCase method testCrossContextSessionIncludeInvocation.
@Test
public void testCrossContextSessionIncludeInvocation() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet direct1 = new HttpGet(DefaultServer.getDefaultServerURL() + "/1/servlet");
HttpGet include1 = new HttpGet(DefaultServer.getDefaultServerURL() + "/1/include?context=/2&path=/servlet");
HttpGet direct2 = new HttpGet(DefaultServer.getDefaultServerURL() + "/2/servlet");
HttpGet include2 = new HttpGet(DefaultServer.getDefaultServerURL() + "/2/include?context=/1&path=/servlet");
HttpResponse result = client.execute(include2);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("1", response);
result = client.execute(direct1);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("2", response);
result = client.execute(include2);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("3", response);
result = client.execute(include2);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("4", response);
result = client.execute(include1);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("1", response);
result = client.execute(include1);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("2", response);
result = client.execute(direct2);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("3", response);
result = client.execute(direct2);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("4", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletSessionCrawlerTestCase method testCrawlerSessionUsage.
@Test
public void testCrawlerSessionUsage() throws IOException, InterruptedException {
final PathHandler pathHandler = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setCrawlerSessionManagerConfig(new CrawlerSessionManagerConfig()).setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addListener(new ListenerInfo(SessionCookieConfigListener.class)).addServlets(new ServletInfo("servlet", SessionServlet.class).addMapping("/aa/b"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
try {
pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
DefaultServer.setRootHandler(pathHandler);
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new CookieStore() {
@Override
public void addCookie(Cookie cookie) {
}
@Override
public List<Cookie> getCookies() {
return Collections.EMPTY_LIST;
}
@Override
public boolean clearExpired(Date date) {
return false;
}
@Override
public void clear() {
}
});
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b");
get.addHeader(Headers.USER_AGENT_STRING, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("1", response);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("2", response);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("3", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletSessionTestCase method testSimpleSessionUsage.
@Test
public void testSimpleSessionUsage() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("1", response);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("2", response);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("3", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletInputStreamConnectionTerminationTestCase method testConnectionTermination.
@Test
public void testConnectionTermination() throws IOException {
StringBuilder builder = new StringBuilder(1000 * HELLO_WORLD.length());
for (int j = 0; j < 1000; ++j) {
builder.append(HELLO_WORLD);
}
String message = builder.toString();
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/term";
HttpPost post = new HttpPost(uri);
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.fail();
} catch (IOException expected) {
//expected
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations