- 追加された行はこの色です。
- 削除された行はこの色です。
#topicpath
----
//ここにコンテンツを記述します。
**Cactusとは [#qd04ede8]
[[Cactus:http://jakarta.apache.org/cactus/index.html]]とはJ2EEのモジュールのUnitテストを行うためのフレームワークです。
JUnitのクラスを拡張して、コンテナ上でテストを行うためのクラス群を提供します。
具体的には、requestパラメータにいろいろな値をセットしてブラウザのリクエストをシミュレーションすることや、ブラウザへ返却される画面に正しく値がセットされてるかをチェックするクラスなどを提供してくれます。
またCactusで対象としているモジュールははServlet,JSP,Filter などです。
#contents
**ダウンロード [#l74a60e4]
[[ここ:http://jakarta.apache.org/cactus/downloads.html]]よりダウンロード可能です。
ダウンロードして、サンプルコーディングを作りながら試してみました。
**サンプルの説明 [#df14f0da]
今回はサーブレットとフィルタとJSPを使ったモジュールのテストをしようと思います。
#ref(01.png)
テストのサーブレット(kino.servlet.SampleServlet)はユーザ入力値を連結して表示するだけの単純なモノです。連結処理を行いJSP(/WEB-INF/index.jsp)に処理を転送します。
フィルタ(kino.filter.RequestEncodingFilter)はrequest.setCharacterEncoding()を実行するフィルタです。
***サンプルの一部 [#n765869a]
-SampleServlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
// パラメタに値が入ってたら値を連結
if (param1 != null && param2 != null) {
String answer = param1 + param2;
request.setAttribute("answer", answer);
request.setAttribute("param1", param1);
request.setAttribute("param2", param2);
}
sc.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
}
-index.jsp
<jsp:useBean id="answer" class="java.lang.String" scope="request" />
<jsp:useBean id="param1" class="java.lang.String" scope="request" />
<jsp:useBean id="param2" class="java.lang.String" scope="request" />
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
<title>サンプルアプリケーション</title>
</head>
<body>
<p>サンプルアプリケーション</p>
<form action="<%=request.getContextPath()%>/SampleServlet" method="get">
<table border="0">
<tbody>
<tr>
<td>param1</td>
<td><input type="text" name="param1" size="20" value='<%=param1%>' /></td>
</tr>
<tr>
<td>param2</td>
<td><input type="text" name="param2" size="20" value='<%=param2%>' /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="action" value="実行" /></td>
</tr>
</tbody>
</table>
<p><%=answer%></p>
</form>
-RequestEncodingFilter
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException, IOException {
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
**Cactusでテストを行うための準備 [#jd3e8f56]
***jarファイルの配置 [#wc3e19be]
WEB-INF/lib ディレクトリに
junit-3.8.1.jar
aspectjrt-1.1.1.jar
cactus-1.6.1.jar
commons-httpclient-2.0.jar
commons-logging-1.0.3.jar
を配置しておきます。
***cactus.propertiesの配置 [#q992af08]
次にクラスパスが通っているディレクトリにcactus.propertiesをおいておきます。
このファイルに記述する内容は
cactus.contextURL=http://localhost:9080/CactusTest
のみでOKです(テスト対象のURL)。
***jspRedirector.jspの配置 [#s1e9c708]
jspRedirector.jspをルート直下に配置します。
最終的にディレクトリ構成は以下のようになりました。
#ref(03.png)
*** web.xmlの編集 [#u1c3cb52]
Cactusはテスト対象のプログラムを直接呼び出すのではなく、プロクシ(リダイレクタとかいう)を介して
クライアント(テストクラス) -> リダイレクタ -> テストクラス -> テスト対象クラス
という方式でテストを行います。というわけでweb.xmlにリダイレクタとなるサーブレットやフィルタ、JSPなどを登録する必要があります。
登録する内容は
<filter>
<filter-name>FilterTestRedirector</filter-name>
<filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterTestRedirector</filter-name>
<url-pattern>/FilterRedirector</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ServletTestRedirector</servlet-name>
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
</servlet>
<servlet>
<servlet-name>jspRedirector</servlet-name>
<jsp-file>/jspRedirector.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>ServletTestRedirector</servlet-name>
<url-pattern>/ServletRedirector</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jspRedirector</servlet-name>
<url-pattern>/JspRedirector</url-pattern>
</servlet-mapping>
などです。
以上で準備は完了です。
**ようやくテストクラスの記述 [#n6df8ed7]
ようやくテストクラスを記述します。
*** [#u3be3a1b]
**TIPS [#c96516bd]
*** リクエストURLを偽造する。 [#pacedaa3]
webRequest.setURL("localhost:8080","/[context]","/[ServletName]",null,null);
-http://www.ingrid.org/jajakarta/cactus/doc/howto_testcase_servlet.html
----
この記事は
#vote(おもしろかった[5],そうでもない[1])
- asian twinks where get [URL= http://www.palurl.com/?Vmy9NmyO.com ]asian twinks info[/URL] ? <a href= http://www.palurl.com/?Vmy9NmyO.net >asian twinks</a> about about http://www.palurl.com/?Vmy9NmyO.org asian twinks + -- [[wwe]] &new{2007-03-06 (火) 08:52:46};
- http://besturl.in/midget_porn for more info click to [URL= http://besturl.in/midget_porn.com ]http://besturl.in/midget_porn[/URL] where get <a href= http://besturl.in/midget_porn.net >http://besturl.in/midget_porn info</a> ? for more info click to http://besturl.in/midget_porn.org http://besturl.in/midget_porn -- [[wwe]] &new{2007-03-06 (火) 09:10:32};
- about http://ourl.org/lesbian_bukkake lesbian bukkake about http://ourl.org/black_bukkake black bukkake http://ourl.org/bukkake_facial bukkake facial aboutfor more info click to http://vilasta.com/?bpBA7OIo flashing public about http://ourl.org/gay_bukkake gay bukkake l -- [[wwe]] &new{2007-03-06 (火) 18:57:49};
- for more info click to http://mazzzer.memebot.com/vintage/porn-vintage-lingerie-pictures.html porn vintage lingerie pictures http://mazzzer.memebot.com/vintage/mens-vintage-clothes.html men's vintage clothes informationabout http://mazzzer.memebot.com/vintage/mature-vintage-porn.html mature vintage porn about http://mazzzer.memebot.com/vintage/hand-job-mature-sex-vintage.html hand job mature sex vintage information about http://mazzzer.memebot.com/vintage/military-sex-education-vintage.html military sex education vintage information for more info click to http://mazzzer.memebot.com/vintage/pinup-vintage.html pinup vintage http://mazzzer.memebot.com/vintage/porn-vintage.html porn vintage about -- [[wwe]] &new{2007-03-06 (火) 19:34:00};
- http://mazzzer.memebot.com/vintage/vintage-asian-sex.html vintage asian sex aboutabout http://mazzzer.memebot.com/vintage/vintage-aprons.html vintage aprons about http://mazzzer.memebot.com/vintage/vintage-board-games.html vintage board games http://mazzzer.memebot.com/vintage/vintage-art.html vintage art information http://mazzzer.memebot.com/vintage/sex-vintage.html sex vintage about http://mazzzer.memebot.com/vintage/vintage-1920-sex.html vintage 1920 sex about http://mazzzer.memebot.com/vintage/vintage-anal-porn.html vintage anal porn aboutt -- [[wwe]] &new{2007-03-06 (火) 21:35:50};
- about http://www.linkhider.com/flashing flashing about http://www.linkhider.com/flashing_girl_pictures flashing girls pictures information http://ourl.org/american_bukkake american bukkake informationabout http://ourl.org/tampa_bukkake tampa bukkake about http://ourl.org/free_bukkake free bukkake m -- [[wwe]] &new{2007-03-06 (火) 21:44:13};
- where get http://mazzzer.memebot.com/vintage/vintage-ebony-sex.html vintage ebony sex info ?about http://mazzzer.memebot.com/vintage/vintage-gay-sex.html vintage gay sex information http://mazzzer.memebot.com/vintage/vintage-drums.html vintage drums aboutfor more info click to http://mazzzer.memebot.com/vintage/vintage-girdles.html vintage girdles where get http://mazzzer.memebot.com/vintage/vintage-fabric.html vintage fabric info ? http://mazzzer.memebot.com/vintage/vintage-dresses.html vintage dresses aboutabout http://mazzzer.memebot.com/vintage/vintage-grannies.html vintage grannies z -- [[wwe]] &new{2007-03-07 (水) 00:13:28};
- about http://www.linkhider.com/flashing_public flashing public information about http://www.linkhider.com/flashing_spring_break_girls flashing spring break girls information http://www.linkhider.com/britney_spears_flashing britney spears flashing informationfor more info click to http://www.linkhider.com/college_girls_flashing college girls flashing http://www.linkhider.com/britney_flashing britney flashing information% -- [[wwe]] &new{2007-03-07 (水) 00:19:12};
- where get http://www.linkhider.com/flashing_in_public flashing in public info ? http://besturl.in/midget_porn midget porn informationfor more info click to http://www.linkhider.com/flashing_teen flashing teen http://www.linkhider.com/flashing_tits flahing tits aboutfor more info click to http://www.linkhider.com/boob_flashing boob flashing s -- [[wwe]] &new{2007-03-07 (水) 03:04:09};
- about http://mazzzer.memebot.com/vintage/vintage-lesbian-porn.html vintage lesbian porn information http://mazzzer.memebot.com/vintage/vintage-lingerie-sex.html vintage lingerie sex informationabout http://mazzzer.memebot.com/vintage/vintage-lingerie.html vintage lingerie where get http://mazzzer.memebot.com/vintage/vintage-motorcycles.html vintage motorcycles info ?for more info click to http://mazzzer.memebot.com/vintage/vintage-magazine-porn.html vintage magazine porn where get http://mazzzer.memebot.com/vintage/vintage-mature-sex.html vintage mature sex info ?for more info click to http://mazzzer.memebot.com/vintage/vintage-lesbian-sex.html vintage lesbian sex o -- [[wwe]] &new{2007-03-07 (水) 03:04:20};
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}