|
Last update : July 6 2002
Doc for : v1.3
Cactusについて
Cactus とは
ニュース
変更履歴
特徴/開発状況
目標
ロードマップ/ToDo
協力者
協力者募集
Cactus ユーザ
テスト済環境 ...
ライセンス
ダウンロード
ダウンロード
ドキュメント
Cactus の仕組み
さぁ始めよう
モック対コンテナ
Javadocs
└Javadocs
よくある質問
Howto ガイド
クラスパス Howto
設定 Howto
アップグレードHowto
テストケース Howto
セキュリティHowto
Ant Howto
HttpUnit Howto
サンプル Howto
EJB Howto
IDE Howto
JUnitEE Howto
サポート
Bug DB
メーリングリスト
その他
名前の由来
ロゴコンテスト
参考文献
アクセス状況
└WebAlizer
開発者向け
CVS
コード規約
ビルドの結果
|
| Cactus の仕組み |
UML シーケンス図はここ
をクリックしてください。
Click here for a UML
sequence diagram.

 |
Cactus はJUnit Testcase を拡張する
いくつかのTestCase クラスと、何種類かのリダイレクタ
(Servlet リダイレクタ、JSP リダイレクタ、...)を提供します。
上の図は Cactus の仕組みを示す一般的な図です。
各リダイレクタ・プロキシーについての詳細は次章以降で見ていきます。
Cactus provides several TestCase classes that extends the
JUnit Testcase and it also provides several kind of
redirectors (Servlet Redirector, JSP Redirector, ...). The diagram
above is a generic diagram which serves to explain the principles.
You'll find details for a specific redirector proxy in the next
section.
|
 |
YYYTestCase = ( ServletTestCase | FilterTestCase | JspTestCase )
|
 |
