設定 Howto/Configuration Howto

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
  • コード規約
  • ビルドの結果


  • 設定ファイル/The configuration files

    Note You should read the Getting Started guide first.

    Note まず最初に、 さあ始めようのガイドをご覧ください。

    Here are the configuration files used by Cactus :

    Cactus で使用される設定ファイルは次の通りです :

    Configuration files

    There are two kind of configuration files :

    2 種類の設定ファイルがあります :

    クライアント側設定ファイル/Client side configuration files

    cactus.properties

    The cactus.properties file contains several configuration properties for Cactus.

    cactus.properties ファイルには、 Cactus の設定プロパティが幾つかあります。

    Here are the properties that you can set in cactus.properties :

    cactus.properties で設定できるプロパティは次の通りです :

    Property Name   Example cactus.contextURL  
    Description   Webapp Context under which the application to test runs.  
    Example   cactus.contextURL = http://localhost:8080/test  
    プロパティ名   cactus.contextURL  
    説明   テストすべきアプリケーションが実行されるウェブアプリケーションのコンテキスト  
      cactus.contextURL = http://localhost:8080/test  


    Property Name   cactus.servletRedirectorName  
    Description   Name of the Cactus Servlet Redirector as it is mapped on the server side in web.xml (see below). This property is needed only if your test classes are extending ServletTestCase (see the TestCase Howto tutorial).  
    Example   cactus.servletRedirectorName = ServletRedirector  
    プロパティ名   cactus.servletRedirectorName  
    説明   サーバ側の web.xml ファイルにおいてマップされる Cactus サーブレットリダイレクタの名前。(下を参照) 自分のテストクラスが ServletTestCase を拡張したものである時、 このプロパティは必要です。 (テストケース Howto のチュートリアルをご覧ください)  
      cactus.servletRedirectorName = ServletRedirector  


    Property Name   cactus.jspRedirectorName  
    Description   Name of the Cactus JSP Redirector as it is mapped on the server side in web.xml (see below). This property is needed only if your test classes are extending JspTestCase (see the TestCase Howto tutorial).  
    Example   cactus.jspRedirectorName = JspRedirector  
    プロパティ名   cactus.jspRedirectorName  
    説明   サーバ側の web.xml ファイルにおいてマップされる Cactus JSP リダイレクトの名前。(下を参照) 自分のテストクラスが JspTestClassを拡張したものである時、 このプロパティは必要です。 (テストケース Howto のチュートリアルをご覧ください)  
      cactus.jspRedirectorName = JspRedirector  


    Property Name   cactus.filterRedirectorName (For J2EE API 1.3 only)  
    Description   Name of the Cactus Filter Redirector as it is mapped on the server side in web.xml (see below). This property is needed only if your test classes are extending FilterTestCase (see the TestCase Howto tutorial).  
    Example   cactus.filterRedirectorName = FilterRedirector  
    プロパティ名   cactus.filterRedirectorName (J2EE API 1.3 のみ対応)  
    説明   サーバ側の web.xml ファイルにおいてマップされる Cactus フィルターリダイレクタの名前。(下を参照) 自分のテストクラスが FilterTestClassを拡張したものである時、 このプロパティは必要です。 (テストケース Howto のチュートリアルをご覧ください)  
      cactus.filterRedirectorName = FilterRedirector  


    Property Name   cactus.enableLogging  
    Description   If set to "true" Cactus internal logging is enabled. Note that you will also need log4j.jar in your classpath to activate logging. If not specified or set to a value different than "true", Cactus logging is disabled.  
    Example   cactus.enableLogging = true  
    プロパティ名   cactus.enableLogging  
    説明   "true" に設定した場合、 Cactus の内部ロギングが可能になります。 ロギングを有効にするにはクラスパスに log4j.jar も加える必要があることに注意してください。 指定されなかったり、値が "true" 以外の値であった場合、 ロギングは無効になります。  
      cactus.enableLogging = true  

    Sample cactus.properties file :

    cactus.properties サンプルファイル :

    # Configuration file for Cactus.
    # Cactus の設定ファイル
    
    # Each project using Cactus need to have such a file put in the client side
    # CLASSPATH (Meaning the directory containgin this file should be in the client
    # side CLASSPATH, not the file itself of course ... :) )
    # Cactus を使用している個々のプロジェクトはクライアント側のクラスパスに
    # このようなファイルを置かなければならなりません。(これは、このファイルがある
    # ディレクトリはクライアント側のクラスパスであるという意味で、
    # ファイル自身をクラスパスに入れるという意味ではありません)
    
    # Defines the URLs that will be used by Cactus to call it's redirectors.
    # You need to specify in these URLs the webapp context that you use for your
    # application. In the example below, the context is "test".
    # リダイレクタが呼び出せるよう Cactus で使われる URL を定義します。
    # これらの URL において、アプリケーションうウェブアプリケーション
    # コンテキストを指定しなければなりません。
    
    # Web app Context under which our application to test runs
    # テストすべきアプリケーションが実行されるウェブアプリケーションコンテキスト
    cactus.contextURL = http://localhost:@test.port@/test
    
    # Default Servlet Redirector Name. Used by ServletTestCase test cases.
    # デフォルトのサーブレットリダイレクタ名
    # ServletTestCase テストケースで使われます
    cactus.servletRedirectorName = ServletRedirector
    
    # Default JSP Redirector Name. Used by JspTestCase test cases.
    # デフォルトの JSP リダイレクタ名。JspTestCase テストケースで使われます
    cactus.jspRedirectorName = JspRedirector
    
    # Default Filter Redirector Name. Used by FilterTestCase test cases.
    # デフォルトのフィルターリダイレクタ名。
    # FilterTestCase テストケースで使われます
    cactus.filterRedirectorName = FilterRedirector
    
    # Enable Cactus internal logging
    # Cactus の内部ロギングを有効にします。
    #cactus.enableLogging = true
    

    There are 2 ways to tell Cactus where cactus.properties is located.

    Cactus に cactus.properties の位置を指定する方法は 2 つあります。

    • The preferred mechanism is to put it in the client side classpath (i.e. have a CLASSPATH entry that points to the directory where it is located).
    • 推奨する方法は、これをクライアント側のクラスパスに置くことです。 (即ち、これが置かれたディレクトリを指す項目を CLASSPATH に持たせる事です)
    • The other option is to pass a command line parameter when starting your JVM. See the Command line section below.
    • もう一つの方法は、JVM 起動時にコマンドラインパラメータを送るというものです。 下の コマンドラインの節 をご覧ください。

    log_client.properties

    A default log_client.properties is already provided in the cactus.jar jar. It is used for configuring Log4j, which is the logging framework used by Cactus to log debug information.

    デフォルトの log_client.properties は、 既に cactus.jar jar ファイルの中で提供されています。 これは、 Cactus がデバッグ情報をログ出力するのに使われるロギングフレームワークである Log4j を設定するのに使われます。

    If the Log4j jar is not present on the client side classpath, Cactus will not log anything. In addition you need to explicitely tell Cactus to perform logging (if that's what you want). This can be achieved in 2 ways :

    Log4j の jar ファイルがクライアント側のクラスパスに無い場合、 Cactus は何もログ出力しません。 加えて、(それが必要ならば) Cactus がロギングを行うよう明白に指示する必要があります。これを行うには 2 つの方法があります :

    • By having a cactus.enableLogging = true property in your cactus.properties file (as described above),
    • (先に述べたように) cactus.properties ファイルにおいて、 cactus.enableLogging = true プロパティを持たせることにより
    • By passing a property on the Java command line when starting the JVM. See the Command line section.
    • JVM を起動する時に、コマンドラインのプロパティとして渡すことにより。 Command コマンドラインの節 を見てください。

    The default log_client.properties is :

    デフォルトの log_client.properties は次の通りです :

    # Properties for configuring Log4j
    # Log4j を設定するためのプロパティ
    # This is the configuring for logging on the JUnit side (i.e. the client side)
    # これは JUnit 側(即ちクライアント側)のロギング設定です。
    
    log4j.appender.cactus = org.apache.log4j.FileAppender
    log4j.appender.cactus.File = cactus_client.log
    log4j.appender.cactus.Append = false
    log4j.appender.cactus.layout = org.apache.log4j.PatternLayout
    log4j.appender.cactus.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n
    
    # Any application log which uses Log4J will be logged to the Cactus log file
    # Log4j を使ったどんなアプリケーションログでも Cactus ログファイルに
    # 出力されます
    log4j.rootCategory=DEBUG, cactus
    
    # By default we don't log at the DEBUG level for Cactus log, in order not to generate too
    # many logs. However, should a problem arise and logs need to be sent to the Cactus dev team,
    # then we will ask you to change this to DEBUG.
    # デフォルトでは、ログを大量に出力しすぎないように、
    # Cactus ログをデバッグレベルで出力しません。
    # しかしながら、問題の発生とログは Cactus 開発チームに送られなければ
    # なりません。
    log4j.category.org.apache.cactus = WARN, cactus
    log4j.additivity.org.apache.cactus=false
    

    If you want to understand how to configure Log4j, go to the Log4j web site.

    Log4j の設定法を理解したい場合には、 Log4j ウェブサイトを参照してください。

    If you wish to define another file name and location or other logging parameter, just provide your own log_client.properties file (it has to be named this way) and put in the client side classpath before the cactus.jar file.

    別のファイル名や保存場所やログパラメーターを定義したい場合には、 自分の log_client.properties ファイル (このような方法で名前を付けられるべきです) を提供し、 クライアント側クラスパス中の cactus.jarファイルよりも前の場所に置くだけです。


    コマンドラインパラメータ/Command line parameters

    Note Command line parameters are purely optional and should only be used for very specific cases where the preferred method cannot be used (the preffered method is through cactus.properties).

    Note コマンドラインパラメータは純粋にオプションであり、 推奨される方法が使えない場合といった、 とても特別な場合にのみ使われるべきです。 (推奨される方法とはcactus.propertiesによるものです)

    The following command line properties can be passed on the java command line :

    次のコマンドラインプロパティが java のコマンドラインに渡されます :

    Property Name   cactus.enableLogging  
    Description   If set to "true" Cactus internal logging is enabled. Note that you will also need log4j.jar in your classpath to activate logging. If not specified or set to a value different than "true", Cactus logging is disabled.  
    Example   -Dcactus.enableLogging=true  
    プロパティ名   cactus.enableLogging  
    説明   "true" に設定した場合、 Cactus の内部ロギングが可能になります。 ロギングを有効にするにはクラスパスに log4j.jar も加える必要があることに注意してください。 指定されなかったり、値が "true" 以外の値であった場合、 ロギングは無効になります。  
      -Dcactus.enableLogging=true  


    Property Name   cactus.config  
    Description   Specify where to find the Cactus configuration file. By default Cactus looks for a cactus.properties file in the classpath. This property overrides this behaviour.  
    Example   -Dcactus.config=conf/mycactus.properties  
    プロパティ名   cactus.config  
    説明   Cactus 設定ファイルの検索場所を指定します。 デフォルトでは、Cactus は、クラスパス中の cactus.properties ファイルを探します。 本プロパティは、この振舞いを上書きします。  
      -Dcactus.config=conf/mycactus.properties  


    サーバ側設定ファイル/Server side configuration files

    cactus.properties

    First and foremost, this file is completely optional on the server side (whereas it is mandatory on the client side). It is only used to turn on Cactus internal logging on the server side.

    まず最初に最も重要な事は、 このファイルは (クライアント側では義務であるにもかかわらず) サーバ側では完全にオプションであるということです。 これは、サーバ側の Cactus の内部ロギングを有効にするのにのみ使われます。

    Note Please note that Cactus logging on the server side can also be turned on by using a java command line property (see the command line section below).

    Note サーバ側の Cactus のロギングは、 java のコマンドラインプロパティを使っても有効にできることに注意してください。 (下のコマンドラインの節を見てください。)

    Here are the properties that you can set in cactus.properties :

    cactus.properties で設定できるプロパティは次の通りです :

    Property Name   cactus.enableLogging  
    Description   If set to "true" Cactus internal logging is enabled. Note that you will also need log4j.jar in your classpath to activate logging. If not specified or set to a value different than "true", Cactus logging is disabled.  
    Example   cactus.enableLogging = true  
    プロパティ名   cactus.enableLogging  
    説明   "true" に設定した場合、 Cactus の内部ロギングが可能になります。 ロギングを有効にするにはクラスパスに log4j.jar も加える必要があることに注意してください。 指定されなかったり、値が "true" 以外の値であった場合、 ロギングは無効になります。  
      cactus.enableLogging = true  

    Location of cactus.properties works in the same way as on the client side.

    cactus.properties の位置は、 クライアント側と同じ方法で動作します。


    web.xml

    Your server side tests are packaged as a web application (either expanded or as .war file) and thus you need to have a web.xml file to configure your test web application.

    自分のサーバ側テストがウェブアプリケーションとして (展開されたもの、あるいは .war ファイルとして)パッケージ化たら、 自分のテストウェブアプリケーションを設定するために web.xml ファイルを置かなければなりません。

    Note If your servlet engine does not support web applications, it won't support a web.xml file. You'll need to edit your servlet engine proprietary configuration file and find out out to map a Servlet, JSP or Filter to a URL.

    Note 使っているサーブレットエンジンがウェブアプリケーションをサポートしていない場合、 web.xml ファイルをサポートしていないでしょう。 使っているサーブレットエンジンのプロパティ設定ファイルを編集したり、 サーブレット、JSP、フィルターから URL へのマッピングを見つけなければなりません。

    You need to register the Cactus Redirectors that you use (see How it works if you don't know what a Cactus Redirector is).

    使っている Cactus リダイレクタを登録する必要があります。 (Cactus リダイレクタとは何か知らない場合には、 Cactus の仕組みを見てください)

    For example, in order to match the sample cactus.properties file defined above, we'll need to name our web application "test" and write our web.xml in the following way :

    例として、上で定義した cactus.properties ファイルにマッチするように、 自分のウェブアプリケーションを "test" と名づけ、 web.xml ファイルを次のような方法で記述する必要があります :

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
    
    <web-app>
    
        <filter>
            <filter-name>FilterRedirector</filter-name>
            <filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>FilterRedirector</filter-name>
            <url-pattern>/FilterRedirector</url-pattern>
        </filter-mapping>
    
        <servlet>
            <servlet-name>ServletRedirector</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>ServletRedirector</servlet-name>
            <url-pattern>/ServletRedirector</url-pattern>
        </servlet-mapping>
    
        <servlet-mapping>
            <servlet-name>JspRedirector</servlet-name>
            <url-pattern>/JspRedirector</url-pattern>
        </servlet-mapping>
    
    </web-app>
    

    Note If you are using the JSP Redirector (i.e. you have test classes that extend JspTestCase), you must copy the jspRedirector.jsp file (found in the sample/web directory where you unpacked your Cactus distribution) in a directory in your webapp and you need to put it's relative path in the mapping defined above (here we have put it in the webapp root.

    Note JSP リダイレクタ(即ち JspTestCaseを拡張したテストクラス)がある場合、 (Cactus ディストリビューションを解凍した sample/webディレクトリにある) jspRedirector.jspファイルを webapp の下にあるディレクトリに置き、その相対パスを上で定義したマッピングに設定しなければなりません。 (ここでは、それを webapp のルートに置きました)

    If you want to provide some initialisation parameters that will be available to the config implicit object available in your test case, simply use the standard <init-param> tags.

    自分のテストケースで使われる config 暗黙オブジェクトで利用可能な初期化パラメーターを幾つか提供したい場合には、 単に標準の<init-param>タグを使えばよいのです。

    For example, for the Servlet Redirector (same principle applies to all other redirectors) :

    例えば、サーブレットリダイレクタの場合次のようになります (他のリダイレクタに対しても同じ原則があてはまります) :

    [...]
        <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>
    [...]
    

    Note Within your testXXX() code, you can also call the config.setInitParameter() method (config being the implicit object of type ServletConfig) to simulate initialisation parameters as if they had been defined in your web.xml.

    Note testXXX() コード中で、 web.xmlで定義されていたような初期化パラメータをシミュレートするために、 config.setInitParameter() メソッド(ServletConfig型のconfig暗黙オブジェクトであるconfig)を呼び出せます。

    Lastly, if you need to unit test code that uses the Servlet Security API, please check the Security Howto.

    最後に、Servlet Security API を使った単体テストコードが必要な場合には、セキュリティHowtoを参照してください。


    log_server.properties

    It works in the same way as for the client side.

    クライアント側と同じ方法で動作します。

    The default log_server.properties is :

    デフォルトlog_server.propertiesは次の通りです :

    # Properties for configuring Log4j
    # Log4j 設定のためのプロパティ
    # This is the configuring for logging on the server side
    # これはサーバ側のロギング設定です。
    
    log4j.appender.cactus = org.apache.log4j.FileAppender
    log4j.appender.cactus.File = cactus_server.log
    log4j.appender.cactus.Append = false
    log4j.appender.cactus.layout = org.apache.log4j.PatternLayout
    log4j.appender.cactus.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n
    
    # Any application log which uses Log4J will be logged to the Cactus log file
    # Log4j を使ったどんなアプリケーションログでも Cactus ログファイルに
    # 出力されます
    log4j.rootCategory=DEBUG, cactus
    
    # By default we don't log at the DEBUG level for Cactus log, in order not to generate too
    # many logs. However, should a problem arise and logs need to be sent to the Cactus dev team,
    # then we will ask you to change this to DEBUG.
    # デフォルトでは、ログを大量に出力しすぎないように、
    # Cactus ログをデバッグレベルで出力しません。
    # しかしながら、問題の発生とログは Cactus 開発チームに送られなければ
    # なりません。
    log4j.category.org.apache.cactus = WARN, cactus
    log4j.additivity.org.apache.cactus=false
    

    If you wish to define another file name and location or other logging parameter, just provide your own log_server.properties file (it has to be named this way) and put in the WEB-INF/classes directory of your webapp (and hope that the webapp classloader of your server picks up the files in WEB-INF/classes before the ones in WEB-INF/lib, where cactus.jar is located ... :) I don't know if this is part of the specification). Alternatively, edit the file in cactus.jar !

    別のファイル名や保存場所やログパラメーターを定義したい場合には、 自分の log_server.properties ファイル (このような方法で名前を付けられるべきです) を提供し、 自分の webapp の WEB-INF/classes ディレクトリに置くだけです。 (サーバーの webapp クラスローダーが、 cactus.jar のある WEB-INF/lib のファイルよりも前に、 WEB-INF/classes からファイルを取り出すことを期待します ... :) これが仕様の一部なのかはわかりません) 別な方法としては、cactus.jar の中のファイルを編集します。


    コマンドラインパラメータ/Command line parameters

    Command line parameters on the server side are exactly the same as on the client side. in order to use them you'll have to modify the startup script of your container and add your properties to it.

    サーバ側のコマンドラインパラメータはクライアント側と全く同じです。 それを使うには、 使っているコンテナの起動スクリプトを変更し、 それにプロパティを加える必要があります。

    Again, please bear in mind that this is completely optional and that the preferred method is by using cactus.properties.

    繰り返しになりますが、これは完全にオプションであり、 推奨される方法はcactus.propertiesを使ったものであるということを心に留めておいてください。






    Copyright © 2000-2002 The Apache Software Foundation. All Rights Reserved.