jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tarek M. Nabil" <Tarek.Na...@itworx.com>
Subject RE: invoking a private method of a servlet
Date Mon, 17 Nov 2003 11:42:37 GMT
Hi Ajay,

I'm not an expert on Unit Testing, but I've been doing so much reading about it lately. This
is, really, the first time I've seen this technique used. I would think this is too much work
and I really doubt if this is the idea behind testing. I think your problem would be better
solved by using mock objects.

Thanks,
Tarek Nabil

-----Original Message-----
From: Ajay Kumar [mailto:ajaykumar1712@hotmail.com]
Sent: Monday, November 17, 2003 1:35 PM
To: cactus-user@jakarta.apache.org
Subject: invoking a private method of a servlet


Hi All,

I have a controller servlet with many private methods and want to write a 
testcase for these methods. I tried using reflection for invoking these 
methods, but got the following report:

<testsuites>
-
<testsuite name="TestMainServlet" tests="2" failures="0" errors="1" 
time="1.254">
<testcase name="testServletContext" time="0.734"/>
-
<testcase name="testGetEmailTemplates" time="0.119">
-
<error message="null" 
type="org.apache.cactus.client.ServletExceptionWrapper">
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at TestMainServlet.testGetEmailTemplates(TestMainServlet.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at 
org.apache.cactus.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:156)
	at 
org.apache.cactus.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:130)
	at 
org.apache.cactus.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:158)
	at 
org.apache.cactus.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
	at 
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:138)
	at 
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:158)
	at 
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
	at 
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:109)
	at 
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:158)
	at 
org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at 
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at 
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
	at 
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
	at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
	at org.a
pache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
	at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
	at java.lang.Thread.run(Thread.java:536)
Caused by: java.lang.NullPointerException
	at 
com.appnetix.mainprospecting.control.MainServlet.getEmailTemplates(MainServlet.java:226)
	... 54 more
</error>
</testcase>
</testsuite>
</testsuites

Is there any approach to solve this problem?

Thanks,
Ajay.

_________________________________________________________________
Enjoy shopping online? Get this e credit card. 
http://server1.msn.co.in/features/amex/ It cuts cost & adds value!


---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org


Mime
View raw message