There are many activity rules, which are dealing with DB operations( like updating and creating work/data objects into DB) and then clean the referenced clipboard pages at the end. In such cases, if we want to perform any assertions on those pages we cannot do it directly, as all pages are removed by rule under test activity.
However, Using After rule execution feature of PegaUnit, users can leverage the ability to perform few actions before invoking assertions and after rule under test execution. Options available are opening DB object (which we saved recently) or load data page or execute activity..etc. At runtime of PegaUnit, actions configured here will get executed immediately after execution of Rule Under Test, thus enabling users to perform actions such as opening and loading a DataBase object to a clipboard page so that they are available for assertions to follow.
Let us take an example activity to understand the case better. We have an activity “LinkAttachmentToCase”. As the name suggests, this activity is used to attach files to the case work object.
To Automate this activity as pre-requisite we should have 2 things. The first one is an open work object and an Attachment which will be linked with the work object. For that, I am trying to create a Work Object for one of the cases using the Set Up capabilities of the Pega Unit.
Navigate to Setup & Cleanup tab -> expand Before rule Execution and then, we can use an Additional clipboard data option. Here I am selecting Create work object option and then providing the class as “UPlus-UPlus_CS-Work-LogComplaint” and Load on Page as “SetUpPage”.
By doing this, Work Object will be created for the class provided then it will be loaded on to the clipboard page specified(SetUpPage) at runtime.
Work Object will be available now. To call the rule under test activity(“LinkAttachmentToCase”) we need to pass this work object. Along with that, we need to pass an attachment also. I have configured parameters for rule under test in Pega Unit as below:
But as we can see, at the end of the activity(LinkAttachmentToCase)it is committing to DB and removing all the pages like below in the page-remove step. So, though the attachment is added to the case, we cannot assert it.
We can leverage the Post rule execution option in these scenarios.
In this case, I am trying to load a Data page “D_AttachmentList” which is used to load attachment for a case work object. It takes Workobject inskey as a parameter. So we are passing the same Work object inskey (SetUpPage.pzInsKey)which we used for the Rule under test.
Now, we verify that the attachment is added to it or not by verifying the count and details of it from Data Page as below :