Continuous Delivery – OPA and Postman, Newman and Jenkins #1

Continuous Development – OPA and Postman, Newman and Jenkins #1

For the first time in a while I was working to set up an example platform for testing purposes. Whilst a good portion of it is not specific to Oracle Policy Automation / Intelligent Advisor, it seemed both useful and appropriate to document some of the ideas, steps and conversation points in some posts here on the website. So without further ado, let’s get started. In this series we will look at setting up Oracle Policy Automation, Postman, Postman Runner, Newman and Jenkins to enable lights-out testing of batch or XML-based projects. Then, once we’ve done that, we will extend our reach to include HTML Interviews.

Firstly, let’s get a handle on the different tools in the kit. Postman, as many will know, is a visual client for testing REST APIs – at least that is what people know it for – but it is in fact capable of making any kind of HTTP call. Although the examples here will focus on the Oracle Policy Automation Batch API, you could use it for SOAP Assess as well.

Learn About Postman

Download Postman for Windows, iOS or Linux

To make a call to an Oracle Policy Automation Project, here are the prerequisites

  • The Project needs to be deployed
  • You need to have an API Client user and password
  • You need to be able to build a sample case.

So, let’s get started!

Assuming you have an Oracle Policy Automation Hub at your disposal, or someone who can sort you out with access to one, then you need to start with the creation of an account of type “API Client”. You will need to be given access to the determinations API, for at least the Collection (or “workspace” as it is now known) and then the account needs to be activated. It probably will look something like this:

Create User for Postman

  1. Go to Permissions > API clients
  2. Create a user and enable them
  3. Select at least the workspace where your project is deployed
  4. Save the user

Your project will need to be deployed in web service mode (not Interview mode, but if it is also used as an interview that’s fine too.

Check Project Deployed

 

So now you are ready to fire up Postman and get this show on the road. Remember that when using the REST api for determinations, you are going to be using OAuth2 as your authentication mechanism. This requires you to make a call first to an authentication URL, and receive a token. That token is valid for 1800 seconds, and must accompany any calls you make to your project. So, here is what you need to do in Postman:

Create a Collection. To keep things organized in Postman, put stuff in a Collection. Create one, give it a good name and then later you can put all your different Requests to OPA in this Collection.

Postman Collection OK

 

While creating your collection, you can set up the Authentication as well. This way, any Request you make that is stored in this collection can inherit the authentication method you define. It’s easier than doing it for every request (although that is also possible).

Postman Authentication Start

Select OAuth 2.0, Request Headers and then click the Get New Access Token button. Since this is the first time you have done this, you will now be tasked with filling in a detailed dialogue to explain to Postman how to go and get the magic “token” for Oracle Policy Automation. The screenshot is accompanied by comments below for each of the steps.

  1. Give the Access Token Authentication a name. You might have multiple Hubs and need to have different data for each of them, so a name is a good thing.
  2. Select Client Credentials
  3. Enter the address of the authentication endpoint. This is something like the address above (replace “http://localhost:7777/opa19d/” with your own URL to your Hub. Note that recently the Authentication URL has evolved, and it is now versioned. Check your version of the documentation to see if you can use the new URL format (“api/version/auth”) and gradually migrate all your calls to this new format, even if the old format works for now (this was introduced in version 20A).
  4. Enter the API Client you created or decided to use
  5. Enter the password you set up.
  6. Select Send client credentials in body
  7. Click Request Token

If everything went according to plan, you should see this:

Postman Authentication OK

Obviously, click Use Token. You are now ready for showtime. You have 1800 seconds to get your first request into Oracle Policy Automation!

Finish your Collection creation (we will be using the other features of the Collection later, in the other parts of this story). Create a new Request and save it in the Collection.

Let’s assume you have a Project ready to go. If you don’t the project I’m using in this demo can be downloaded here. The Body of the request (using Raw JSON as your format) would look something like this:

{ "outcomes": [
"b_success",
"resultstepnumber",
"resultstep",
"totaltime"
],
"cases": [
{
"@id": "1",
"origin": "Miromesnil",
"destination": "Oberkampf"
},
{
"@id": "2",
"origin": "Grands Boulevards",
"destination": "Concorde"
}
]
}

This assumes your project has a boolean to indicate success and some other attributes (in my case, the step number, the step and the total time. This project calculates the time to travel between two Paris Metro stations, in the days before confinement and lockdown. There are two cases to be tested. They are based on two attributes, namely origin and destination.

The output should look something like this:

{
"cases": [
{
"@id": "1",
"b_success": true,
"totaltime": 42,
"theresults": [
{
"@id": 0,
"resultstep": "Miromesnil",
"resultstepnumber": 1
},
{
"@id": 1,
"resultstep": "Saint Augustin",
"resultstepnumber": 2
},
{
"@id": 2,
"resultstep": "Havre Caumartin",
"resultstepnumber": 3
},
{
"@id": 3,
"resultstep": "Auber",
"resultstepnumber": 4
},
{
"@id": 4,
"resultstep": "Opéra",
"resultstepnumber": 5
},
{
"@id": 5,
"resultstep": "Richelieu Drouot",
"resultstepnumber": 6
},
{
"@id": 6,
"resultstep": "Grands Boulevards",
"resultstepnumber": 7
},
{
"@id": 7,
"resultstep": "Bonne Nouvelle",
"resultstepnumber": 8
},
{
"@id": 8,
"resultstep": "Strasbourg Saint-Denis",
"resultstepnumber": 9
},
{
"@id": 9,
"resultstep": "Réaumur Sébastopol",
"resultstepnumber": 10
},
{
"@id": 10,
"resultstep": "Arts et Métiers",
"resultstepnumber": 11
},
{
"@id": 11,
"resultstep": "Temple",
"resultstepnumber": 12
},
{
"@id": 12,
"resultstep": "République",
"resultstepnumber": 13
},
{
"@id": 13,
"resultstep": "Oberkampf",
"resultstepnumber": 14
}
]
},
{
"@id": "2",
"b_success": true,
"totaltime": 12,
"theresults": [
{
"@id": 0,
"resultstep": "Grands Boulevards",
"resultstepnumber": 1
},
{
"@id": 1,
"resultstep": "Richelieu Drouot",
"resultstepnumber": 2
},
{
"@id": 2,
"resultstep": "Opéra",
"resultstepnumber": 3
},
{
"@id": 3,
"resultstep": "Pyramides",
"resultstepnumber": 4
},
{
"@id": 4,
"resultstep": "Madeleine",
"resultstepnumber": 5
},
{
"@id": 5,
"resultstep": "Concorde",
"resultstepnumber": 6
}
]
}
],
"summary": {
"casesRead": 2,
"casesProcessed": 2,
"casesIgnored": 0,
"processorDurationSec": 0.04,
"processorCasesPerSec": 45.45
}

For the sake of space, I’ve cut this off before the end. But you should be getting the idea. The output is the time taken, and the steps from the origin to the destination. There are some stations on my map which are inaccessible (because I didn’t fill in the entire map of the Paris Metro) so the boolean tells me if the route is possible, and the total time is also shown. Now that we have the basic setup, in the next part we will add

  • A test script to calculate average response time
  • A test to see if the route is possible
  • A command line to be able to run this without Postman

See you in the next part!