Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / September 2005

Tip: Looking for answers? Try searching our database.

fun with NetBeans & StrutsTestCase

Thread view: 
Phlip - 14 Sep 2005 17:24 GMT
Newsgroupies:

I have this boss who thinks we have to write lots of unit tests,
instead of getting anything done.

Under the NetBeans editor, and its bundled TomCat, he wants us to use
StrutsTestCase, from here:

   http://strutstestcase.sourceforge.net/

That mocks the servlet layer and the GUI layer within, permitting test
cases like this:

   public void testSuccessfulLogin() {

       addRequestParameter("username","deryl");
       addRequestParameter("password","radar");
       setRequestPathInfo("/login");

       actionPerform();  //  <--  trouble

       verifyForward("success");
       ...

My boss seems to think that running these tests over and over again
will somehow "propell development", and be more efficient than manually
logging into our site and messing with it over and over again.
Whatever.

However, that test fails with this spew:

compile-test:
Sep 14, 2005 8:53:13 AM org.apache.struts.action.ActionServlet
initServlet
SEVERE: The /WEB-INF/web.xml was not found.

The sub-spew says:

Sep 14, 2005 8:53:13 AM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected
exception or error thrown, so marking the servlet as unavailable.  Most
likely, this is due to an incorrect or missing library dependency.
javax.servlet.ServletException: The /WEB-INF/web.xml was not found.
       at
org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1138)
       at
org.apache.struts.action.ActionServlet.init(ActionServlet.java:328)
       at javax.servlet.GenericServlet.init(GenericServlet.java:211)
       at
servletunit.struts.MockStrutsTestCase.getActionServlet(MockStrutsTestCase.java:326)
       at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394)
       at TestLoginAction.testSuccessfulLogin(TestLoginAction.java:37)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Everyone else can find the magic /WEB-INF/web.xml file.

Note that the path starts with /. (Temporarily) putting that folder in
the root makes us stop running at actionPerform() instead of just
crash.

The documentation just says to add various permutations of...

   setConfigFile("/WEB-INF/struts-config.xml");

...to the test case. None of the permutations work, and the error
message continues to speak of web.xml, not struts*.xml.

Has anyone here got this stuff working in the NetBeans editor?

Signature

 Phlip
 http://www.greencheese.org/ZeekLand  <-- NOT a blog!!!

Phlip - 14 Sep 2005 19:56 GMT
> Newsgroupies:

>     http://strutstestcase.sourceforge.net/

