unit testing - Run Jettys ServletTester within JUnit test -
I'm trying to run Jettys ServletTester
in my JUnit test. To test setup I first created a simple HelloServlet
, but when I try to request a servlet, I get a invalid access
so far That I have so far:
my unit test
@ first public zero set up throws exception (exception) {tester = new ServletTester (); Tester.setContextPath ("/ reference"); Tester.addServlet (HelloServlet Class, "/ Hello / *"); Tester.start (); } Public Zero Tyride () throws exception after {tester.stop (); } @Test Public Zero Examination Default Services throws an exception {HttpTester request = new HTTPTTER (); Request.setMethod ("GET"); Request.setHeader ("host", "127.0.0.1"); Request.setURI ("/ Reference / Hello / Information"); Request.setVersion ("HTTP / 1.0"); HTTPTestor feedback = new HTTPTaster (); Response.parse (tester.getResponses (request.generate ())); AssertNull (response.getMethod ()); AssertEquals (200, response.getStatus ()); AssertEquals ("& lt; h1 & gt; Hello servlet & lt; / h1 & gt;", response.getContent ()); }
My HelloServlet
This servlet is defined as unit testing in the same file, because I After all, if everything is going on for the initial establishment of JT, I will remove it (or maybe keep it, but it will remain within the unit test).
Update This servlet was defined within the unit itself because it meant only as a configuration test for the JTI server. But Jetti was not able to use it, and after taking it to a public class and looking for a file for himself, worked as comment.
class HelloServlet extends HttpServlet {@Override Public Zero doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {PrintWriter out = resp.getWriter (); Out.println ("hello, world!"); Out.flush (); }}
My Exception ...
2009-10-20 09: 36: 28.973 :: info: STDERR via org.mortbay Logging Logs.tdErrLog 2009-10-20 09: 36: 28.989 :: Info: JT-6.1.21 2009-10-20 09:36: 29.098 :: Information: LocalConnector @ 0.0.0.0: 1 200 9-10- 20 09: 36: 29.161: / Context: Warning: unavailable java.lang.IllegalAccessException: class org.mortbay.jetty.servlet.Holder class can not reach member of my.package. Hello with the researchers "" on the sun. Make sure at java.lang.Class.newInstance0 (Class.java349) at java.lang.Class.newInstance (class.java.308) at Org.mortbay.jetty.servlet.older.newInstanceMailer Login (Reflections.Javaah: 65) Org On org.mortbay.jetty.servlet.ServletHolder.getServlet (ServletHolder.java:339) at ORg.mortbay.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:428) (holder.java 153) on .mortbay. Jetty.servlet.ServletHolder.handle (ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler.handle (org.mortbay.jetty.security.SecurityHandler.handle at servlethand or.g.mortbay.jetty (securityHandler. Java, 16) org.mortbay.jetty.servlet.SessionHandler.handle (session Handler.java:182) at ler.java:390). .handler.ContextHandler.handle (ContextHandler.java:765) at org.mortbay.jetty.handle.HandlerWrapper.handle (HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle (server.java: 326) Org.mortbay.jetty.HttpConnection.handleRequest (HTTP Connection.Javaana 00:06) org.mortbay.jetty.HttpConnection $$handler on Header Full (HTTPConnect.java: 9 15) at org.mortbay.jetty.HttpParser.parseNext (HttpParser.java: 539) available at org.mortbay.jetty.HttpParser.parse (http: // java1212) org.mortbay.jetty. On HttpConnection.handle (http Connection .java: 405) at org.mortbay.jetty.LocalConnector.accept (Local Connector .Java): 186) org.mortbay.jetty.AbstractConnector $ Acceptor.run (AbstractConnector.java:707) org .mreadbay.thread.QueuedThreadPool $ PoolThread.run (QueuedTh ReadPool.java +82)
is odd enough, because I got this example almost directly.
Comments
Post a Comment