<?xml version="1.0" encoding="EUC-JP"?>

<!DOCTYPE document SYSTEM "./dtd/document-v10.dtd">

<document>
  <header>
    <title>HttpUnit Howto</title>
    <authors>
      <person name="Vincent Massol" email="vmassol@apache.org"/>
    </authors>
    <translators><person name="漆島賢二"/></translators>
  </header>

  <body>

    <s1 title="HttpUnit との統合/HttpUnit integration">

      <note>
        <strong>The HttpUnit integration is only available for Cactus v1.2 and
        later. It won't work with version 1.1 and earlier.</strong>
      </note>
      <note>
        <strong>HttpUnit との統合は Cactus 1.2 以上でのみ利用可能です。
	バージョン 1.1 以前では動作しません。</strong>
      </note>

      <p>
        Cactus test cases allow to assert the results of the returned server
        output stream in an <code>endXXX()</code> method (where <code>XXX</code>
        is the name of your test case).
      </p>
      <p>
	Cactus テストケースでは、
	<code>endXXX()</code>
	メソッドにより返されたサーバー出力ストリームの結果のアサーションを記述することができます。
	(<code>XXX</code>はテストケース名です)
      </p>
      <p>
        Cactus proposes 2 ways of writing your <code>endXXX()</code> methods,
      </p>
      <p>
	Cactus は <code>endXXX()</code>メソッドを記述する方法を 2 通り提案しています。
      </p>
      <ul>
        <li>
          <strong>Method 1</strong> :  it allows you to do simple check on the
          returned stream like checking for returned cookies, HTTP headers and
          to do assertions on the returned content as a String,
        </li>
        <li>
          <strong>方法1</strong> :  
	返されたストリームに対し、
	クッキーやHTTP ヘッダといった単純なチェックを行い、
	戻り値を文字列として検証できるようにするもの
        </li>
        <li>
          <strong>Method 2</strong> : it allows you to do complex and
          powerful assertions on the returned content. For example, you can
          get an HTML DOM view of your returned HTML page and check that a given
          named table has the correct number of columns, ....
        </li>
        <li>
          <strong>メソッド 2</strong> : 
	返された内容に対し、複雑で強力なアサーションを可能にするもの。
	例えば、返された HTML ページの HTML DOM のビューを得たり、
	与えられた名前のテーブルが正しいカラム数であるかチェックするなどです。
        </li>
      </ul>
      <p>
        Method 2 is supported through the integration with
        <link href="http://httpunit.sourceforge.net">HttpUnit</link>, meaning
        you'll benefit from the full assertion power of HttpUnit in your
        <code>endXXX()</code> method. Method 1 is a class provided by Cactus.
      </p>
      <p>
        Depending on your need you can choose, on a per test case basis, the
        method you want to use.
      </p>
      <p>
	必要に応じて、使いたい方法を、テストケース単位で選択することができます。
      </p>

    </s1>

    <s1 title="使い方/Usage">

      <p>
        The signature of an <code>endXXX()</code> method is always :
      </p>
      <p>
	<code>endXXX()</code> メソッドの書式は常に次のようになります: 
      </p>
<source><![CDATA[
public void endXXX(WebResponse theResponse)
{
[...]
}
]]></source>

      <p>
        The <code>WebResponse</code> object is passed by the Cactus framework
        to your <code>endXXX()</code> method. What changes between the 2
        methods described above is the class of the <code>WebResponse</code>
        object that is passed :
      </p>
      <p>
	<code>WebResponse</code> オブジェクトは
	Cactus フレームワークにより
	上述の 2 つの方法の違いは、
	渡される <code>WebResponse</code> オブジェクトのクラスです : 
What changes between the 2
        methods described above is the class of the <code>WebResponse</code>
        object that is passed :
      </p>
      <ul>
        <li>
          <code>org.apache.cactus.WebResponse</code> for Method 1,
        </li>
        <li>
          方法1では<code>org.apache.cactus.WebResponse</code>
        </li>
        <li>
          <code>com.meterware.httpunit.WebResponse</code> for Method 2
          (HttpUnit)
        </li>
        <li>
	  方法2(HttpUnit)では
          <code>com.meterware.httpunit.WebResponse</code>
        </li>
      </ul>

      <s2 title="方法1 : Cactus が提供する WebResponse オブジェクト/Method 1 : Cactus provided WebResponse object">

         <p>
           An example :
         </p>
         <p>
           例 :
         </p>

<source><![CDATA[
public void endXXX(org.apache.cactus.WebResponse theResponse)
{
  // Get the returned cookies
  // 返されたクッキーを得る
  Hashtable cookies = theResponse.getCookies();

  // Get the returned content as a string
  // 返されたコンテンツを文字列として得る
  String content = theResponse.getText();

  // Do some asserts
  // アサーションを行う
  assertEquals(content, "<html><body><h1>Hello world!</h1></body></html>");
[...]
}
]]></source>

        <note>
          For the complete list of all methods available on the
          <code>WebResponse</code> object, see the associated Javadoc.
        </note>
        <note>
	  <code>WebResponse</code> オブジェクトで利用可能なメソッドの完全な一覧は、対応する javadoc をご覧ください。
        </note>

      </s2>

      <s2 title="メソッド 2 : HttpUnit により提供される WebResponse オブジェクト/Method 2 : HttpUnit provided WebResponse object">

         <p>
           An example :
         </p>
         <p>
           例 :
         </p>

<source><![CDATA[
public void endXXX(com.meterware.httpunit.WebResponse theResponse)
{
  WebTable table = theResponse.getTables()[0];
  assertEquals("rows", 4, table.getRowCount());
  assertEquals("columns", 3, table.getColumnCount());
  assertEquals("links", 1, table.getTableCell(0, 2).getLinks().length);
[...]
}
]]></source>

        <note>
          For the complete list of all methods available on the
          HttpUnit <code>WebResponse</code> object, see the HttpUnit
          documentation.
        </note>
        <note>
	  HttpUnit の
	  <code>WebResponse</code> オブジェクトで利用可能なメソッドの完全な一覧は、HttpUnit のドキュメントをご覧ください。
        </note>

      </s2>

    </s1>

  </body>
</document>
