Cactus のサンプルを JBoss 3.2.0 (Beta) に対して実行できるようにしてみました。
かなり強引になんとかテストを行ってパスしてくれるところまでにしたので、もっと Smart な/まともなやり方がきっとあると思いますし、間違っているところもあると思います。とりあえずの現状、ということでご参考にしてください。もしもっとよい方法がある場合はぜひご教示ください。
そのままの Cactus 付属のサンプルには JBoss に対してのスクリプトは用意されていません。いろいろなものを参考にして、つぎはぎして作ってみました。
まず最初に build.xml に対して以下の太字のような追加を行います。
build.xml は、目的別の build ファイルをインクルードしているだけです。
サンプルアプリケーションのコンパイルなど共通の作業は build-share.xml で行い、テスト対象のアプリケーション・サーバーの開始や終了、サンプルアプリケーションの配置などはそれぞれ異なるため、個別の
build ファイルにしています。
そこでそのお作法に則って JBoss 用のスクリプトを新しく作って定義しているわけです。
| <?xml version="1.0"?> <!DOCTYPE project [ <!ENTITY build-share SYSTEM "file:./build-share.xml"> <!ENTITY build-tests-resin-20 SYSTEM "file:./build-tests-resin-20.xml"> <!ENTITY build-tests-resin-13 SYSTEM "file:./build-tests-resin-13.xml"> <!ENTITY build-tests-orion-14 SYSTEM "file:./build-tests-orion-14.xml"> <!ENTITY build-tests-orion-15 SYSTEM "file:./build-tests-orion-15.xml"> <!ENTITY build-tests-orion-16 SYSTEM "file:./build-tests-orion-16.xml"> <!ENTITY build-tests-tomcat-40 SYSTEM "file:./build-tests-tomcat-40.xml"> <!ENTITY build-tests-weblogic-61 SYSTEM "file:./build-tests-weblogic-61.xml"> <!ENTITY build-tests-weblogic-70 SYSTEM "file:./build-tests-weblogic-70.xml"> <!ENTITY build-tests-jboss-320 SYSTEM "file:./build-tests-jboss-320.xml"> ]> <!-- ======================================================================== Run all Cactus tests for Servlet API 2.3 ======================================================================== --> <target name="test.all" depends="test.resin.20,test.resin.13,test.tomcat.40,test.orion.14,test.orion.15,test.orion.16,test.weblogic.61,test.weblogic.70,test.jboss.320" description="Run tests on all defined containers"> </target> &build-tests-resin-20; &build-tests-resin-13; &build-tests-orion-14; &build-tests-orion-15; &build-tests-orion-16; &build-tests-tomcat-40; &build-tests-weblogic-61; &build-tests-weblogic-70; &build-tests-jboss-320; </project> |
次に build-share.xml に対しての変更です。
JBoss 側に httpunit のクラスが存在している必要があるため、Web アプリケーションの
WEB-INF/lib に httpunit.jar をコピーさせるようにします。
後の JBoss 用のスクリプトでも可能ですし、実際には重複して行ってしまっているのですが、ここで実行した方が簡単なため、そうしています。
<property file="build/build.properties" />
<property file="${user.home}/build.properties" />
<property name="base.dir" value="."/>
<!--
========================================================================
Set the properties related to the source tree.
========================================================================
-->
<property name="src.dir" value="${base.dir}/src"/>
<property name="src.sample.dir" value="${src.dir}/sample"/>
<property name="src.unit.dir" value="${src.dir}/unit"/>
<property name="build.dir" value="${base.dir}/build"/>
<property name="conf.dir" value="${base.dir}/conf"/>
<property name="conf.test.dir" value="${conf.dir}/test"/>
<property name="web.dir" value="${base.dir}/web"/>
<!--
========================================================================
Set the properties related to the target area
========================================================================
-->
<!-- Destination locations for the build -->
<property name="target.dir" value="${base.dir}/target"/>
<property name="target.classes.dir" value="${target.dir}/classes"/>
<property name="target.classes.sample.dir"
value="${target.classes.dir}/sample"/>
<property name="target.classes.unit.dir"
value="${target.classes.dir}/unit"/>
<property name="target.conf.dir" value="${target.dir}/conf"/>
<property name="target.conf.client.dir" value="${target.conf.dir}/client"/>
<property name="target.conf.server.dir" value="${target.conf.dir}/server"/>
<property name="target.doc.dir" value="${target.dir}/doc"/>
<property name="target.doc.api.dir" value="${target.doc.dir}/api"/>
<property name="target.test.dir" value="${target.dir}/test"/>
<property name="target.lib.dir" value="${target.dir}/lib"/>
<target name="testwar"
depends="compile,prepare.testwar.log4j,prepare.testwar.clover,prepare.test">
<!-- Gather libraries in a place where they can be copied in the
war. Note: We don't copy the version information in the jar as
it has some "." in the name (ex: clover-0.6b.jar) and WebLogic
7.0 has a bug and ignore jars with dots in the name! Will be fixed
in a upcoming patch as it has been fixed in WL 6.1 SP3 -->
<copy tofile="${target.lib.dir}/junit.jar" file="${junit.jar}"/>
<copy tofile="${target.lib.dir}/cactus.jar" file="${cactus.framework.jar}"/>
<copy tofile="${target.lib.dir}/aspectjrt.jar" file="${aspectjrt.jar}"/>
<copy tofile="${target.lib.dir}/commons-logging.jar" file="${commons.logging.jar}"/>
<!-- Next line is included for JBOSS support
Testcase: testHttpUnitGetText would fail without this -->
<copy tofile="${target.lib.dir}/httpunit.jar" file="${httpunit.jar}"/>
<!-- Copy the log4j server configuration file in order to change its
name to log4j.properties (the default name for Log4j) -->
<copy tofile="${target.conf.server.dir}/log4j.properties"
file="${conf.test.dir}/log_server.properties"/>
<!-- Make sure the directory for the war exist -->
<mkdir dir="${target.test.dir}"/>
<!-- Create the war file -->
<war warfile="${target.test.dir}/test.war"
webxml="${conf.test.dir}/web.xml">
<classes dir="${target.classes.sample.dir}"/>
<classes dir="${target.classes.unit.dir}"/>
<!-- log_server.properties need to be in the server classpath -->
<classes dir="${target.conf.server.dir}">
<include name="log4j.properties"/>
</classes>
<!-- We need to copy all dependent jar in the war. This is
because if we just put these jars in the global classpath for
the Servlet engine, the Cactus jar might not be able to load
the test case class as it may be loadable only by the war
classloader -->
<lib dir="${target.lib.dir}"/>
<fileset dir="${web.dir}"/>
</war>
</target>
sample-servlet/conf/test/jboss320 というディレクトリを作成します。
他のサーバー用のスクリプトでも、/sample-servlet/conf/test/サーバーの種類名
というディレクトリに、各サーバー固有に必要なファイルなどを格納しておいてコピーするようにしています。
ここでもお作法に則って、同様にしました。
用意する JBoss 固有のファイルは jboss-web.xml、users.properties、roles.properties
の 3つです。
それぞれの働きについては、以前の「JMX-Console のセキュア化」や「JBoss の Web セキュリティの仕組み」についての記事をご参照ください。

