use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestRequestPath method testMultipleSeperatorsRequestPath.
public void testMultipleSeperatorsRequestPath() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
BasicTestingServlet testServlet = new BasicTestingServlet();
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test/a/b//c", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertTrue(testServlet.getPathInfo().equals("/a/b/c"));
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestRequestPath method testSimpleRequestPath.
public void testSimpleRequestPath() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
BasicTestingServlet testServlet = new BasicTestingServlet();
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test/a/b/c", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertTrue(testServlet.getPathInfo().equals("/a/b/c"));
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testExecutePUT.
/**
* Test can execute PUT method.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testExecutePUT() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
BasicTestingServlet testServlet = new BasicTestingServlet();
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "PUT");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertFalse(testServlet.isGetCalled());
assertFalse(testServlet.isDeleteCalled());
assertFalse(testServlet.isPostCalled());
assertTrue(testServlet.isPutCalled());
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testGETResponseStringContent.
/**
* Test that container returns exact content as specified in servlet.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testGETResponseStringContent() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
String content = "test content";
BasicTestingServlet testServlet = new BasicTestingServlet(content, false);
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
String response = readInputAsString(client.getInputStream());
printBytes(content.getBytes());
printBytes(response.getBytes());
assertTrue(content.equals(response));
httpService.unregister("/test");
content = "test content";
testServlet = new BasicTestingServlet(content, true);
httpService.registerServlet("/test", testServlet, null, null);
client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
response = readInputAsString(client.getInputStream());
printBytes(content.getBytes());
printBytes(response.getBytes());
assertTrue(content.length() == response.length());
assertTrue(content.equals(response));
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testGETResponseBinaryContent.
/**
* Test that container returns exact content as specified in servlet.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testGETResponseBinaryContent() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
byte[] content = generateRandomBinaryContent();
BasicTestingServlet testServlet = new BasicTestingServlet(content, false);
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
byte[] response = readInputAsByteArray(client.getInputStream());
printBytes(content);
printBytes(response);
assertTrue(content.length == response.length);
for (int i = 0; i < content.length; ++i) {
assertTrue(content[i] == response[i]);
}
httpService.unregister("/test");
}
Aggregations