Re: Problems in Starting up with ServletUnit
Wolfgang Fahl <[email protected]> Thu, 13 Jan 2011 14:25:01 +0100
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Organization | BITPlan GmbH |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============5447660222443559300==
Content-Type: multipart/alternative;
boundary="------------020005090906040500070009"
This is a multi-part message in MIME format.
--------------020005090906040500070009
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Narinder,
thanks for making the mailinglist a bit more active with your e-mail.
I'd be happy to support you but there are two obstacles:
- Servlet...something is not the part of httpunit I know well
- I have other urgent issues on my agenda that hold me up.
You might want to investigate a solution and post it accoring to the FAQs.
Yours
Wolfgang
Am 13.01.11 11:19, schrieb Narinder Kumar:
> 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
>
>
> ------------------------------------------------------------------------------
> 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
>
>
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
--
BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl
--------------020005090906040500070009
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Narinder,<br>
<br>
thanks for making the mailinglist a bit more active with your
e-mail.<br>
I'd be happy to support you but there are two obstacles:<br>
- Servlet...something is not the part of httpunit I know well<br>
- I have other urgent issues on my agenda that hold me up.<br>
<br>
You might want to investigate a solution and post it accoring to the
FAQs. <br>
<br>
Yours <br>
<br>
Wolfgang<br>
<br>
Am 13.01.11 11:19, schrieb Narinder Kumar:
<blockquote
cite="mid:[email protected]"
type="cite">Hi,
<div><br>
</div>
<div>I was planning to unit test my Servlet through ServletUnit
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 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:</li>
</ul>
<code></div>
<div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
ServletRunner sr = new ServletRunner(new File("<b>C:/eclipse-workspaces/pocs/lms-csd/src/main/webapp/WEB-INF/web.xml</b>"));</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
ServletUnitClient sc = sr.newClient();</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
WebRequest request = new PostMethodWebRequest("<a
moz-do-not-send="true" href="http://localhost/login">http://localhost/login</a>"
);</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
request.setParameter( "userId", "test" );</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
request.setParameter( "password", "csd" );</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
WebResponse response = sc.getResponse(request);</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
String text = response.getText();</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>
Assert.assertTrue(text.contains("Welcome to Leave
Management System"));</div>
</div>
<div></code><br>
com.meterware.httpunit.HttpInternalErrorException: Error on HTTP
request: 500 org.apache.jasper.JasperException:
java.io.FileNotFoundException: <b>C:\eclipse-workspaces\pocs\lms-csd\WEB-INF\web.xml</b>
(The system cannot find the path specified) [<a
moz-do-not-send="true" href="http://localhost/login">http://localhost/login</a>]<br>
<ul>
</ul>
<div>
<ul>
<li>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 ?</li>
</ul>
<ul>
<li>In the Servlet code, I use the following code :</li>
</ul>
String result = null</div>
<div> if (someCondition)<br>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>result
= "/welcome.jsp";</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}
else {</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>logger.warn("Password
Validation failed");</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>request.setAttribute("failedlogin",
new Boolean(true));</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>result
= "/index.jsp";</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>RequestDispatcher
requestDispatcher =
getServletContext().getRequestDispatcher(result);</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>requestDispatcher.forward(request,
response);</div>
<div><br>
</div>
</div>
</div>
<blockquote class="webkit-indent-blockquote" style="margin: 0pt
0pt 0pt 40px; border: medium none; padding: 0px;">
<div>
<div>
<div>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 ?</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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
------------------------------------------------------------------------------
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.
<a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/oracle-sfdevnl">http://p.sf.net/sfu/oracle-sfdevnl</a></pre>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Httpunit-develop mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/httpunit-develop">https://lists.sourceforge.net/lists/listinfo/httpunit-develop</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: <a class="moz-txt-link-freetext" href="http://www.bitplan.de">http://www.bitplan.de</a>
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl </pre>
</body>
</html>
--------------020005090906040500070009--
--===============5447660222443559300==
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
--===============5447660222443559300==
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
--===============5447660222443559300==--