XXX はテスト・ケースの名前です。
各 YYYTestCase クラスはいくつかのテスト・ケースを含んでいます。
XXX is the name of the test case. Each YYYTestCase class contains
several test cases.
|
では、これがどのように動作するのか、
いくつかのステップを踏みながら見ていきましょう。
あなたのテスト・ケース・クラス YYYTestCase
の中の各 testXXX() メソッドに対しては、
以下の操作が行なわれます。
Let's go through the different steps to understand how it works. Here
is what happens for each testXXX() method in your
test case class (derived from YYYTestCase) :
-
JUnit の Test Runner が
YYYTestCase.runTest()
を呼び出します。このメソッドは beginXXX(WebRequest)
を探し出して、それが見つかれば実行します。
これはクライアント側(つまり、サーバ・エンジンの外)で実行されます。
beginXXX() に渡される WebRequest
パラメータは、ステップ2 のリダイレクタ・プロキシーに送られる
HTTP ヘッダや HTTP パラメータなどの設定に使用されます。
The JUnit Test Runner calls a YYYTestCase.runTest()
method. This method looks for a
beginXXX(WebRequest) method and executes it if
one is found. This is executed on the client side (i.e. not in a
server engine). The WebRequest
parameter passed to the beginXXX() method is used
to set the HTTP headers, the HTTP parameters, ... that will be
sent in step 2 to the Redirector proxy.
-
YYYTestCase.runTest()
メソッドはリダイレクタ・プロキシーに対して HTTP 接続を開始します。
beginXXX()
メソッドの中で設定された全てのパラメータは
HTTP リクエストの一部(HTTP ヘッダ、HTTP パラメータ、...)
として送られます。
The YYYTestCase.runTest() method then opens an HTTP
connection to the Redirector proxy. All the parameters set up
in the beginXXX() method are sent in the HTTP request
(HTTP headers, HTTP parameters, ...)
-
リダイレクタ・プロキシーは、サーバ側で
あなたのテスト・ケース・クラスのためのプロキシーとして動作します。
これはつまり、 あなたのテスト・ケース・クラスは
二回インスタンス化されるということを意味しています:
一回はクライアント側で(JUnit の Test Runner によって)、
もう一回はサーバ側で(リダイレクト・プロキシーによって)です。
クライアント側のインスタンスは
beginXXX()
メソッドと endXXX()
メソッドを実行するのに使用され(ステップ1 とステップ8 を参照)、
サーバ側のインスタンスは testXXX()
メソッドを実行するのに使用されます(ステップ4 を参照)。
リダイレクタ・プロキシーの働きは以下の通りです。
The Redirector proxy acts as a proxy on the server side for your
test case class. It means that your test case class is instantiated
twice : once on the client side (by the JUnit Test Runner) and once
on the server side (by the Redirector proxy). The client side
instance is used for executing the
beginXXX() and endXXX() methods (see
steps 1 and 8) and the server side instance is used for executing
the testXXX() methods (see step 4). The Redirector
proxy does the following :
-
リフレクションを利用して、
あなたのテスト・クラスをインスタンス化します。
そして、いくつかの暗黙のオブジェクト(これは
YYYTestCase のクラス変数です)を設定します。
どのような暗黙のオブジェクトが設定されるかは、
リダイレクタ・プロキシーによって異なります(次章を参照)。
creates an instance of your test class using reflection. It
then sets specific implicit objects (which are class
variables of YYYTestCase). These implicit objects
depend on the redirector proxy (see next section).
-
サーバ・オブジェクトのための
Cactus ラッパー(
HttpServletRequest、
ServletConfig、ServletContext、...)
をいくつか生成します。
これらのラッパーはテスト環境をシミュレートした値を返すように、
いくつかのメソッドをオーバーライドしています。
たとえば、Cactus フレームワークは URI をシミュレートする
(つまり、リダイレクタ・プロキシーの URI ではなく、
テスト対象の URI が指定されたかのように振舞う)ことができます。
このために、getServerName()、
getServerPort(),
getRequestURI(), ... といったメソッドは
(もしユーザによって定義されていれば)シミュレートされた
URI に基く値を返します。
creates instances of Cactus wrappers for some server objects
(HttpServletRequest, ServletConfig,
ServletContext, ...). This is to be able to
to override some methods in order to return simulated values.
For example, the Cactus framework can simulate an URI (i.e.
act as if this URI was called instead of the Redirector proxy
URI). Thus, the getServerName(),
getServerPort(),
getRequestURI(), ... methods return values based
on the simulated URI (if there is any defined by the user).
-
ユーザの指定に従って、HTTP セッションを生成します(ユーザは
beginXXX() メソッドの中で
WebRequest.setAutomaticSession(boolean)
を使用することによって、
セッションを生成するかどうかを指定できます。
デフォルトではセッションは常に生成されます)。
次に、リダイレクタはリフレクションによって暗黙のオブジェクト
session に値を代入します。
creates an HTTP Session if the user has expressed the wish
(using the
WebRequest.setAutomaticSession(boolean)
code in the beginXXX() method. By default a session
is always created) and the redirector fills by reflection the
session implicit object.
-
テスト・クラス内の
setUp()、testXXX()、
tearDown() メソッドが(この順番で)実行されます。
これらはリダイレクタ・プロキシーがリフレクションを使用して
呼び出します。もちろん、setUp() と
tearDown()は(JUnit と同様)オプションです。
The setUp(), testXXX()
and tearDown() methods of your test class are executed
(in that order). They are called by the Redirector proxy using
reflection. Of course, setUp() and
tearDown() are optional (same as in JUnit).
-
testXXX() メソッドは、テストのために
あなたのサーバ側コードを呼び出し、テストを実行して、
JUnit のassert API を使用して結果を確認します(assert()、
assertEquals()、fail()、...)。
Your testXXX() method calls your server
side code to test, executing the test and using the JUnit assert API
to assert the result (assert(),
assertEquals(), fail(), ...)
-
もしテストが失敗すれば、
testXXX()
メソッドはリダイレクタ・プロキシーによって捕捉される例外を
スローします。
If the test fails, your testXXX() methods
throws exceptions which are caught by the Redirector proxy.
-
例外が発生すると、リダイレクタ・プロキシーは例外に関する情報
(名前、クラス、スタック・トレース)をクライアント側に返します。
その例外に関する情報は JUnit によって Test Runner
のコンソールに表示されます。
If an exception has been raised, the Redirector proxy returns the
information about the exception (it's name, class, stack trace) back
to the client side. Information about the exception will then be
printed by JUnit in it's Test Runner console.
-
もし例外が発生しなければ、
YYYTestCase.runTest()
メソッドはendXXX(org.apache.cactus.WebResponse)
メソッドかendXXX(com.meterware.httpunit.WebResponse)
メソッド(このシグネチャはHttpUnit
との連携に使用されます)を探し出して、
それが見つかれば実行します。この段階で、あなたは返ってきた
HTTP ヘッダやクッキー、Servlet の出力などをチェックすること
ができます。endXXX() メソッドの中で JUnit の
assert と、Cactus によって提供される
ヘルパー・ユーティリティ・クラスを使用してください。
If no exception occurred, the YYYTestCase.runTest()
method looks for an endXXX(org.apache.cactus.WebResponse)
or endXXX(com.meterware.httpunit.WebResponse) (this
signature is used for HttpUnit
integration) method and executes it if found. At this stage,
you have the opportunity to check returned HTTP headers, Cookies and
the servlet output stream in the endXXX() method, again
using JUnit asserts and helper utility classes provided by Cactus.
| リダイレクタ・プロキシー |
Cactus はリダイレクタ・プロキシーの実装を 3種類、提供しています
(これらの使用方法に関する詳細は
TestCase Howto
チュートリアルを参照してください)。
Cactus provides 3 implementations of Redirector Proxies
(see the TestCase Howto
tutorial for more details on how to use these redirectors) :
-
Servlet リダイレクタ。このリダイレクタは Servlet
として実装されており、servlet のメソッドや Servlet
オブジェクト(
HttpServletRequest、...)
を使用する java クラスの単体テストに使用されます。
A Servlet Redirector. This redirector is a servlet that
should be used for unit testing servlet methods or any java class
that uses servlet objects (HttpServletRequest, ...)
-
JSP リダイレクタ。このリダイレクタは JSP
ページとして実装されており、
JSP の暗黙のオブジェクト(
PageContext、...)
にアクセスする必要のあるサーバ・コードの単体テストに使用されます。
JSP リダイレクタはカスタム・タグ・ライブラリのテストにも使用されます。
A JSP Redirector. This redirector is a JSP page that
should be used for unit testing server code that need access to
JSP implicit objects (PageContext, ...). The JSP
Redirector should be used to unit test custom Tag libraries.
-
Filter Redirector。このリダイレクタは Servlet
Filter として実装されており、Servlet Filter や Filter オブ
ジェクト(
FilterConfig、...)を使用する java
クラスの単体テストに使用されます。
A Filter Redirector. This redirector is a Servlet Filter
that should be uses for unit testing Servlet Filters or any java
class that uses filter objects (FilterConfig, ...).
| Servlet リダイレクタ・プロキシー |

クライアント側は Servlet リダイレクタに対して二回、
HTTP 接続します。一回目はテストを実行し、
Servlet の出力を受け取るためのもので、
二回目はテスト結果を受け取るためのものです。
これによってテストが失敗したときの例外の情報(メッセージや
スタック・トレースなど)を取得することができます。
テスト結果は一旦ServletContext内の変数に保存され、
二回目の HTTP 接続によって取得されます。
The client side opens 2 HTTP connections to the Servlet redirector.
Once to execute the tests and retrieve the servlet output stream and
a second time to get the test result. This is to be able to get
the exception data (message, stack trace, ...) if the test failed.
The test results are stored in a variable which is put in the
ServletContext and then retrieved on the second HTTP
connection.
|
| JSP リダイレクタ・プロキシー |

クライアント側は JSP リダイレクタに対して二回、
HTTP 接続します。一回目はテストを実行し、
Servlet の出力を受け取るためのもので、
二回目はテスト結果を受け取るためのものです。
これによってテストが失敗したときの例外の情報(メッセージや
スタック・トレースなど)を取得することができます。
テスト結果は一旦ServletContext内の変数に保存され、
二回目の HTTP 接続によって取得されます。
The client side opens 2 HTTP connections to the JSP redirector.
Once to execute the tests and retrieve the servlet output stream and
a second time to get the test result. This is to be able to get
the exception data (message, stack trace, ...) if the test failed.
The test results are stored in a variable which is put in the
ServletContext and then retrieved on the second HTTP
connection.
|
| Filter リダイレクタ・プロキシー |

クライアント側は Filter リダイレクタに対して二回、
HTTP 接続します。一回目はテストを実行し、
Servlet の出力を受け取るためのもので、
二回目はテスト結果を受け取るためのものです。
これによってテストが失敗したときの例外の情報(メッセージや
スタック・トレースなど)を取得することができます。
テスト結果は一旦ServletContext内の変数に保存され、
二回目の HTTP 接続によって取得されます。
The client side opens 2 HTTP connections to the Filter redirector.
Once to execute the tests and retrieve the servlet output stream and
a second time to get the test result. This is to be able to get
the exception data (message, stack trace, ...) if the test failed.
The test results are stored in a variable which is put in the
ServletContext and then retrieved on the second HTTP
connection.
|
|
|
|
|