How to run / debug User Defined Function using Testview

In this article we will show how to locally run / debug SAP PI User defined functions using Integrace Testview plugin. We assuming you have NWDS and Testview installed. All our examples are published on “google code” .

1. Create UDF in ESR

First of all, let’s just create new UDF. Let’s make for our example simple UDF that would concat 2 strings and will accept queues with different length. Let’s name it SafeConcat and will make Execution type “All Values of Queue”.

We all hate to write Java code in ESR editor so now we are will try to ….

2. Export UDF to local Java file and add it to existing project

Standard Export button would ask us for local folder to export. Let’s note it for further use.

By default file is exported as complete Eclipse project so you could just import existing project into your workspace. However, we will simply copy generated source files into our examples project source folder.



Now we could implement UDF using NWDS

3. Create Testview configuration file.

To run or debug UDF locally we need to create Testview Configuration file first. This file contains all information regarding input data and parameters to make possible local run.

Create package in our test source folder. Our advise is to separate tests folder from sources but use same package names.

Then create Testview configuration using New > Other > New Testview Configuration wizard.

Specify configuration filename. It should end with .xml .  Select Class type “User Defined Function”, then search for class and method names

After pressing Finish button configuration file will be created and saved into selected folder.

4. Specify UDF input parameters

In editor opened you can specify input queues and other parameters, including options to execute Init function prior of running UDF method itself. Don’t forget to select option “Save output files/queues”. This would allow you to see function output.

4. Run / Debug UDF

All preparations are done so we are ready to run or debug our UDF. First of all let’s run it. To do it, right-click our configuration file and select Run as > Testview . After execution you would be able to see execution log in console. Also, output queues would be saved in configuration file in Output > FunctionOutput section.

To debug UDF you should specify you desired breakpoints and then Debug configuration file for this UDF.

After this you would be asked to switch in Debug view and you will be able to see all internal stuff.

5. Export UDF back to ESR

Finally, let’s export our UDF back to ESR. Of course, we could just use copy/paste for the text, but it’s better to use “Import” function. Just specify Java file with this UDF.

5. Conclusion.

Now you have fully tested UDF ready to use in your environment. Needless to say you could create more than one configuration file to try different test cases. This effectively allows you to use test driven development approach – from multiple test-cases to regressive testing in case of changes.
In our next blog posts we will show how to use parameters and how to run UDF using Testview API library.