In this article, we will take a detailed look into the steps to test a business policy. It is always a best practice to test the policy before actually deploying the policy/version into the production environment. To test the policy using BizTalk360 Business Rules Composer, you need to specify one or more instances for the following fact types - XML Documents, Database Tables, and .NET Classes.
To understand how to work with the BizTalk360 Business Rules Composer's Policy testing section, we will consider one classic example of processing a purchase order. The rule to be tested is when a XML schema containing the purchase order information has quantity information less than or equal to 500, the purchase order has to be approved. If the quantity information is greater than or equal to 500, the purchase order has to be denied. To test this using the BizTalk360 Business Rules Composer, let's assume the business policy (version) has been created and published.
Follow the steps as shown below to test the policy with the XML schema file.
- Log in to BizTalk360
- Expand the Rules section. Click Business Rules Composer from the drop down.
- Select the policy from the list in the Policies pane. In our case, lets select the ProcessPurchaseOrder policy.
- Select the appropriate version of the policy from the drop down. Lets select Version 1.1 Published.
- Once you select the version information from the policies pane, you will notice that the Help/Rules Creation Pane would now become the Policy Testing pane. The policy testing pane contains the following sections -
- Fact Types - Lists the fact types - XML Documents, Database Tables, and .NET Classes
Select File - Option to choose the XML file. When adding a Database Table, this option would display as "Add Instance". Similarly, when adding a .NET Class, this would would display as "Create Fact".
Once you have added the input for the fact type, when you select the input file, you will notice the button changing to Remove Instance.
- Test - The rule engine fires the test and the result is displayed in the results pane
- Download Test Result - This is a new functionality in BizTalk360 Business Rules Composer. This button will be displayed only when the test is trying to change the value in the XML file (the status field in this case!). As per the above scenario, when the input file contains a value (quantity) less than or equal to 500 (say, 400), the status of the purchase order has to be changed to "Approved". When the BizTalk360 Business Rules Composer is trying to make this change, you will notice the Download Test Result button. Clicking on the button will download the "modified" purchase order (where status is set to Approved). On the other hand, when the rule doesn't match, you will not see the Download Test Result button.
- Result Execution pane - The pane that displays the test execution result, similar to the BizTalk Business Rules Composer
- For our scenario, we will only be using the 'XML Documents' facts type to test the business rule. Expand the (+) against XML Documents and select RuleTest.PO (since we have constructed the rule to be based on the schema file, you will notice the RuleTest.PO appearing as a drop down).
Please note that the current version of BizTalk360 Business Rules Composer does not allow you to create business rules with the help of XML schemas. If you are looking at creating a rule using the XML schema, you need to create the business policy (rule) in the BizTalk Business Rules Composer. We will be adding this capability in the upcoming versions of BizTalk360.
- Once you have selected the schema file, click Select File. You will be prompted to choose the XML input file (in our example the purchase order file). Let's say we have 2 purchase orders - PO1.xml & PO2.xml. Select the PO1.xml file.
- Click Test
- Depending on the result, if any of the purchase orders matches the rule condition, you will notice the Download Test Result button appearing next to the Test button.
- Click the Download Test Result button to download the test result file (that contains the modified values - Status = Approved)
- The process remains the same for the PO2.xml file as well. If the input file contains the quantity value >=500, the condition will not be met and no changes will be done to the input file. In this case, you will not see the Download Test Result button.
Click the sliders to go through the process.