You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Murali Mohan Annapragada <mu...@digitalthink.com> on 2003/07/23 12:01:14 UTC

Help Please

Hello All,

I downloaded the "jakarta-cactus-13-1.5-beta1" to perform the servlet
testing. In my company, we have automated the EJB unit testing using JUnitEE
framework and after lot of searching we decided that Cactus is best for
automating servlet testing.  I am running into lot of problems to setup test
environment. I am writing down what exactly i am trying to do and it would
be great if you can provide me some help.

I have a web application which has servlets deployed on weblogic 6.1 SP5. I
want to test these servlets but not using any JunitRunner or any UI tool
instead i want to be able to run the test cases from the browser.

To explain the problem i will refer the webapplication that has servlets to
be tested as "app1".  I created another webapplication called "app2" and has
both the servlets and my test classes under web-inf/classes.  In the
web-inf/lib of app2 i placed all the jar files that are listed in the
documentation along with xalan for html generation. I added
'cactus.properties' under web-inf/classes which has
"cactus.contextURL=http://localhost:7001/app1" and
cactus.servletRedirectorName = ServletRedirector defined. In "app1" which is
my server, I also added my test classes under web-inf/classes and made
changes to web.xml to add entries for "ServletRedirector". I also added all
the libraries under web-inf/lib for server too. When i start my weblogic and
access the test classes in app2 like in this URL..
http://localhost:7001/app2/ServletTestRunner?suite=TestMasterCatalogServlet&
transform=yes I assumed that this will invoke the test classes in app2 and
will execute beginXXX() at this end and on "app1" side it will execute
"setUp(), textXXX(), tearDown()" in that order. But what happpens is it
executes beginXXX( ), doesn't print the statement in setUp() but executes
testXXx() and throws NullPointerException when either "session" or "request"
are accessed.  Based on above scenario i have following doubts..

1. Can i use 2 different contexts like app1, app2 in weblogic, one as server
and another as client? (They run on same instance of weblogic)
2. As a follow up question, is it must to run client on seperate JVM?
3. I placed "cactus.properties" file in web-inf/classes of the client
application, but it doesn't seem to be loading it when i printed the
"theRequest.getRedirectorName()" in beginXXx() it printed Null so i
explicitly did this "theRequest.setRedirectorName("ServletRedirector");".

I maybe totally on wrong track, i will be glad to provide any details..
Could you please help me?

The exception it prins is ::

java.lang.NullPointerException
at
com.digitalthink.ast.catalog.servlet.TestMasterCatalogSvlt.testAddCourse(Tes
tMasterCatalogSvlt.java:154)
at
org.apache.cactus.internal.server.ServerTestCaseDelegate.runServerTest(Serve
rTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:214)
at
org.apache.cactus.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.
java:156)
at
org.apache.cactus.server.AbstractWebTestController.dispatch133_handleRequest
(AbstractWebTestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:
130)
at
org.apache.cactus.server.AbstractWebTestController.around133_handleRequest(A
bstractWebTestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:11
58)
at
org.apache.cactus.server.AbstractWebTestController.handleRequest(AbstractWeb
TestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:101)
at
org.apache.cactus.server.ServletTestRedirector.dispatch160_doPost(ServletTes
tRedirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:125)
at
org.apache.cactus.server.ServletTestRedirector.around160_doPost(ServletTestR
edirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:1158)
at
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.
java;org/apache/cactus/util/log/LogAspect.aj[1k]:109)
at
org.apache.cactus.server.ServletTestRedirector.dispatch159_doGet(ServletTest
Redirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:96)
at
org.apache.cactus.server.ServletTestRedirector.around159_doGet(ServletTestRe
director.java;org/apache/cactus/util/log/LogAspect.aj[1k]:1158)
at
org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.j
ava;org/apache/cactus/util/log/LogAspect.aj[1k]:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:265)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:200)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
ntext.java:2546)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
:2260)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

Thanks & Regards
Murali

Re: Help Please

