이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 4. Testing XML rules
After you have created an XML rule, you should create a test rule to ensure that it works.
4.1. Creating a test rule 링크 복사링크가 클립보드에 복사되었습니다!
Test rules are created using a process similar to the process for creating a test rule, with the following differences:
-
Test rules should be placed in a
tests/
directory beneath the rule to be tested. -
Any data, such as test classes, should be placed in a
data/
directory beneath thetests/
directory. -
Test rules should use the
.mta.test.xml
extension. - These rules use the structure defined in the Test XML Rule Structure.
In addition, it is recommended to create a test rule that follows the name of the rule it tests. For instance, if a rule were created with a filename of proprietary-rule.mta.xml
, the test rule should be called proprietary-rule.mta.test.xml
.
4.1.1. Test XML rule structure 링크 복사링크가 클립보드에 복사되었습니다!
All test XML rules are defined as elements within ruletests
which contain one or more rulesets
. For more details, see the MTA XML rule schema.
A ruletest is a group of one or more tests that targets a specific area of migration. This is the basic structure of the <ruletest>
element.
<ruletest id="<RULE_TOPIC>-test">
: Defines this as a unique MTA ruletest and gives it a unique ruletest id.-
<testDataPath>
: Defines the path to any data, such as classes or files, used for testing. -
<sourceMode>
: Indicates if the passed in data only contains source files. If an archive, such as an EAR, WAR, or JAR, is in use, then this should be set tofalse
. Defaults totrue
. -
<rulePath>
: The path to the rule to be tested. This should end in the name of the rule to test. -
<ruleset>
: Rulesets containing the logic of the test cases. These are identical to the ones defined in Rulesets.
-
4.1.2. Test XML rule syntax 링크 복사링크가 클립보드에 복사되었습니다!
In addition to the tags in the standard XML rule syntax, the following when
conditions are commonly used for creating test rules:
-
<not>
-
<iterable-filter>
-
<classification-exists>
-
<hint-exists>
In addition to the tags in the standard perform action
syntax, the following perform
conditions are commonly used as actions in test rules:
-
<fail>
4.1.2.1. syntax 링크 복사링크가 클립보드에 복사되었습니다!
Summary
The <not>
element is the standard logical not operator, and is commonly used to perform a <fail>
if the condition is not met.
The following is an example of a test rule that fails if only a specific message exists at the end of the analysis.
The <not>
element has no unique attributes or child elements.
4.1.2.2. syntax 링크 복사링크가 클립보드에 복사되었습니다!
Summary
The <iterable-filter>
element counts the number of times a condition is verified. For additional information, see the IterableFilter class.
The following is an example that looks for four instances of the specified message.
The <iterable-filter>
element has no unique child elements.
<iterable-filter> element attributes
Attribute Name | Type | Description |
---|---|---|
size | integer | The number of times to be verified. |
4.1.2.3. syntax 링크 복사링크가 클립보드에 복사되었습니다!
The <classification-exists>
element determines if a specific classification title has been included in the analysis. For additional information, see the ClassificationExists class.
When testing for a message that contains special characters, such as [
or '
, you must escape each special character with a backslash (\
) to correctly match.
The following is an example that searches for a specific classification title.
The <classification-exists>
has no unique child elements.
<classification-exists> element attributes
Attribute Name | Type | Description |
---|---|---|
classification | String |
The |
in | String | An optional argument that restricts matching to files that contain the defined filename. |
4.1.2.4. syntax 링크 복사링크가 클립보드에 복사되었습니다!
The <hint-exists>
element determines if a specific hint has been included in the analysis. It searches for any instances of the defined message, and is typically used to search for the beginning or a specific class inside of a <message>
element. For additional information, see the HintExists class.
When testing for a message that contains special characters, such as [
or '
, you must escape each special character with a backslash (\
) to correctly match.
The following is an example that searches for a specific hint.
The <hint-exists>
element has no unique child elements.
<hint-exists> element attributes
Attribute Name | Type | Description |
---|---|---|
message | String |
The |
in | String |
An optional argument that restricts matching to |
4.1.2.5. syntax 링크 복사링크가 클립보드에 복사되었습니다!
The <fail>
element reports the execution as a failure and displays the associated message. It is commonly used in conjunction with the <not>
condition to display a message only if the conditions are not met.
The <fail>
element has no unique child elements.
<fail> element attributes
Attribute Name | Type | Description |
---|---|---|
message | String | The message to be displayed. |
4.2. Manually testing an XML rule 링크 복사링크가 클립보드에 복사되었습니다!
You can run an XML rule against your application file to test it:
<MTA_HOME>/bin/mta-cli [--sourceMode] --input <INPUT_ARCHIVE_OR_FOLDER> --output <OUTPUT_REPORT_DIRECTORY> --target <TARGET_TECHNOLOGY> --packages <PACKAGE_1> <PACKAGE_2> <PACKAGE_N>
$ <MTA_HOME>/bin/mta-cli [--sourceMode] --input <INPUT_ARCHIVE_OR_FOLDER> --output <OUTPUT_REPORT_DIRECTORY> --target <TARGET_TECHNOLOGY> --packages <PACKAGE_1> <PACKAGE_2> <PACKAGE_N>
You should see the following result:
Report created: <OUTPUT_REPORT_DIRECTORY>/index.html Access it at this URL: file:///<OUTPUT_REPORT_DIRECTORY>/index.html
Report created: <OUTPUT_REPORT_DIRECTORY>/index.html
Access it at this URL: file:///<OUTPUT_REPORT_DIRECTORY>/index.html
More examples of how to run MTA are located in the Migration Toolkit for Applications CLI Guide.
4.3. Testing the rules using JUnit 링크 복사링크가 클립보드에 복사되었습니다!
Once a test rule has been created, it can be analyzed as part of a JUnit test to confirm that the rule meets all criteria for execution. The WindupRulesMultipleTests
class in the MTA rules repository is designed to test multiple rules simultaneously, and provides feedback on any missing requirements.
Prerequisites
- Fork and clone the MTA XML rules. The location of this repository will be referred to as <RULESETS_REPO>.
- Create a test XML rule.
Creating the JUnit test configuration
The following instructions detail creating a JUnit test using the Red Hat CodeReady Studio. When using a different IDE it is recommended to consult your IDE’s documentation for instructions on creating a JUnit test.
- Import the MTA rulesets repository into your IDE.
Copy the custom rules, along with the corresponding tests and data, into
</path/to/RULESETS_REPO>/rules-reviewed/<RULE_NAME>/
. This should create the following directory structure.Directory structure
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Select Run from the top menu bar.
- Select Run Configurations… from the drop down that appears.
- Right-click JUnit from the options on the left side and select New.
Enter the following:
-
Name: A name for your JUnit test, such as
WindupRulesMultipleTests
. -
Project: Ensure this is set to
windup-rulesets
. Test class: Set this to
org.jboss.windup.rules.tests.WindupRulesMultipleTests
.
-
Name: A name for your JUnit test, such as
Select the Arguments tab, and add the
-DrunTestsMatching=<RULE_NAME>
VM argument. For instance, if your rule name wascommunity-rules
, then you would add-DrunTestsMatching=community-rules
as seen in the following image.- Click Run in the bottom right corner to begin the test.
Once the execution completes the results will be available for analysis. If all tests passed, then the test rule is correctly formatted; otherwise, it is recommended to address each of the issues raised in the test failures.
4.4. About validation reports 링크 복사링크가 클립보드에 복사되었습니다!
Validation reports provide details about test rules and failures and contain the following sections:
Summary
This section contains the total number of tests executed and reports the number of errors and failures. It displays the total success rate and the time taken, in seconds, for the report to be generated.
Package List
This section contains the number of tests executed for each package and reports the number of errors and failures. It displays the success rate and the time taken, in seconds, for each package to be analyzed.
A single package named
org.jboss.windup.rules.tests
is displayed unless additional test cases have been defined.Test Cases
This section describes the test cases. Each failure includes a Details section that can be expanded to show the stack trace for the assertion, including a human-readable line indicating the source of the error.
4.4.1. Creating a validation report 링크 복사링크가 클립보드에 복사되었습니다!
You can create a validation report for your custom rules.
Prerequisites
- You must fork and clone the MTA XML rules.
- You must have one or more test XML rules to validate.
Procedure
-
Navigate to the local
windup-rulesets
repository. -
Create a directory for your custom rules and tests:
windup-rulesets/rules-reviewed/myTests
. -
Copy your custom rules and tests to the
windup-rulesets/rules-reviewed/<myTests>
directory. Run the following command from the root directory of the
windup-rulesets
repository:mvn -Dtest=WindupRulesMultipleTests -DrunTestsMatching=<myTests> clean <myReport>:report
$ mvn -Dtest=WindupRulesMultipleTests -DrunTestsMatching=<myTests> clean <myReport>:report
1 2 Copy to Clipboard Copied! Toggle word wrap Toggle overflow The validation report is created in the
windup-rulesets/target/site/
repository.
4.4.2. Validation report error messages 링크 복사링크가 클립보드에 복사되었습니다!
Validation reports contain errors encountered while running the rules and tests.
The following table contains error messages and how to resolve the errors.
Error message | Description | Resolution |
---|---|---|
No test file matching rule | This error occurs when a rule file exists without a corresponding test file. | Create a test file for the existing rule. |
Test rule Ids <RULE_NAME> not found! | This error is thrown when a rule exists without a corresponding ruletest. | Create a test for the existing rule. |
XML parse fail on file <FILE_NAME> | The syntax in the XML file is invalid, and unable to be parsed successfully by the rule validator. | Correct the invalid syntax. |
Test file path from |
No files are found in the path defined in the |
Create the path defined in the |
The rule with id="<RULE_ID>" has not been executed. | The rule with the provided id has not been executed during this validation. | Ensure that a test data file exists that matches the conditions defined in the specified rule. |