>     public void testSuccessfulLogin() {
>
[quoted text clipped - 5 lines]
>
>         verifyForward("success");

> SEVERE: The /WEB-INF/web.xml was not found.

This thread seems to cover that:

http://www.testdriven.com/modules/newbb/viewtopic.php?topic_id=1683&forum=6&PHPS
ESSID=15bdc965449e56e1840e18d5a0157c73


Sorry about the long URL (not my site!). I'l summarize:

George D: The /WEB-INF/web.xml was not found.

JBRainsberger: Create the ServletRunner, passing in the fully-qualified
pathname of
web.xml (which you can extract to a JVM property or something). That
should help.

New question: The ServletRunner from what JAR? Google only references a
'com.netscape' JAR, and I don't want to add someone else's servlet
system to this Tomcat mix.

George D: File webXml = new
File("/home/george/workspace/MyProj/WebRoot/WEB-INF/web.xml");
assertTrue(webXml.canRead());
ServletRunner sr = new ServletRunner(webXml,"");

It seems that our previous use of a relative path wasn't the problem,
it
was the lack of context for Struts.

We're still having difficulty. We register the ActionServlet ok:

sr.registerServlet("RequestInfo", ActionServlet.class.getName());

But what name do we use for the servlet that the JSP compiles to? And
should it be registered as JspServlet.class.getName()?

New question: Where is he calling those lines, and to what does he pass
the sr?

George D: Yay! We got a green bar. It turns out we don't need to
register the
JspServlet, but we *do* need to include the commons-el.jar on the
classpath. <sigh>

This leaves me searching for commons-el.jar.

Yes, I'm gonna get JBR's book, but does anyone have a code drop with
all this stuff in it?

Signature

 Phlip

etienno@gmail.com - 29 Sep 2005 19:00 GMT
Hi,

I have the same problem. MockStrutsTestCase doesn't seems to see the
Web.xml even if you set it in the setServletConfigFile method.

It try:

setServletConfigFile("webApplication/WEB-INF/web.xml");

And it never work.

This is the error I got putting most on the log on DEBUG:

2005-09-29 13:59:42,316 DEBUG [main] (MockStrutsTestCase.java:113) -
Entering
0 [main] DEBUG struts.MockStrutsTestCase  - Entering
172 [main] DEBUG struts.MockStrutsTestCase  - Exiting
172 [main] DEBUG struts.MockStrutsTestCase  - Entering - key =
validating, value = false
172 [main] DEBUG struts.MockStrutsTestCase  - Exiting
2005-09-29 13:59:42,488 DEBUG [main] (MockStrutsTestCase.java:122) -
Exiting
2005-09-29 13:59:42,488 DEBUG [main] (MockStrutsTestCase.java:407) -
Entering - key = validating, value = false
2005-09-29 13:59:42,488 DEBUG [main] (MockStrutsTestCase.java:412) -
Exiting
2005-09-29 13:59:42,488 DEBUG [main] (MockStrutsTestCase.java:439) -
Entering - pathName = webApplication/WEB-INF/struts-config.xml
2005-09-29 13:59:42,503 DEBUG [main] (MockStrutsTestCase.java:457) -
Entering - moduleName = null, pathname
=webApplication/WEB-INF/struts-config.xml
2005-09-29 13:59:42,503 DEBUG [main] (MockStrutsTestCase.java:465) -
Exiting
2005-09-29 13:59:42,503 DEBUG [main] (MockStrutsTestCase.java:443) -
Exiting
172 [main] DEBUG struts.MockStrutsTestCase  - Entering - pathName =
webApplication/WEB-INF/struts-config.xml
187 [main] DEBUG struts.MockStrutsTestCase  - Entering - moduleName =
null, pathname =webApplication/WEB-INF/struts-config.xml
187 [main] DEBUG struts.MockStrutsTestCase  - Exiting
2005-09-29 13:59:42,503 DEBUG [main] (MockStrutsTestCase.java:479) -
Entering - pathname = webApplication/WEB-INF/web.xml
187 [main] DEBUG struts.MockStrutsTestCase  - Exiting
187 [main] DEBUG struts.MockStrutsTestCase  - Entering - pathname =
webApplication/WEB-INF/web.xml
1141 [main] DEBUG struts.MockStrutsTestCase  - Exiting
2005-09-29 13:59:43,457 DEBUG [main] (MockStrutsTestCase.java:528) -
Exiting
2005-09-29 13:59:43,457 DEBUG [main] (SearchLuceneActionTest.java:45) -
TEST inside the test class
2005-09-29 13:59:43,457 DEBUG [main] (MockStrutsTestCase.java:320) -
Entering - parameterName = keyword, parameterValue = test
2005-09-29 13:59:43,457 DEBUG [main] (MockStrutsTestCase.java:324) -
Exiting
2005-09-29 13:59:43,457 DEBUG [main] (MockStrutsTestCase.java:353) -
Entering - pathInfo = /searchLucene
1141 [main] DEBUG control.SearchLuceneActionTest  - TEST inside the
test class
1141 [main] DEBUG struts.MockStrutsTestCase  - Entering - parameterName
= keyword, parameterValue = test
1141 [main] DEBUG struts.MockStrutsTestCase  - Exiting
1141 [main] DEBUG struts.MockStrutsTestCase  - Entering - pathInfo =
/searchLucene
1141 [main] DEBUG struts.MockStrutsTestCase  - Entering - moduleName =
, pathInfo = /searchLucene
2005-09-29 13:59:43,457 DEBUG [main] (MockStrutsTestCase.java:376) -
Entering - moduleName = , pathInfo = /searchLucene
1172 [main] DEBUG struts.Common  - Entering - path = /searchLucene
2005-09-29 13:59:43,488 DEBUG [main] (Common.java:349) - Entering -
path = /searchLucene
1172 [main] DEBUG struts.Common  - Exiting - returning path =
/searchLucene
1172 [main] DEBUG struts.MockStrutsTestCase  - setting request
attribute - name = javax.servlet.include.servlet_path, value =
2005-09-29 13:59:43,488 DEBUG [main] (Common.java:358) - Exiting -
returning path = /searchLucene
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:387) -
setting request attribute - name = javax.servlet.include.servlet_path,
value =
1172 [main] DEBUG struts.MockStrutsTestCase  - Exiting
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:394) -
Exiting
1172 [main] DEBUG struts.MockStrutsTestCase  - Exiting
1172 [main] DEBUG struts.MockStrutsTestCase  - Entering
1172 [main] DEBUG struts.MockStrutsTestCase  - Entering
1172 [main] DEBUG struts.MockStrutsTestCase  - intializing
actionServlet
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:357) -
Exiting
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:282) -
Entering
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:219) -
Entering
2005-09-29 13:59:43,488 DEBUG [main] (MockStrutsTestCase.java:224) -
intializing actionServlet
1172 [main] INFO servletunit.ServletContextSimulator  - ActionServlet:
init
1922 [main] ERROR action.ActionServlet  - The /WEB-INF/web.xml was not
found.
2005-09-29 13:59:44,238 ERROR [main] (ActionServlet.java:1137) - The
/WEB-INF/web.xml was not found.
1938 [main] ERROR action.ActionServlet  - Unable to initialize Struts
ActionServlet due to an unexpected exception or error thrown, so
marking the servlet as unavailable.  Most likely, this is due to an
incorrect or missing library dependency.
javax.servlet.ServletException: The /WEB-INF/web.xml was not found.
    at
org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1138)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:328)
    at javax.servlet.GenericServlet.init(GenericServlet.java:258)
    at
servletunit.struts.MockStrutsTestCase.getActionServlet(MockStrutsTestCase.java:226)
    at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:290)

But if I place the webApplication folder in the claspath, when running
my test, it works!

But this is not the best way to do this I guess.

Etienne.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.