You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by cm...@apache.org on 2003/05/06 18:10:46 UTC

cvs commit: jakarta-cactus/documentation/docs/xdocs/integration howto_junitee.xml howto_tomcat.xml

cmlenz      2003/05/06 09:10:46

  Added:       documentation/docs/xdocs/integration howto_junitee.xml
                        howto_tomcat.xml
  Log:
  Move files directly into the 'integration' directory
  
  Revision  Changes    Path
  1.1                  jakarta-cactus/documentation/docs/xdocs/integration/howto_junitee.xml
  
  Index: howto_junitee.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document id="howto_junitee">
  
    <properties>
      <title>JUnitEE Howto</title>
      <authors>
        <author name="Kaarle Kaila" email="kaarle.kaila@iki.fi"/>
        <author name="Vincent Massol" email="vmassol@apache.org"/>
      </authors>
    </properties>
  
    <body>
  
      <section title="JUnitEE, a TestRunner inside the Container">
  
        <note>
          Since Version 1.4 Cactus contains a new Servlet Test Runner that
          enables the same features than the JUnitEE was providing, but in an
          even easier way. Please check the
          <link href="site:howto_runner">TestRunner Howto</link> tutorial.
        </note>
  
        <p>
          You can use the
          <link href="ext:junitee">JUnitEE</link> user
          interface to run your all your tests inside the Container. JUnitEE is
          a JUnit TestRunner that has been written as a servlet with the user
          interface in HTML format.
        </p>
  
        <p>
          You cannot achieve all features of Cactus using JUnitEE as
          part of them depend on being executed on the client side.
          Executing JUnitEE from ANT commands will probably not be possible.
          Some benefits however of JUnitEE are:
        </p>
  
        <ul>
          <li>
            <strong>All class files are in one place</strong>:  Install all your
            TestCase class-files only in your container classpath. Both
            TestCases derived from
            <code>junit.framework.TestCase</code> and from
            <code>org.apache.cactus.JspTestCase</code>
            will be located in the same place and only once.
          </li>
          <li>
            <strong>Run all TestCases in the container</strong>: You can mix
            both types of TestCases mentioned above in your test. All tests are
            executed inside the Container. You can use testcases derived from
            <code>junit.framework.TestCase</code> to test methods that do not
            require the http objects such as the
            <code>HttpServletRequest</code> or
            <code>HttpServletResponse</code> objects.
          </li>
        </ul>
  
        <p>
          Using JUnitEE is (relatively) simple. Assuming you have a container
          such as Weblogic, Tomcat or Orion functioning and you know how to
          configure Servlets and adding libraries to the Containers classpath and
          you are familiar with the basics of Cactus then the rest is easy.
        </p>
  
        <ul>
          <li>
            One good reason to use JUnitEE would be when you want to try Cactus
            quickly and are not concerned with automatic unit testing.
        </li>
          <li>
            Usage of standard JUnit testrunner (textui,swingui, ...) will not be
            possible if cactus is configured this way and thus the ant junit task
            cannot be used to automate the test.
          </li>
        </ul>
  
      </section>
  
      <section title="How to install JUnitEE">
  
        <p>
          Download the <link href="ext:junitee">JUnitEE</link>
          zip-file. Add a reference to <code>junitee.jar</code> to your Container
          classpath. Add also references to
          <code>junit.jar</code>,
          <code>httpunit.jar</code>
          <code>cactus.jar</code> and
          <code>aspectjrt.jar</code> if you have not
          already done that.
        </p>
  
        <note>
          add
          <code>junitee.jar</code> in the same way as cactus.jar is added.
        </note>
  
        <p>
          Configure TestServlet in your Container. You may use the example servlet
          <code>org.infohazard.servlet.TestServlet</code> that
          comes with JUnitEE. Check JUnitEE documentation. TestServlet extends
          <code>junit.htmlui.TestServletBase</code> that executes
          <code>junit.htmlui.TestRunner</code>
          i.e. the JUnitEE interface.
        </p>
  
      </section>
  
      <section title="Executing the tests with JUnitEE">
        <p>
          You request the tests from an html-page in your container. You can
          write the name of your testclasses according to the examples with
          JUnitEE as:
        </p>
  
        <ul>
          <li>
            a commandstring parameter such as "
            <code>/TestServlet?suite=fi.iki.kaila.MyTests&amp;list=yes</code>"
          </li>
          <li>
            as input using
            <code>&lt;input type="text" name="suite" size=60 /&gt;</code> in
            a form element that requests TestServlet
          </li>
          <li>
            as one or more option elements in a select element in the
            form-element
          </li>
        </ul>
      </section>
  
      <section title="Tell JUnitEE to use Cactus redirector">
  
        <p>
          The
          <code>cactus.properties</code> file must be located so that your
          container can find it e.g. in your containers classpath.
        </p>
  
      </section>
  
    </body>
  </document>
  
  
  
  1.1                  jakarta-cactus/documentation/docs/xdocs/integration/howto_tomcat.xml
  
  Index: howto_tomcat.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document id="howto_tomcat">
  
    <properties>
      <title>Tomcat Quickstart</title>
      <authors>
        <author name="Vincent Massol" email="vmassol@apache.org"/>
      </authors>
    </properties>
  
    <body>
  
      <section title="Tomcat Quickstart forewords">
  
        <note>
          This tutorial applies to Cactus 1.4 or greater and Tomcat 4.0 or
          greater.
        </note>
  
        <p>
          This document is a step by step tutorial that explains how to set up
          Cactus and run Cactus tests in Tomcat in less than 10 minutes !
          (discounting download time of course :-)).
        </p>
        <p>
          There are 2 ways of packaging Cactus so that you can execute Cactus
          tests on your application:
        </p>
        <ul>
          <li>
            By putting all Cactus jars in your <code>WEB-INF/lib</code> directory,
            as described in the <link href="site:howto_classpath">Classpath
            Tutorial</link>,
          </li>
          <li>
            By putting the Cactus jars in your container classpath so that Cactus
            will load them using the container Context class loader. This
            tutorial will describe this strategy as it is the less intrusive one
            and provides reuse of Cactus jars across several webapps.
          </li>
        </ul>
        <p>
          In addition to this, there are several ways to trigger the execution of
          the Cactus tests (see the <link href="site:howto_runner">TestRunner
          Howto</link> tutorial). We will describe the easiest one to set up in
          this tutorial, which is by using a browser.
        </p>
        <note>
          Step 1 to step 3 are a one time install steps that you need to perform
          only once to be able to run Cactus tests within Tomcat.
        </note>
  
      </section>
  
      <section title="Step 1: Install Tomcat">
        <p>
          Download <link href="http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/">Tomcat</link>
          4.0 or greater and unzip it in any directory. Let's call this directory
          <code>[tomcat-root]</code>.
        </p>
      </section>
  
      <section title="Step 2 : Copy the Cactus jars">
        <p>
          Download the Cactus jars from the <link href="site:downloads">Cactus
          download page</link>. They are located in the <code>lib/</code>
          directory in the zip.
        </p>
        <p>
          Copy the following jars to <code>[tomcat-root]/common/lib</code>:
        </p>
        <ul>
          <li>
            <code>cactus.jar</code>
          </li>
          <li>
            <code>commons-httpclient.jar</code>
          </li>
          <li>
            <code>commons-logging.jar</code>
          </li>
          <li>
            <code>junit.jar</code>
          </li>
          <li>
            <code>aspectjrt.jar</code>
          </li>
        </ul>
        <note>
          This is the minium set of jars needed. If later on you wish to use the
          Cactus <link href="site:howto_httpunit">HttpUnit integration</link>
          you'll also need to copy <code>httpunit.jar</code>.
        </note>
      </section>
  
      <section title="Step 3: Modify Tomcat web.xml">
        <p>
          Edit <code>[tomcat-root]/conf/web.xml</code> and add the following at
          the beginning of the file, after the <code>&lt;webapp&gt;</code> tag:
        </p>
  <source><![CDATA[
  <servlet>
    <servlet-name>ServletRedirector</servlet-name>
    <servlet-class>
      org.apache.cactus.server.ServletTestRedirector
    </servlet-class>
    <init-param>
      <param-name>param1</param-name>
      <param-value>value1 used for testing</param-value>
    </init-param>
  </servlet>
  
  <servlet>
    <servlet-name>ServletTestRunner</servlet-name>
    <servlet-class>
      org.apache.cactus.server.runner.ServletTestRunner
    </servlet-class>
  </servlet>
  ]]></source>
  
        <p>
          Then, after the last <code>&lt;servlet&gt;</code> definition (there
          are a few provided by Tomcat in addition to our 2 above), add:
        </p>
  
  <source><![CDATA[
  <servlet-mapping>
      <servlet-name>ServletRedirector</servlet-name>
      <url-pattern>/ServletRedirector</url-pattern>
  </servlet-mapping>
  
  <servlet-mapping>
      <servlet-name>ServletTestRunner</servlet-name>
      <url-pattern>/ServletTestRunner</url-pattern>
  </servlet-mapping>
  ]]></source>
  
      </section>
  
      <section title="Step 4: Creating a sample applicaton to test">
        <p>
          We're now going to create a very very simple application to server
          so that we can unit test it.
        </p>
        <p>
          First, create the following directory structure:
        </p>
  
  <source><![CDATA[
  [tomcat-root]/webapps
    |_ test
      |_ WEB-INF
        |_ classes
  ]]></source>
  
        <p>
          Then, create the following <code>SampleServlet.java</code> java source
          file, compile it and copy the resulting .class file in
          <code>[tomcat-root]/webapps/test/WEB-INF/classes</code>. Note that
          you can download the pre-compiled class file
          <link href="site:code_sample_servlet">here</link>.
        </p>
  
  <source><![CDATA[
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  
  public class SampleServlet extends HttpServlet
  {
      public void saveToSession(HttpServletRequest request)
      {
      	String testparam = request.getParameter("testparam");
      	request.getSession().setAttribute("testAttribute", testparam);
      }
  }
  ]]></source>
  
        <note>
          You'll notice that this isn't even a finished servlet ! However, this
          shows that you can start testing your code with Cactus even before
          you have finished writing it completely. Extreme Programmers should
          like this :-)
        </note>
  
        <p>
          We're now read to create our first Cactus test case. Create the
          following <code>TestSampleServlet.java</code> java source file, compile
          it and copy the resulting .class file in
          <code>[tomcat-root]/webapps/test/WEB-INF/classes</code>. Note that
          you can download the pre-compiled class file
          <link href="site:code_test_sample_servlet">here</link>.
        </p>
  
  <source><![CDATA[
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.cactus.ServletTestCase;
  import org.apache.cactus.WebRequest;
  
  public class TestSampleServlet extends ServletTestCase
  {
      public TestSampleServlet(String theName)
      {
          super(theName);
      }
  
      public static Test suite()
      {
          return new TestSuite(TestSampleServlet.class);
      }
  
      public void beginSaveToSessionOK(WebRequest webRequest)
      {
          webRequest.addParameter("testparam", "it works!");
      }
  
      public void testSaveToSessionOK()
      {
          SampleServlet servlet = new SampleServlet();
          servlet.saveToSession(request);
          assertEquals("it works!", session.getAttribute("testAttribute"));
      }
  }
  ]]></source>
  
      </section>
  
      <section title="Step 5: Run the test">
  
        <p>
          Time to enjoy our hard work ! Start Tomcat by running
          <code>[tomcat-root]/bin/startup.bat</code> (for windows) or
          <code>[tomcat-root]/bin/startup.sh</code> (for unix).
        </p>
        <p>
          Open a browser and point it at
          <code>http://localhost:8080/test/ServletTestRunner?suite=TestSampleServlet</code>
        </p>
        <p>
          You should see:
        </p>
        <figure src="images/tomcat_xml.jpg" alt="XML output of ServletTestRunner"/>
  
      </section>
  
      <section title="Step 6: Even more fun!">
        <p>
          Ok, that's nice ... But what if I want HTML instead of XML? Don't
          worry there is a solution. Grab the following
          <link href="site:code_junit_noframes">junit-noframes.xsl</link>
          stylesheet used to format JUnitReport Ant task results and drop it in
          <code>[tomcat-root]/webapps/test</code>. Then, open a browser and type
          <code>http://localhost:8080/test/ServletTestRunner?suite=TestSampleServlet&amp;xsl=junit-noframes.xsl</code>.
          You should now see the following:
        </p>
  
        <figure src="images/tomcat_html.jpg" alt="HTML output of ServletTestRunner"/>
  
        <note>
          This will work with any browser that supports client-slide XSLT 
          transformations (both Internet Explorer and Mozilla do, for example).
        </note>
  
      </section>
  
    </body>
  
  </document>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org