第4章 XML ルールのテスト
XML ルールを作成したら、テストルールを作成して、そのルールが機能するようにする必要があります。
4.1. テストルールの作成
テストルールは、以下の違いで、テストルールを作成するプロセスを使用して作成されます。
-
テストルールは、テストするルールの下にある
tests/ディレクトリーに置く必要があります。 -
テストクラスなどのデータは、
tests/ディレクトリーの下のdata/ディレクトリーに配置する必要があります。 -
テストルールは、
.mta.test.xmlエクステンションを使用する必要があります。 - これらのルールは、Test XML Rule Structure で定義された構造を使用します。
さらに、テストするルールの名前に続くテストルールを作成することが推奨されます。たとえば、ファイル名 proprietary-rule.mta.xml でルールを作成した場合、テストルールは proprietary-rule.mta.test.xml と呼ばれます。
4.1.1. XML ルール構造のテスト
すべてのテスト XML ルールは、1 つ以上のルールセット rulesets を含む ruletests 内の要素として定義されます。詳細は、MTA XML rule schema を参照してください。
ルールテストは、移行の特定の領域を対象とする 1 つ以上のテストのグループです。これは <ruletest> 要素の基本構造です。
<ruletest id="<RULE_TOPIC>-test">: 一意の MTA ルールテストとして定義し、固有のルールテスト ID を提供します。-
<testDataPath>: テストに使用するクラスやファイルなどのデータへのパスを定義します。 -
<sourceMode>: データで渡されたにソースファイルのみが含まれるかどうかを示します。EAR、WAR、JAR などのアーカイブが使用されている場合は、falseに設定する必要があります。デフォルトはtrueです。 -
<rulePath>: テストされるルールへのパス。これは、テストするルールの名前で終了します。 -
<ruleset>: テストケースのロジックが含まれるルールセット。これらは Ruleset で定義されるものと同じです。
-
4.1.2. XML ルール構文のテスト
標準の XML ルール構文のタグに加え、以下の when 条件がテストルールの作成に一般的に使用されます。
-
<not> -
<iterable-filter> -
<classification-exists> -
<hint-exists>
標準 perform action 構文のタグのほかに、以下の perform 条件がテストルールのアクションとして一般的に使用されます。
-
<fail>
4.1.2.1. <not> 構文
概要
<not> 要素は標準の論理演算子 not で 、通常は条件を満たさない場合に <fail> を実行するために使用されます。
以下は、分析の最後に特定のメッセージのみが存在する場合に失敗したテストルールの例です。
<ruletest xmlns="http://windup.jboss.org/schema/jboss-ruleset"
id="proprietary-servlet-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/</testDataPath>
<rulePath>../proprietary-servlet.mta.xml</rulePath>
<ruleset>
<rules>
<rule id="proprietary-servlet-01000-test">
<when>
<!--
The <not> will perform a logical not operator on the elements within.
-->
<not>
<!--
The defined <iterable-filter> has a size of 1. This rule will only match on a single instance of the defined hint.
-->
<iterable-filter size="1">
<hint-exists message="Replace the proprietary @ProprietaryServlet annotation with the Java EE 7 standard @WebServlet annotation*" />
</iterable-filter>
</not>
</when>
<!--
This <perform> element is only executed if the previous <when> condition is false.
This ensures that it only executes if there is not a single instance of the defined hint.
-->
<perform>
<fail message="Hint for @ProprietaryServlet was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
<not> 要素には固有の属性や子要素がありません。
4.1.2.2. <iterable-filter> 構文
概要
<iterable-filter> 要素は、条件の検証回数をカウントします。詳細は、IterableFilter クラスを参照してください。
以下は、指定のメッセージの 4 つのインスタンスを検索する例です。
<ruletest xmlns="http://windup.jboss.org/schema/jboss-ruleset"
id="proprietary-servlet-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/</testDataPath>
<rulePath>../proprietary-servlet.mta.xml</rulePath>
<ruleset>
<rules>
<rule id="proprietary-servlet-03000-test">
<when>
<!--
The <not> will perform a logical not operator on the elements within.
-->
<not>
<!--
The defined <iterable-filter> has a size of 4. This rule will only match on four instances of the defined hint.
-->
<iterable-filter size="4">
<hint-exists message="Replace the proprietary @ProprietaryInitParam annotation with the Java EE 7 standard @WebInitParam annotation*" />
</iterable-filter>
</not>
</when>
<!--
This <perform> element is only executed if the previous <when> condition is false.
In this configuration, it only executes if there are not four instances of the defined hint.
-->
<perform>
<fail message="Hint for @ProprietaryInitParam was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
<iterable-filter> 要素には一意の子要素がありません。
<iterable-filter> 要素属性
| 属性名 | タイプ | 説明 |
|---|---|---|
| size | integer | 検証される回数。 |
4.1.2.3. <classification-exists> 構文
<classification-exists> 要素は、分析に特定の分類タイトルが含まれているかどうかを判断します。詳細は、ClassificationExists クラスを参照してください。
特殊文字 ([、' など) が含まれるメッセージをテストする場合は、各特殊文字をバックスラッシュ (\) でエスケープして正しく一致させる必要があります。
以下は、特定の分類タイトルを検索する例です。
<ruletest xmlns="http://windup.jboss.org/schema/jboss-ruleset"
id="proprietary-servlet-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/</testDataPath>
<rulePath>../weblogic.mta.xml</rulePath>
<ruleset>
<rules>
<rule id="weblogic-01000-test">
<when>
<!--
The <not> will perform a logical not operator on the elements within.
-->
<not>
<!--
The defined <classification-exists> is attempting to match on the defined title.
This classification would have been generated by a matching <classification title="WebLogic scheduled job" .../> rule.
-->
<classification-exists classification="WebLogic scheduled job" />
</not>
</when>
<!--
This <perform> element is only executed if the previous <when> condition is false.
In this configuration, it only executes if there is not a matching classification.
-->
<perform>
<fail message="Triggerable not found" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
<classification-exists> には一意の子要素がありません。
<classification-exists> 要素属性
| 属性名 | タイプ | 説明 |
|---|---|---|
| classification | String |
検索する |
| in | String | 定義されたファイル名が含まれるファイルに一致することを制限する任意の引数。 |
4.1.2.4. <hint-exists> 構文
<hint-exists> 要素は、分析に特定のヒントが含まれているかどうかを判断します。これは定義されたメッセージのインスタンスをすべて検索し、通常は <message> 要素内の開始または特定のクラスを検索するために使用されます。詳細は、HintExists クラスを参照してください。
特殊文字 ([、' など) が含まれるメッセージをテストする場合は、各特殊文字をバックスラッシュ (\) でエスケープして正しく一致させる必要があります。
以下は、特定のヒントを検索する例です。
<ruletest xmlns="http://windup.jboss.org/schema/jboss-ruleset"
id="proprietary-servlet-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/</testDataPath>
<rulePath>../weblogic.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="weblogic-eap7-05000-test">
<when>
<!--
The <not> will perform a logical not operator on the elements within.
-->
<not>
<!--
The defined <hint-exists> is attempting to match on the defined message.
This message would have been generated by a matching <message> element on the <hint> condition.
-->
<hint-exists message="Replace with the Java EE standard method .javax\.transaction\.TransactionManager\.resume\(Transaction tx\)." />
</not>
</when>
<!--
This <perform> element is only executed if the previous <when> condition is false.
In this configuration, it only executes if there is not a matching hint.
-->
<perform>
<fail message="Note to replace with standard TransactionManager.resume is missing!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
<hint-exists> 要素には固有の子要素がありません。
<hint-exists> 要素属性
| 属性名 | タイプ | 説明 |
|---|---|---|
| message | String |
検索する |
| in | String |
指定のファイル名を参照する |
4.1.2.5. <fail> 構文
<fail> 要素は実行を失敗として報告し、関連するメッセージを表示します。通常、これは、条件が満たされない場合のみメッセージを表示するために <not> 条件とともに使用されます。
<fail> 要素には、一意の子要素がありません。
<fail> 要素属性
| 属性名 | タイプ | 説明 |
|---|---|---|
| message | String | 表示されるメッセージ。 |