this is expected behaviour. The problem is that the config object is *not* initialized with the init-params of the servlet you're trying to test, but rather with the init-params of the ServletRedirector.
I would recommend setting up the init-params in the test case, which also makes the test code better readable because you're not relying on values set in web.xml. For that, the Cactus ServletConfigWrapper offers methods to add initialization parameters.
Matt Raible wrote:
I am trying to use Cactus to verify that a servlet's init-params from
web.xml has been loaded correctly. I have setUp and my testInit
seemingly coded correctly. When this servlet loads at the start of the
application, the parameters load fine (they're printed out by log4j),
however, when it's called from the test case, all values are null, and
test fails, since my servlet checks for null.
protected void setUp() throws Exception {
// JUnitDoclet begin method testcase.setUp
super.setUp();
servlet = new LoginServlet();
servlet.init(config);
// JUnitDoclet end method testcase.setUp
}
public void testInit() throws Exception {
// Call method to test
servlet.init();
// check all parameters from web.xml
String authURL = config.getInitParameter("authURL");
assertTrue(authURL != null &&
authURL.equals("j_security_check"));
assertEquals((String) servlet.getServletContext()
.getAttribute(Constants.HTTP_PORT), "8080");
assertEquals((String) servlet.getServletContext()
.getAttribute(Constants.HTTPS_PORT), "8443");
assertEquals((Boolean) servlet.getServletContext()
.getAttribute("secureLogin"), Boolean.FALSE);
assertEquals((String) servlet.getServletContext()
.getAttribute(Constants.ENC_ALGORITHM), "SHA");
}
When tomcat starts:
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(129) | authURL: j_security_check
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(130) | Use SSL for login? false
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(131) | Programmatic encryption of pa
ssword? false
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(132) | Encryption algorithm: SHA
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(147) | HTTP Port: 8080
[java] DEBUG [main] [org.apache.webapp.actions.LoginServlet]
LoginServlet.init(148) | HTTPS Port: 8443
When called by junit task in ant:
[java] DEBUG [HttpProcessor[8080][0]]
[org.apache.webapp.actions.LoginServlet] LoginServlet.init(129) |
authURL: null
[java] DEBUG [HttpProcessor[8080][0]]
[org.apache.webapp.actions.LoginServlet] LoginServlet.init(130) | Use
SSL for login? false
[java] DEBUG [HttpProcessor[8080][0]]
[org.apache.webapp.actions.LoginServlet] LoginServlet.init(131) |
Programmatic encryption of password? False
.
[junit] INFO [main] [httpclient.wire] Log4JCategoryLog.info(88) | <<
"<webresult><exception classname="javax.servlet
.ServletException"><message><![CDATA[No 'authURL' Context Parameter
supplied in web.xml]]></message><stacktrace><![CDATA
[javax.servlet.ServletException: No 'authURL' Context Parameter supplied
in web.xml
Any ideas are appreciated. It's late and hopefully I'm just overlooking
something.
Thanks,
Matt
-- Christopher Lenz /=/ cmlenz at gmx.de
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