login-config.xml の "other" という Application-Policy を参照するように jboss-web.xml を設定しています。

roles.properties です。
「admin=JBossAdmin」は参考のために入れてあるだけで、必要なものではありません。

users.properties です。
こちらも「admin=admin」は参考のために入れてあるだけで、必要なものではありません。

sample-servlet/conf/test/web.xml にも以下の一行を足しました。これがないと「Realm not configured」といったかんじのメッセージが出てきてしまい、Web アプリケーションのセキュリティが正しく設定されません。

こちらが新しく作成した JBoss 3.2.0 用の build ファイルです。
試行錯誤を結構しているので、もうほとんど意味のない部分がありますが、それも何かの情報になるかと思って残してあります。
<property name="run.bin.dir" value="${jboss.home.320}/bin" />
<property name="run.jboss.flags" value="-c default"/>
<property name="stop.jboss.flags" value="-S"/>
<!--
========================================================================
Run JBOSS 3.2.0 tests
========================================================================
-->
<target name="test.jboss.320" depends="prepare.test.jboss.320"
if="jboss.home.320" description="Run tests on JBOSS 3.2.0">
<!-- Start the servlet engine, wait for it to be started, run the
unit tests, stop the servlet engine, wait for it to be stopped.
The servlet engine is stopped if the tests fail for any reason -->
<runservertests
testURL="http://localhost:${test.port}/test/ServletRedirector?Cactus_Service=RUN_TEST"
startTarget="start.jboss.320"
stopTarget="stop.jboss.320"
testTarget="test"/>
</target>
<!-- target name="run-jboss-win32" -->
<target name="start.jboss.320">
<echo message="run.home.dir=${jboss.home.320}"/>
<echo>Starting JBoss</echo>
<exec executable="${run.bin.dir}/run.bat"
dir="${jboss.home.320}"
newenvironment="true">
<arg line="${run.jboss.flags}"/>
</exec>
</target>
<target name="run-jboss-java-320">
<echo message="run.home.dir=${jboss.home.320}"/>
<echo>Starting JBoss</echo>
<java classname="org.jboss.Main" fork="yes">
<jvmarg value="-Dprogram.name=${run.bin.dir}/run.bat"/>
<classpath>
<pathelement path="${classpath}"/>
<pathelement path="${java.home}/lib/tools.jar"/>
<pathelement path="${jboss.home.320}/bin/run.jar"/>
<fileset dir="${jboss.home.320}">
<include name="lib/*.jar"/>
</fileset>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<!-- target name="stop-jboss-win32" -->
<target name="stop.jboss.320">
<echo>Stopping JBoss</echo>
<exec executable="${run.bin.dir}/shutdown.bat"
dir="${jboss.home.320}">
<arg line="${stop.jboss.flags}"/>
</exec>
</target>
<target name="stop-jboss-java-320">
<!-- shutdown the server -->
<echo>Stopping JBoss</echo>
<java classname="org.jboss.Shutdown">
<classpath>
<pathelement location="${run.bin.dir}/shutdown.jar"/>
</classpath>
<arg value="localhost"/>
<arg value="8080"/>
</java>
</target>
<!--
========================================================================
Prepare directories and variables for running the tests
========================================================================
-->
<target name="prepare.test.jboss.320"
depends="check.test.jboss.320,testwar" if="jboss.home.320">
<echo message="jboss.home.320 = ${jboss.home.320}"/>
<property name="target.jboss320.dir"
value="${target.test.dir}/jboss320"/>
<property name="conf.jboss320.dir" value="${conf.test.dir}/jboss320"/>
<!-- Create work and conf directories and copy configuration files -->
<mkdir dir="${target.jboss320.dir}/server/default/conf"/>
<mkdir dir="${target.jboss320.dir}/server/default/deploy"/>
<!-- Delete some config file so that they will be copied every time -->
<!-- delete file="${target.jboss320.dir}/server/default/conf/xxxx.xml"/ -->
<!-- Remove the auto deployed webapp so that it is redeployed every
time -->
<delete dir="${target.jboss320.dir}/server/default/deploy/test"/>
<delete file="${target.jboss320.dir}/server/default/deploy/test.war"/>
<delete file="${jboss.home.320}/server/default/deploy/test.war"/>
<!-- copy todir="${target.jboss320.dir}/server/default/conf" filtering="on">
<fileset dir="${conf.jboss320.dir}">
<include name="*.properties"/>
</fileset>
</copy -->
<!-- Copy the war file -->
<copy file="${target.test.dir}/test.war"
tofile="${target.jboss320.dir}/server/default/deploy/test.war"/>
<!-- Hack: Make sure jboss-web.xml is always newer than the war so that
the later is always updated. Waiting for an Ant bug fix -->
<touch file="${target.jboss320.dir}/server/default/deploy/test.war"
datetime="06/28/2000 2:02 pm"/>
<war update="true"
destfile="${target.jboss320.dir}/server/default/deploy/test.war">
<webinf dir="${conf.jboss320.dir}">
<include name="jboss-web.xml"/>
</webinf>
<classes dir="${conf.jboss320.dir}">
<include name="*.properties"/>
</classes>
<lib dir="${target.lib.dir}">
<include name="httpunit.jar"/>
</lib>
</war>
<echo message="${target.jboss320.dir}/server/default/deploy/test.war is updated."/>
<!-- Copy the war file to the test server
<copy todir="${jboss.home.320}/server/default/conf" filtering="on">
<fileset dir="${conf.jboss320.dir}"/>
</copy>
-->
<!-- Copy the war file to the test server -->
<copy file="${target.jboss320.dir}/server/default/deploy/test.war"
tofile="${jboss.home.320}/server/default/deploy/test.war"/>
</target>
<!--
========================================================================
Display a warning message if the needed servlet engine home property
is not set
========================================================================
-->
<target name="check.test.jboss.320" unless="jboss.home.320">
<echo message=""/>
<echo message="******************************************************"/>
<echo message="WARNING : The 'jboss.home.320' property has not been"/>
<echo message="set. No test will be run on that servlet engine."/>
<echo message="******************************************************"/>
<echo message=""/>
</target>
と言ってもやはり理解のさまたげになることもあるでしょうから、こちらにいらないところをすべてはぶいたものも載せました。こちらです。
<property name="run.bin.dir" value="${jboss.home.320}/bin" />
<property name="run.jboss.flags" value="-c default"/>
<property name="stop.jboss.flags" value="-S"/>
<!--
========================================================================
Run JBOSS 3.2.0 tests
========================================================================
-->
<target name="test.jboss.320" depends="prepare.test.jboss.320"
if="jboss.home.320" description="Run tests on JBOSS 3.2.0">
<!-- Start the servlet engine, wait for it to be started, run the
unit tests, stop the servlet engine, wait for it to be stopped.
The servlet engine is stopped if the tests fail for any reason -->
<runservertests
testURL="http://localhost:${test.port}/test/ServletRedirector?Cactus_Service=RUN_TEST"
startTarget="start.jboss.320"
stopTarget="stop.jboss.320"
testTarget="test"/>
</target>
<target name="start.jboss.320">
<echo message="run.home.dir=${jboss.home.320}"/>
<echo>Starting JBoss</echo>
<exec executable="${run.bin.dir}/run.bat"
dir="${jboss.home.320}"
newenvironment="true">
<arg line="${run.jboss.flags}"/>
</exec>
</target>
<target name="stop.jboss.320">
<echo>Stopping JBoss</echo>
<exec executable="${run.bin.dir}/shutdown.bat"
dir="${jboss.home.320}">
<arg line="${stop.jboss.flags}"/>
</exec>
</target>
<!--
========================================================================
Prepare directories and variables for running the tests
========================================================================
-->
<target name="prepare.test.jboss.320"
depends="check.test.jboss.320,testwar" if="jboss.home.320">
<echo message="jboss.home.320 = ${jboss.home.320}"/>
<property name="target.jboss320.dir"
value="${target.test.dir}/jboss320"/>
<property name="conf.jboss320.dir" value="${conf.test.dir}/jboss320"/>
<!-- Create work and conf directories and copy configuration files -->
<mkdir dir="${target.jboss320.dir}/server/default/conf"/>
<mkdir dir="${target.jboss320.dir}/server/default/deploy"/>
<!-- Remove the auto deployed webapp so that it is redeployed everytime -->
<delete dir="${target.jboss320.dir}/server/default/deploy/test"/>
<delete file="${target.jboss320.dir}/server/default/deploy/test.war"/>
<delete file="${jboss.home.320}/server/default/deploy/test.war"/>
<!-- copy todir="${target.jboss320.dir}/server/default/conf" filtering="on">
<fileset dir="${conf.jboss320.dir}">
<include name="*.properties"/>
</fileset>
</copy -->
<!-- Copy the war file -->
<copy file="${target.test.dir}/test.war"
tofile="${target.jboss320.dir}/server/default/deploy/test.war"/>
<!-- Hack: Make sure jboss-web.xml is always newer than the war so that
the later is always updated. Waiting for an Ant bug fix -->
<touch file="${target.jboss320.dir}/server/default/deploy/test.war"
datetime="06/28/2000 2:02 pm"/>
<war update="true"
destfile="${target.jboss320.dir}/server/default/deploy/test.war">
<webinf dir="${conf.jboss320.dir}">
<include name="jboss-web.xml"/>
</webinf>
<classes dir="${conf.jboss320.dir}">
<include name="*.properties"/>
</classes>
<lib dir="${target.lib.dir}">
<include name="httpunit.jar"/>
</lib>
</war>
<echo message="${target.jboss320.dir}/server/default/deploy/test.war is updated."/>
<!-- Copy the war file to the test server
<copy todir="${jboss.home.320}/server/default/conf" filtering="on">
<fileset dir="${conf.jboss320.dir}"/>
</copy>
-->
<!-- Copy the war file to the test server -->
<copy file="${target.jboss320.dir}/server/default/deploy/test.war"
tofile="${jboss.home.320}/server/default/deploy/test.war"/>
</target>
<!--
========================================================================
Display a warning message if the needed servlet engine home property
is not set
========================================================================
-->
<target name="check.test.jboss.320" unless="jboss.home.320">
<echo message=""/>
<echo message="******************************************************"/>
<echo message="WARNING : The 'jboss.home.320' property has not been"/>
<echo message="set. No test will be run on that servlet engine."/>
<echo message="******************************************************"/>
<echo message=""/>
</target>
実行例です。
ant test.jboss.320 とコマンドを実行することによって、スクリプトが実行されます。
これは build-tests-jboss-320.xml にあるターゲットの名前ですね。

どのターゲットが実行されているかがわかります。

JBoss の開始です。

JBoss の開始を待ってテストが開始されます。

テストが終了すると、JBoss を終了します。

全部終わって「BUILD SUCCESSFUL」で OK です。

|
|