Problems in Starting up with ServletUnit
Narinder Kumar <[email protected]> Thu, 13 Jan 2011 15:49:08 +0530
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============8811996682808367973==
Content-Type: multipart/alternative; boundary=0016e64761daedb85c0499b7a5c0
--0016e64761daedb85c0499b7a5c0
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I was planning to unit test my Servlet through ServletUnit and ran across
some problems :
- As a starting point, we are supposed to create a ServletRunner object.
One of the constructors expects File object with web.xml file. I provide the
full path of my web.xml file but somehow it ignores the path provided and
searches at the top level folder. The code-snippet and error message is
below:
<code>
ServletRunner sr = new ServletRunner(new File("*
C:/eclipse-workspaces/pocs/lms-csd/src/main/webapp/WEB-INF/web.xml*"));
ServletUnitClient sc = sr.newClient();
WebRequest request = new PostMethodWebRequest("http://localhost/login"
);
request.setParameter( "userId", "test" );
request.setParameter( "password", "csd" );
WebResponse response = sc.getResponse(request);
String text = response.getText();
Assert.assertTrue(text.contains("Welcome to Leave Management System"));
</code>
com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request:
500 org.apache.jasper.JasperException: java.io.FileNotFoundException: *
C:\eclipse-workspaces\pocs\lms-csd\WEB-INF\web.xml* (The system cannot find
the path specified) [http://localhost/login]
- Why does the system keep on looking at the folder structure to be
.../WEB-INF/web.xml. Mine is a maven project and I would not like to change
the structure of the project to adapt this way. How can I make ServletRunner
class to read from a specified folder ?
- In the Servlet code, I use the following code :
String result = null
if (someCondition)
result = "/welcome.jsp";
} else {
logger.warn("Password Validation failed");
request.setAttribute("failedlogin", new Boolean(true));
result = "/index.jsp";
}
}
RequestDispatcher requestDispatcher =
getServletContext().getRequestDispatcher(result);
requestDispatcher.forward(request, response);
Again ServletUnit expects welcome.jsp to be at root foler, though jsp files
are present at .../src/main/webapp/ folder. Again how can ServletUnit be
told about the target folder location ?
Many thanks in advance.
Best Regards
Narinder
--0016e64761daedb85c0499b7a5c0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,<div><br></div><div>I was planning to unit test my Servlet through Servl=
etUnit and ran across some problems :</div><div><br></div><div><ul><li>As a=
starting point, we are supposed to create a ServletRunner object. One of t=
he constructors expects File object with web.xml file. I provide the full p=
ath of my web.xml file but somehow it ignores the path provided and searche=
s at the top level folder. The code-snippet and error message is below:</li=
>
</ul><code></div><div><div><span class=3D"Apple-tab-span" style=3D"wh=
ite-space:pre"> </span>=A0=A0 =A0ServletRunner sr =3D new ServletRunner(new=
File("<b>C:/eclipse-workspaces/pocs/lms-csd/src/main/webapp/WEB-INF/w=
eb.xml</b>"));</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =
=A0ServletUnitClient sc =3D sr.newClient();</div><div><br></div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =A0WebReque=
st request =A0 =3D new PostMethodWebRequest("<a href=3D"http://localho=
st/login">http://localhost/login</a>" );</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =
=A0request.setParameter( "userId", "test" );</div><div>=
<span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =A0re=
quest.setParameter( "password", "csd" );</div>
<div><br></div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre=
"> </span> =A0 =A0WebResponse response =3D sc.getResponse(request);</div><d=
iv><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =
=A0</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </s=
pan> =A0 =A0String text =3D response.getText();</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =A0 =
=A0Assert.assertTrue(text.contains("Welcome to Leave Management System=
"));</div></div><div></code><br>com.meterware.httpunit.HttpInter=
nalErrorException: Error on HTTP request: 500 org.apache.jasper.JasperExcep=
tion: java.io.FileNotFoundException: <b>C:\eclipse-workspaces\pocs\lms-csd\=
WEB-INF\web.xml</b> (The system cannot find the path specified) [<a href=3D=
"http://localhost/login">http://localhost/login</a>]<br>
<ul>
</ul><div><ul><li>Why does the system keep on looking at the folder structu=
re to be .../WEB-INF/web.xml. Mine is a maven project and I would not like =
to change the structure of the project to adapt this way. How can I make Se=
rvletRunner class to read from a specified folder ?</li>
</ul><ul><li>In the Servlet code, I use the following code :</li></ul>=A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 String result =3D null</div><di=
v>=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (someCondition)<br><=
div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>res=
ult =3D "/welcome.jsp";</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>} e=
lse {</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span>logger.warn("Password Validation failed");</div><div><sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>request.se=
tAttribute("failedlogin", new Boolean(true));</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>re=
sult =3D "/index.jsp";</div><div><span class=3D"Apple-tab-span" s=
tyle=3D"white-space:pre"> </span>}</div><div><span class=3D"Apple-tab-spa=
n" style=3D"white-space:pre"> </span>}</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>Requ=
estDispatcher requestDispatcher =3D getServletContext().getRequestDispatche=
r(result);</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e"> </span>requestDispatcher.forward(request, response);</div>
<div><br></div></div></div><blockquote class=3D"webkit-indent-blockquote" s=
tyle=3D"margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div>Aga=
in ServletUnit expects welcome.jsp to be at root foler, though jsp files ar=
e present at .../src/main/webapp/ folder. Again how can ServletUnit be told=
about the target folder location ?</div>
</div></div><div><br></div></blockquote><div><div>Many thanks in advance.
</div></div><div><br></div><div>Best Regards</div><div>Narinder</div>
--0016e64761daedb85c0499b7a5c0--
--===============8811996682808367973==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
--===============8811996682808367973==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
--===============8811996682808367973==--