org.junitee.servlet
Class JUnitEEServlet

java.lang.Object
  extended byHttpServlet
      extended byorg.junitee.servlet.JUnitEEServlet
Direct Known Subclasses:
JUnitEEThreadedServlet, JUnitEEXMLServlet

public class JUnitEEServlet
extends HttpServlet

This servlet implements the JUnitEE test runner. By default the classloader of this servlet is used also for loading the test classes. This will work in almost any case, but if necessary you can change this behaviour by subclassing this class and overwrite the method getDynamicClassLoader() to answer the classloader of your choice.

Since:
1.5
Author:
Oliver Rossmueller
See Also:
Serialized Form

Field Summary
static java.lang.String CACTUS_CONTEXT_URL_PROPERTY
           
static java.lang.String OUTPUT_HTML
           
static java.lang.String OUTPUT_XML
           
 
Constructor Summary
JUnitEEServlet()
           
 
Method Summary
 void doGet(HttpServletRequest request, HttpServletResponse response)
           
 void doPost(HttpServletRequest request, HttpServletResponse response)
           
protected  void errorResponse(java.lang.String[] testCases, java.lang.String servletPath, java.lang.String message, java.lang.String output, HttpServletRequest request, HttpServletResponse response, java.lang.String xsl, boolean filterTrace, boolean showMethods)
           
protected  java.lang.String getDefaultOutput()
          Answer the default output format of the test report.
protected  boolean getDefaultThreadMode()
          Answer the default for the thread mode.
protected  java.lang.ClassLoader getDynamicClassLoader()
          Answer the classloader used to load the test classes.
protected  OutputProducer getOutputProducer(TestRunnerResults results, java.lang.String outputParam, HttpServletRequest request, HttpServletResponse response, java.lang.String xsl, boolean filterTrace)
          Answer the output producer for the given output format.
protected  java.lang.String[] getTestClassMethods(java.lang.String testClass)
          Looks up all the test methods for a particular test class.
 void init(ServletConfig config)
           
protected  java.lang.String[] parseTestCaseList(java.io.InputStream stream)
           
protected  void printIndexHtml(java.lang.String[] testCases, java.lang.String servletPath, java.lang.String message, java.io.PrintWriter pw, boolean showMethods)
           
protected  void printIndexHtmlTestMethods(java.lang.StringBuffer bufferList, java.lang.String testCase, java.lang.String servletPath)
          Generates links to run individual test methods
protected  void renderResults(TestRunnerResults results, HttpServletRequest request, HttpServletResponse response, java.lang.String xsl, boolean filterTrace)
           
protected  TestRunnerResults runTests(java.lang.String test, java.lang.String[] testClassNames, HttpServletRequest request, boolean forkThread)
           
protected  java.lang.String[] searchForTestCaseList()
           
protected  java.lang.String[] searchForTests(java.lang.String param)
          Search all resources set via the searchResources init parameter for classes ending with "Tests"
protected  java.lang.String[] searchForTests(java.lang.String[] param)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_HTML

public static final java.lang.String OUTPUT_HTML
See Also:
Constant Field Values

OUTPUT_XML

public static final java.lang.String OUTPUT_XML
See Also:
Constant Field Values

CACTUS_CONTEXT_URL_PROPERTY

public static final java.lang.String CACTUS_CONTEXT_URL_PROPERTY
See Also:
Constant Field Values
Constructor Detail

JUnitEEServlet

public JUnitEEServlet()
Method Detail

getDynamicClassLoader

protected java.lang.ClassLoader getDynamicClassLoader()
Answer the classloader used to load the test classes. The default implementation answers the classloader of this class, which usally will be the classloader of the web application the servlet is a part of. If this default behaviour does not work for you, overwrite this method and answer the classloader that fits your needs.


init

public void init(ServletConfig config)
          throws ServletException
Throws:
ServletException

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws ServletException,
                  java.io.IOException
Throws:
ServletException
java.io.IOException

renderResults

protected void renderResults(TestRunnerResults results,
                             HttpServletRequest request,
                             HttpServletResponse response,
                             java.lang.String xsl,
                             boolean filterTrace)
                      throws java.io.IOException
Throws:
java.io.IOException

runTests

protected TestRunnerResults runTests(java.lang.String test,
                                     java.lang.String[] testClassNames,
                                     HttpServletRequest request,
                                     boolean forkThread)

doPost

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   java.io.IOException
Throws:
ServletException
java.io.IOException

searchForTests

protected java.lang.String[] searchForTests(java.lang.String[] param)
                                     throws java.io.IOException,
                                            ServletException
Throws:
java.io.IOException
ServletException

searchForTests

protected java.lang.String[] searchForTests(java.lang.String param)
                                     throws java.io.IOException,
                                            ServletException
Search all resources set via the searchResources init parameter for classes ending with "Tests"

Throws:
java.io.IOException
ServletException

searchForTestCaseList

protected java.lang.String[] searchForTestCaseList()
                                            throws java.io.IOException
Throws:
java.io.IOException

parseTestCaseList

protected java.lang.String[] parseTestCaseList(java.io.InputStream stream)
                                        throws java.io.IOException
Throws:
java.io.IOException

getDefaultOutput

protected java.lang.String getDefaultOutput()
Answer the default output format of the test report. This implementation returns html as the default output. It is possible to set the output format by using the output request parameter. Overwrite this method in your subclass to change the output format without the need for the request parameter.

Returns:

getDefaultThreadMode

protected boolean getDefaultThreadMode()
Answer the default for the thread mode.

Returns:
true if a thread should be forked

getOutputProducer

protected OutputProducer getOutputProducer(TestRunnerResults results,
                                           java.lang.String outputParam,
                                           HttpServletRequest request,
                                           HttpServletResponse response,
                                           java.lang.String xsl,
                                           boolean filterTrace)
                                    throws java.io.IOException
Answer the output producer for the given output format.

Parameters:
results -
outputParam -
request -
response -
xsl -
filterTrace -
Returns:
Throws:
java.io.IOException

errorResponse

protected void errorResponse(java.lang.String[] testCases,
                             java.lang.String servletPath,
                             java.lang.String message,
                             java.lang.String output,
                             HttpServletRequest request,
                             HttpServletResponse response,
                             java.lang.String xsl,
                             boolean filterTrace,
                             boolean showMethods)
                      throws java.io.IOException
Throws:
java.io.IOException

printIndexHtml

protected void printIndexHtml(java.lang.String[] testCases,
                              java.lang.String servletPath,
                              java.lang.String message,
                              java.io.PrintWriter pw,
                              boolean showMethods)
                       throws java.io.IOException
Throws:
java.io.IOException

printIndexHtmlTestMethods

protected void printIndexHtmlTestMethods(java.lang.StringBuffer bufferList,
                                         java.lang.String testCase,
                                         java.lang.String servletPath)
Generates links to run individual test methods

Parameters:
bufferList -
testCase -
servletPath -

getTestClassMethods

protected java.lang.String[] getTestClassMethods(java.lang.String testClass)
Looks up all the test methods for a particular test class. Not particulary efficient, it just leverages existing test lookup functionality from org.junitee.runner.TestRunner

Parameters:
testClass -
Returns: