use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestParameters method testParameterContents.
/**
* Test the parameter contents.
*
* @throws IOException
* @throws ServletException
* @throws NamespaceException
*/
public void testParameterContents() throws IOException, ServletException, NamespaceException {
HttpService httpService = getHTTPService(registry.getBundleContext());
BasicTestingServlet testServlet = new BasicTestingServlet();
httpService.registerServlet("/test", testServlet, null, null);
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
int parameterCount = 16;
for (int i = 0; i < parameterCount; ++i) {
client.addRequestProperty("k" + i, "v" + i);
}
client.connect();
assertTrue(client.getResponseCode() == 200);
Map rp = new HashMap();
Enumeration e = testServlet.getHeaderNames();
while (e.hasMoreElements()) {
String key = e.nextElement().toString();
rp.put(key, testServlet.getHeader(key));
}
for (int i = 0; i < parameterCount; ++i) {
assertTrue(rp.get("k" + i).equals("v" + i));
}
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testExecutePOST.
/**
* Test can execute POST method.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testExecutePOST() 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", "POST");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertFalse(testServlet.isGetCalled());
assertFalse(testServlet.isDeleteCalled());
assertTrue(testServlet.isPostCalled());
assertFalse(testServlet.isPutCalled());
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testExecuteGET.
/**
* Test calling GET enters TestServlet doGet() method.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testExecuteGET() 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", "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertTrue(testServlet.isGetCalled());
assertFalse(testServlet.isDeleteCalled());
assertFalse(testServlet.isPostCalled());
assertFalse(testServlet.isPutCalled());
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestServletContainer method testExecuteDELETE.
/**
* Test can execute DELETE method.
*
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testExecuteDELETE() 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", "DELETE");
client.connect();
assertTrue(client.getResponseCode() == 200);
assertFalse(testServlet.isGetCalled());
assertTrue(testServlet.isDeleteCalled());
assertFalse(testServlet.isPostCalled());
assertFalse(testServlet.isPutCalled());
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestQueryString method testQueryString.
// TODO: test unicode keys and values
// TODO: test invalid query string in request
/**
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testQueryString() throws ServletException, NamespaceException, IOException {
HttpService httpService = getHTTPService(registry.getBundleContext());
BasicTestingServlet testServlet = new BasicTestingServlet();
httpService.registerServlet("/test", testServlet, null, null);
StringBuffer qs = new StringBuffer("?");
int parameterCount = 16;
for (int i = 0; i < parameterCount; ++i) {
qs.append("k" + i);
qs.append("=");
qs.append("v" + i);
if (i != (parameterCount - 1)) {
qs.append('&');
}
}
HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test" + qs.toString(), "GET");
client.connect();
assertTrue(client.getResponseCode() == 200);
Map qsm = testServlet.getQueryStringMap();
assertTrue(qsm.size() == parameterCount);
for (int i = 0; i < parameterCount; ++i) {
assertTrue(qsm.containsKey("k" + i));
assertTrue(qsm.get("k" + i).equals("v" + i));
}
}
Aggregations