Posted by Rameshkumar P <ra...@india.adventnet.com>.
Hi,
When you use ServletTestRunner servlet to run your test, I dont think 
you will need the cactus.properties. I tested that. I think that 
ServletTestRunner will search for the test class in the context path in 
which it has been called and excecute. Example 
http://localhost:8080/app1/ServletTestRunner?suite=com.test.TestMyJava, 
then ServletTestRunner will search for class in the context path 
http://localhost:8080/app1 .
In the case ServletTestRunner, it is single JVM.
Regards,
Ramesh.

Murali Mohan Annapragada wrote:

>Hello All,
>
>I downloaded the "jakarta-cactus-13-1.5-beta1" to perform the servlet
>testing. In my company, we have automated the EJB unit testing using JUnitEE
>framework and after lot of searching we decided that Cactus is best for
>automating servlet testing.  I am running into lot of problems to setup test
>environment. I am writing down what exactly i am trying to do and it would
>be great if you can provide me some help.
>
>I have a web application which has servlets deployed on weblogic 6.1 SP5. I
>want to test these servlets but not using any JunitRunner or any UI tool
>instead i want to be able to run the test cases from the browser.
>
>To explain the problem i will refer the webapplication that has servlets to
>be tested as "app1".  I created another webapplication called "app2" and has
>both the servlets and my test classes under web-inf/classes.  In the
>web-inf/lib of app2 i placed all the jar files that are listed in the
>documentation along with xalan for html generation. I added
>'cactus.properties' under web-inf/classes which has
>"cactus.contextURL=http://localhost:7001/app1" and
>cactus.servletRedirectorName = ServletRedirector defined. In "app1" which is
>my server, I also added my test classes under web-inf/classes and made
>changes to web.xml to add entries for "ServletRedirector". I also added all
>the libraries under web-inf/lib for server too. When i start my weblogic and
>access the test classes in app2 like in this URL..
>http://localhost:7001/app2/ServletTestRunner?suite=TestMasterCatalogServlet&
>transform=yes I assumed that this will invoke the test classes in app2 and
>will execute beginXXX() at this end and on "app1" side it will execute
>"setUp(), textXXX(), tearDown()" in that order. But what happpens is it
>executes beginXXX( ), doesn't print the statement in setUp() but executes
>testXXx() and throws NullPointerException when either "session" or "request"
>are accessed.  Based on above scenario i have following doubts..
>
>1. Can i use 2 different contexts like app1, app2 in weblogic, one as server
>and another as client? (They run on same instance of weblogic)
>2. As a follow up question, is it must to run client on seperate JVM?
>3. I placed "cactus.properties" file in web-inf/classes of the client
>application, but it doesn't seem to be loading it when i printed the
>"theRequest.getRedirectorName()" in beginXXx() it printed Null so i
>explicitly did this "theRequest.setRedirectorName("ServletRedirector");".
>
>I maybe totally on wrong track, i will be glad to provide any details..
>Could you please help me?
>
>The exception it prins is ::
>
>java.lang.NullPointerException
>at
>com.digitalthink.ast.catalog.servlet.TestMasterCatalogSvlt.testAddCourse(Tes
>tMasterCatalogSvlt.java:154)
>at
>org.apache.cactus.internal.server.ServerTestCaseDelegate.runServerTest(Serve
>rTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:214)
>at
>org.apache.cactus.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.
>java:156)
>at
>org.apache.cactus.server.AbstractWebTestController.dispatch133_handleRequest
>(AbstractWebTestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:
>130)
>at
>org.apache.cactus.server.AbstractWebTestController.around133_handleRequest(A
>bstractWebTestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:11
>58)
>at
>org.apache.cactus.server.AbstractWebTestController.handleRequest(AbstractWeb
>TestController.java;org/apache/cactus/util/log/LogAspect.aj[1k]:101)
>at
>org.apache.cactus.server.ServletTestRedirector.dispatch160_doPost(ServletTes
>tRedirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:125)
>at
>org.apache.cactus.server.ServletTestRedirector.around160_doPost(ServletTestR
>edirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:1158)
>at
>org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.
>java;org/apache/cactus/util/log/LogAspect.aj[1k]:109)
>at
>org.apache.cactus.server.ServletTestRedirector.dispatch159_doGet(ServletTest
>Redirector.java;org/apache/cactus/util/log/LogAspect.aj[1k]:96)
>at
>org.apache.cactus.server.ServletTestRedirector.around159_doGet(ServletTestRe
>director.java;org/apache/cactus/util/log/LogAspect.aj[1k]:1158)
>at
>org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.j
>ava;org/apache/cactus/util/log/LogAspect.aj[1k]:92)
>at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>at
>weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
>:265)
>at
>weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
>:200)
>at
>weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
>ntext.java:2546)
>at
>weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
>:2260)
>at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
>at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
>Thanks & Regards
>Murali
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>  
>


