use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class AbstractResponseWrapperTestCase method testNoWrapper.
@Test
public void testNoWrapper() throws IOException, ServletException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(HttpServletRequestImpl.class.getName() + "\n" + HttpServletResponseImpl.class.getName(), response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SessionIdHandlingTestCase method testIsRequestedSessionIdValid.
@Test
public void testIsRequestedSessionIdValid() throws IOException, InterruptedException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=create");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("null", response);
String sessionId = getSession(client.getCookieStore().getCookies());
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=timeout");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(sessionId, response);
Thread.sleep(2500);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=isvalid");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("false", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SessionIdHandlingTestCase method testGetRequestedSessionId.
@Test
public void testGetRequestedSessionId() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=create");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("null", response);
String sessionId = getSession(client.getCookieStore().getCookies());
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=default");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(sessionId, response);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=change");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(sessionId, response);
String newSessionId = getSession(client.getCookieStore().getCookies());
Assert.assertNotEquals(sessionId, newSessionId);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=default");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(newSessionId, response);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=destroycreate");
result = client.execute(get);
final String createdSessionId = getSession(client.getCookieStore().getCookies());
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(newSessionId, response);
Assert.assertNotEquals(createdSessionId, newSessionId);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/session?action=destroy");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals(createdSessionId, response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ServletSessionInvalidateTestCase method testSimpleSessionUsage.
@Test
public void testSimpleSessionUsage() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/test");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class GetCookiesTestCase method testGetCookiesWithInvalidCookieName.
@Test
public void testGetCookiesWithInvalidCookieName() throws Exception {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aaa");
get.setHeader(Headers.COOKIE_STRING, "testcookie=works; ctx:123=456");
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();
}
}
Aggregations