Thanks for the guidance, we tried out and it worked by creating a work directory and creating policy files there, followed by configuring the Integration server setting as described in the above diagram.
Original Message:
Sent: Mon February 26, 2024 06:35 AM
From: Paul Lacy
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Hello Tarandeep,
When you right click on a test project and select Run Test Project, we create a temporary Integration server to run the test project.
It will build a bar file containing the test project and the application you are testing.
It does not include any other setup so any policy projects will not be included.
You can stop the toolkit from using a temporary Integration server by changing the launch configuration that gets created when you first run a test project.
You can update the launch configuration to use a particular Integration server and define what gets reset when you run the test project.
Hence you could start the server and deploy the policy and then the test should work.
The launch configuration is accessed by clicking in the run configurations menu item under run menu and you should see your project under Integration Server JUnit:

In this example I have changed the launch configuration to use an Integration Server under the directory: c:\myIntegrationServer.
I would start this server and deploy the policy project and then run the test again.
Make sure you stop the server before running the test in the toolkit.
On your question of SonarQube , I cannot help you since that is not an IBM product.
------------------------------
Paul Lacy
Original Message:
Sent: Thu February 22, 2024 12:32 PM
From: Tarandeep Singh
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Hi Paul,
We have an application and a shared library. In the shared Library there is a Java Project that fetches User defined Policy Variables - using MbPolicy. The Application when invoked, fetches the value from the User Defined policy file using this Java Code by the Java Routine Esql Function Call.
*The Java Project has the Jplugin2.jar in the Build Path
Scenario: We like to create a coverage report (SonarQube) of this Java Project and How do we accomplish this?
So, to begin with, First we wanted to explore the JUnit. However JUnit is fairly new concept with regards to IBM ACE v12 Toolkit.
In the Application Development View, we created a Test Project with the Application as a container to test.
Two simple Tests were added one for Reading the Value of Property1 and another value for Property2.
Problem: When we run the Test Project, the MbPolicy is unable to fetch the values from the Policy.
How do we resolve this? And foremost how do we create a code Coverage report.
We also tried by adding the Jplugin2.jar file in the build path of the Test project but No luck!
------------------------------
Tarandeep Singh
Original Message:
Sent: Thu February 22, 2024 11:13 AM
From: Paul Lacy
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Hello TaranDeep,
What error do you get ?
Regards, Paul.
------------------------------
Paul Lacy
Original Message:
Sent: Thu February 22, 2024 10:47 AM
From: Tarandeep Singh
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Did you get any luck with this, stuck with the same issue.
What other things you tried to test the policy file!
------------------------------
Tarandeep Singh
Original Message:
Sent: Thu December 22, 2022 10:30 PM
From: Chuan Luu Huu
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Thanks for your support, I will try it.
------------------------------
Chuan Luu Huu
Original Message:
Sent: Mon December 19, 2022 04:50 AM
From: Paul Lacy
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Hello,
Here is some sample code for reading a policy that is deployed to an IntegrationServer based on test case created by the test case wizard:
import........
import com.ibm.broker.plugin.MbException; // Add these two lines
import com.ibm.broker.plugin.MbPolicy;
public void App_Flow_Compute_TestCase_001() throws TestException {
.......
try {
MbPolicy pol = MbPolicy.getPolicy("ActivityLog", "{MyPolicies}:TestPolicy");
// get the policy from policy project MyPolicies for policy TestPolicy for type ActivityLog
if (pol != null)
{
System.out.println("Policy name is "+pol.getName());
System.out.println("log file is: "+pol.getProperty("fileName").valueAsString());
}
else
{
System.out.println("policy not found");
}
} catch (MbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
.......
You need to jplugin2.jar to the java build path for the tets project:
You will need to change the run configuration as described previously and also depoy the policy you want to read.
You can find the policy type by opening the policy using a text editor and the type is in the policy:
<policies>
<policy policyType="ActivityLog" policyName="TestPolicy" policyTemplate="ActivityLog">
.....
------------------------------
Paul Lacy
Original Message:
Sent: Mon December 12, 2022 09:01 PM
From: Chuan Luu Huu
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
I tried but my program can not read .policyxml file. Can you show me for more detail to read policyxml?
------------------------------
Chuan Luu Huu
Original Message:
Sent: Wed November 16, 2022 03:57 AM
From: Paul Lacy
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
Hello Chuan,
When you run/debug a test project fron the toolkit, it will create a new temporary server to run it on.
If you want to deploy additional projects such as a policy or setup credentails then there is an option to do this.
When you run the test project it will create a run/debug launch configuration. You should see the run/debug options by selecting the run or debug configuration from the menu (does not matter which one you select).
This will show the run/debug configurations and under Integration Server Junit you should see a configuration that will be called by test project name. Select it
and you can tell the configuration to use a temp work directory (default) or point at an existing work directory.
This means you can configue that integration server before you run the test.
Please note that by default the integration server is not cleared of any resources.
Here is screen shot of my launch configuration showing App_Test project after I had run the test project for the first time:
There are a number of other options here as well that you can change.
Please note that each project will have its own launch configuration.
If you run the just the test java file then that will also have its own configration. For instance, I had generated a test java file on a compute node and then ran it using the run as option by right clicking on the java file and that generated another configuration called App_Test.test.App_flow_Compute_0001_Test
Regards,
------------------------------
Paul Lacy
Original Message:
Sent: Tue November 15, 2022 02:43 AM
From: Chuan Luu Huu
Subject: Read Policy file(.policyxml) in source code jUnit test for handle testcase
I create testcase in App connect enterprise toolkit v12 then auto gen java source test. But It can not read policy file when I debug or run test.
Can you help how can I read policy file in source code jUnit test.java?
------------------------------
Chuan Luu Huu
------------------------------