RE: Help Please

Posted by Vincent Massol <vm...@pivolis.com>.
Hi Murali,

> -----Original Message-----
> From: Murali Mohan Annapragada [mailto:muralia@digitalthink.com]
> Sent: 23 July 2003 12:01
> To: 'Cactus Users List'
> Subject: Help Please
> Importance: High
> 
> Hello All,
> 
> I downloaded the "jakarta-cactus-13-1.5-beta1" to perform the servlet
> testing. In my company, we have automated the EJB unit testing using
> JUnitEE
> framework and after lot of searching we decided that Cactus is best
for
> automating servlet testing.  

FYI, Cactus also offers the same feature as JUnitEE to unit test EJBs
(AFAIK).

> I am running into lot of problems to setup
> test
> environment. I am writing down what exactly i am trying to do and it
would
> be great if you can provide me some help.
> 
> I have a web application which has servlets deployed on weblogic 6.1
SP5.
> I
> want to test these servlets but not using any JunitRunner or any UI
tool
> instead i want to be able to run the test cases from the browser.

ok

> 
> To explain the problem i will refer the webapplication that has
servlets
> to
> be tested as "app1".  I created another webapplication called "app2"
and
> has
> both the servlets and my test classes under web-inf/classes.  

No, that's not possible. The Servlet specifications prevents this! You
can't call app1 from app2 (and you'll have classloader issues).

> In the
> web-inf/lib of app2 i placed all the jar files that are listed in the
> documentation along with xalan for html generation. I added
> 'cactus.properties' under web-inf/classes which has
> "cactus.contextURL=http://localhost:7001/app1" and
> cactus.servletRedirectorName = ServletRedirector defined. 

The cactus.properties is not needed when running from a browser as
Cactus is able to infer the contextURL, and "ServletRedirector" is the
default used.

> In "app1" which
> is
> my server, I also added my test classes under web-inf/classes and made
> changes to web.xml to add entries for "ServletRedirector". I also
added
> all
> the libraries under web-inf/lib for server too. When i start my
weblogic
> and
> access the test classes in app2 like in this URL..
>
http://localhost:7001/app2/ServletTestRunner?suite=TestMasterCatalogServ
le
> t&
> transform=yes I assumed that this will invoke the test classes in app2
and
> will execute beginXXX() at this end and on "app1" side it will execute
> "setUp(), textXXX(), tearDown()" in that order. But what happpens is
it
> executes beginXXX( ), doesn't print the statement in setUp() but
executes
> testXXx() and throws NullPointerException when either "session" or
> "request"
> are accessed.  Based on above scenario i have following doubts..
> 
> 1. Can i use 2 different contexts like app1, app2 in weblogic, one as
> server
> and another as client? (They run on same instance of weblogic)

no

> 2. As a follow up question, is it must to run client on seperate JVM?

yes

> 3. I placed "cactus.properties" file in web-inf/classes of the client
> application, but it doesn't seem to be loading it when i printed the
> "theRequest.getRedirectorName()" in beginXXx() it printed Null so i
> explicitly did this
"theRequest.setRedirectorName("ServletRedirector");".

You don't need to do all that.

[snip]

Try using only one webapp as described here
(http://jakarta.apache.org/cactus/integration/howto_classpath.html) and
we'll go from there.

Thanks
-Vincent