Tests that exercise the Cactus Servlet Config wrapper.
| Method from org.apache.cactus.sample.servlet.unit.TestServletConfig Detail: |
public void testGetLogs() {
String message = "some test log";
ServletContext context = config.getServletContext();
context.log(message);
Vector logs = ((ServletContextWrapper) context).getLogs();
assertEquals("Found more than one log message", logs.size(), 1);
assertTrue("Cannot find expected log message : [" + message + "]",
logs.contains("some test log"));
}
Verify that calls to ServletContext.log() methods can
be retrieved and asserted. |
public void testGetServletNameNoOverride() {
assertEquals(config.getOriginalConfig().getServletName(),
config.getServletName());
}
Verify that if we don't override the servlet name we get the original
name (i.e. Cactus is effectively transparent). |
public void testGetServletNameOverriden() {
config.setServletName("MyServlet");
assertEquals("MyServlet", config.getServletName());
assertTrue(!config.getOriginalConfig().getServletName().equals(
config.getServletName()));
}
Verify that we can override the
ServletConfig.getServletName() method. |
public void testSetConfigParameter() {
config.setInitParameter("testparam", "test value");
assertEquals("test value", config.getInitParameter("testparam"));
boolean found = false;
Enumeration en = config.getInitParameterNames();
while (en.hasMoreElements())
{
String name = (String) en.nextElement();
if (name.equals("testparam"))
{
found = true;
break;
}
}
assertTrue("[testparam] not found in parameter names", found);
}
Verify that we can add parameters to the config list of parameters
programatically, without having to define them in web.xml. |
public void testSetConfigParameterOverrideWebXmlParameter() {
// Note: "param1" is a parameter that must be defined on the Servlet
// redirector, with a value different than "testoverrideparam1".
assertTrue(
config.getOriginalConfig().getInitParameter("param1") != null);
assertTrue(
!config.getOriginalConfig().getInitParameter("param1").equals(
"testoverrideparam1"));
config.setInitParameter("param1", "testoverrideparam1");
Enumeration en = config.getInitParameterNames();
int count = 0;
while (en.hasMoreElements())
{
String name = (String) en.nextElement();
if (name.equals("param1"))
{
assertEquals("testoverrideparam1",
config.getInitParameter(name));
count++;
}
}
assertTrue("[param1] was found " + count + " times. Should have "
+ "been found once.", count == 1);
}
Verify that calling setInitParameter() with a parameter
already defined in web.xml will override it. |