Implement the Test-Connection Behavior Using Flows

This procedure describes how you can implement the Test Connection functionality using a flow.

  1. Define a simple flow with a GET call to an idempotent test API.
    Here is a sample code:
    "flows": {  
       "testConnectionFlow" :{
          "id": "testConnectionFlow",
          "description": "testConnectionFlow",
          "specVersion": "0.8",
          "version": "0.1",
          "start": "startState",
          "functions": [
            {
              "name": "generalRestFunc",
              "type": "custom",
              "operation": "connectivity::rest"
            }
          ],
          "states": [
            {
              "name": "startState",
              "type": "operation",
              "actions": [
                {
                  "functionRef": {
                    "refName": "generalRestFunc",
                    "arguments": {
                      "uri": "${.connectionProperties.baseURL + \"/customers\"}",
                      "method": "GET"
                    }
                  },
                  
                }
              ],
              "end": true
            }
          ]
        }
    }
  2. Add a actionDataFilter action that asserts a condition and set the .output.success to true to assert the status code.
    Here is a sample code:
    "actionDataFilter": {
                    "results": "${ { success: (.status==200), message: .body.origin } }",
                    "toStateData": "${ .output }"
                  }
    Here is the full sample code that makes an outbound GET call to the test endpoint and uses state's boolean output value to indicate the result:
    "flows": {   
       "testConnectionFlow" :{
          "id": "testConnectionFlow",
          "description": "testConnectionFlow",
          "specVersion": "0.8",
          "version": "0.1",
          "start": "startState",
          "functions": [
            {
              "name": "generalRestFunc",
              "type": "custom",
              "operation": "connectivity::rest"
            }
          ],
          "states": [
            {
              "name": "startState",
              "type": "operation",
              "actions": [
                {
                  "functionRef": {
                    "refName": "generalRestFunc",
                    "arguments": {
                      "uri": "${.connectionProperties.baseURL + \"/customers\"}",
                      "method": "GET"
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ { success: (.status==200), message: .body.origin } }",
                    "toStateData": "${ .output }"
                  }
                }
              ],
              "end": true
            }
          ]
        }
    }
  3. Call the flow in the connection definition.
    Here is the sample code:
    "connectionDefinition": {
      "connectionProperties": [
      ],
      "securityPolicies": [
        {
        "type": "managed",
        "policy": "BASIC_AUTH",
        "description": "Account credentials",
        "displayName": "Account credentials",
        "scope": "ACTION",
        "securityProperties": [
          {
            "name": "username",
            "hidden" : true,
            "default": "oracle"
          }
        ]   
        }
      ],
      "test": "flow:testConnectionFlow"