use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestOSGiService method testCanRegisterServlet.
/**
* Can register a servlet with the HTTPService
*
* @throws ServletException
* @throws NamespaceException
*/
public void testCanRegisterServlet() throws ServletException, NamespaceException {
HttpService httpService = getHTTPService(registry.getBundleContext());
httpService.registerServlet("/", new BasicTestingServlet(), null, null);
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestOSGiService method testCannotRegisterInvalidAlias.
/**
* Test invalid aliases throw NamespaceException.
*
* @throws ServletException
* @throws NamespaceException
*/
public void testCannotRegisterInvalidAlias() throws ServletException, NamespaceException {
HttpService httpService = getHTTPService(registry.getBundleContext());
String[] badAliases = { "noslash" };
for (int i = 0; i < badAliases.length; ++i) {
boolean namespaceExceptionThrown = false;
try {
httpService.registerServlet(badAliases[i], new BasicTestingServlet(), null, null);
} catch (NamespaceException e) {
namespaceExceptionThrown = true;
}
}
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestOSGiService method testCanReregisterAlias.
/**
* Test that an alias can be registered after it's been previously registered and then unregistered.
*
* @throws ServletException
* @throws NamespaceException
*/
public void testCanReregisterAlias() throws ServletException, NamespaceException {
HttpService httpService = getHTTPService(registry.getBundleContext());
httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
httpService.unregister("/alias");
httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestOSGiService method testCannotRegisterSameAliasTwice.
/**
* Test that HTTP Service does not allow same alias to be registered twice.
*
* @throws ServletException
* @throws NamespaceException
*/
public void testCannotRegisterSameAliasTwice() throws ServletException, NamespaceException {
HttpService httpService = getHTTPService(registry.getBundleContext());
boolean namespaceExceptionThrown = false;
httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
try {
httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
} catch (NamespaceException e) {
namespaceExceptionThrown = true;
}
assertTrue(namespaceExceptionThrown);
}
use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.
the class TestParameters method testCorrectParameterCount.
// TODO: test unicode parameters
// TODO: test parameters with empty values
// TODO: test parameter name collision
/**
* @throws ServletException
* @throws NamespaceException
* @throws IOException
*/
public void testCorrectParameterCount() 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");
int parameterCount = 16;
for (int i = 0; i < parameterCount; ++i) {
client.addRequestProperty("k" + i, "v" + i);
}
client.connect();
assertTrue(client.getResponseCode() == 200);
int headerCount = 0;
Enumeration e = testServlet.getHeaderNames();
while (e.hasMoreElements()) {
headerCount++;
System.out.println("header: " + e.nextElement().toString());
}
assertTrue(headerCount >= parameterCount);
}
Aggregations