Tag: REST

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

Continuous Delivery – 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 REST 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!

Input REST Batch Requests into Debugger

Input REST Batch Requests into Debugger

One of the new features introduced in 19C is the ability to use REST batch sessions (or requests, to give them their real name) directly in the Debugger. This is a great leap forward. Up to now, where I am working at the moment, we had built a tool to translate the REST into XML but it was still less than optimal.

So you can imagine how excited I was when I saw this new feature arrive in the product. There is, however, one major issue that I still find very frustrating. You will understand perhaps if I show you an example. Let’s consider the following. I have a batch of 10000 REST Batch cases that have been used in our testing and saved in JSON format. Now I want to open one of these in my Debugger to investigate what is happening. I open the project in Oracle Policy Modeling and I rush to the Debugger.

REST Batch

The pop-up window shows that my JSON file has been loaded, and shows me…the case id. Which from a functional point of view, of course, tells me nothing at all. Most of the testers here would be unable to remember which case represents which testing scenario. What we would have loved (and we are going to ask for) is the possibility to choose what to display in that window. For example, in our case, maybe if we show the identifying attribute from one of the entities being used, that would be more than enough for us to be able to recognize which case it is.

This might not seem a big deal but when you have an operations department who simply sends you the file and says it does not work i(they don’t necessarily know anything about Oracle Policy Automation apart from how to run it) it can be frustrating working backwards from REST case numbers back to scenarios that we can relate to our Test Cases in Excel.

I’m going to be accused of mixing everything up but it would be nice to have something easier to recognize, or perhaps a parameter that we could change.

Deployment REST API : Uploading Zip Files #1

Deployment REST API : Uploading Zip Files

Following on from a post in the not too distant past, where we looked sideways at the Deployment REST API and the ability to download the Zip File of a deployment snapshot programatically, this new post answers a request from one of our readers regarding the “other side of the coin” ; specifically how to take a Zip File that needs to be uploaded into an Oracle Policy Automation Hub, and get the file to load up into the Deployments, using code. I must thank the commenter on the previous article for sharing his question, since it is one that comes up quite a lot and this is a good opportunity to hopefully show how you might do it.

The starting point of the process is that you have previously downloaded a snapshot file from a Deployments page of your Hub in environment A, and you now want to copy it across to environment B.

With your Zip File in hand, what can you do to automate this process? Of course, you turn your attention to the REST API and the deployment REST API in particular. Find the page that matches your version and let’s have a look.

{
    "name": "Example",
    "description": "Description of Example Project",
    "compatibilityMode": "latest",
    "services":
    [
        "interview",
        "webservice",
        "mobile",
        "javaScriptSessions"
    ],
    "collections":
    [
        "Default Collection"
    ],
    "versions":
    {
        "items":
        [
            {
                "description": "The initial version",
                "activeVersionFlag": true,
                "snapshot":
                {
                    "base64": "...base64 value..."
                }
            }
        ]
    }
}

How to get a class out of that? If only I could find a way to turn that into something easy to use in Visual Studio, I could create my own…wait a minute! Enter JSONUtils – the perfect site for converting JSON into C# or Visual Basic Classes.

OPA Hub - Deployment REST API Generate Class

How easy is that?

  1. Choose your language
  2. Give your new Class a name
  3. Paste the sample from the Oracle REST API documentation
  4. Press this button
  5. There’s your class, ready to use in your Visual Studio project.

Armed with this, we are ready to continue our research. We also need to be able to POST our request to the Oracle Policy Automation Hub. Thankfully somebody else has already asked about POSTing JSON to a specific URL millions of times, and there is a good starter function on Stack Exchange. At the bottom of that question is a great example.

Checklist – REST API Deployment

We can step back a moment and review a checklist

  1. We have Class to model our request
  2. We have a function to use HTTPWebRequest send things to the Oracle Policy Automation Hub
  3. We have an integration user and password, and the url of the Oracle Policy Automation Hub

So what else do we need? We need to be able to turn the Zip File into an encoded string as per the example given on the Oracle Policy Automation website : something like this:

 

Public Function ConvertFileToBase64(ByVal fileName As String) As String
        Return Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName))
    End Function

In the second part of this post, we will put it all together and see the result!

February 2017 Release of Oracle Policy Automation

February 2017 Release of Oracle Policy Automation

In case you missed it, the February 2017 Release of Oracle Policy Automation is now available for download and inspection from the official sources. This release sees some interesting new tweaks in the Interview Tab, as well as enhancements to the Oracle Policy Automation Hub, especially in respect of programmatic access to some features. There are also some exciting new flexibility enhancements in respect of the Oracle Service Cloud connection. Here is a list of the new features.

  • Service Cloud connection – enhanced usage of a single interview for agents, logged-in users and anonymous users
  • Manage Hub users programatically – Oracle Policy Automation HUB REST Interface
  • New User Account Type in the Hub (see Video)
  • Use external identity providers (via REST)
  • Export Data Model to CSV (See Video)
  • Entity Type Highlight in Data Tab (See Video)
  • Slider Enhancements (See Video)
  • File Upload Enhancements (See Video)
  • Unsaved Interview Prompts

We have already posted five videos outlining the new features, and more will be uploaded in the coming days to give you a rapid overview of the new enhancements both in the Oracle Policy Modeling application and on the Oracle Policy Automation Hub web application.  Proof, if ever proof was needed, of the continued investment in the OPA line to further enhance its status as the go-to natural language logic and dematerialised interview engine.

Worldwide
Logo by Southpaw Projects LLC