ThingWorx Flow > ThingWorx Flow SDK > Connector Test Automation
Connector Test Automation
The Connector test helper provides a programmatic interface to the CLI. All options provided on the CLI can also be provided through the programmatic interface. This is useful to convert a interactive run using the CLI to an automated regression test.
ptc-flow-test-helper npm module provides APIs to automate Connector integration test cases. You can use these APIs along with any node.js testing framework such as mocha, to automate the Connector test cases.
This npm module provide three APIs:
ConnectorTestHelper—Provides APIs to invoke Connector artifacts
ConnectorSyntaxTestHelper—Verifies syntax of the Connector artifacts
JSONUtils—Provides JSON utilities to be used as assertions in the test case
ConnectorTestHelper
It provides the APIs to test the following connector artifacts:
ActionAPI—Connector Action
ConnectionAPI—Connector Connection
LookupAPI—Connector Lookup
TriggerAPI—Connector Trigger
CredsAPI—Utility to read and store the Connector Authentication
ActionAPI
The information set at test suite using this method must be passed while testing an individual test case.
The method setTestInfo returns information set by setTestInfo. This method sets information for the level of the test suite.
Signature :setTestInfo (Object info)
info = {
name: <string>,
connector: <connector object>,
version: <integer>,
access_token: <string>,
connection: <string>,
skipSchemaValidation: <boolean>,
logLevel: <string>
}
The following table explains each parameter in the sample above:
Parameters
Description
name
Sets the Action to be tested by the test cases
connector
Sets the Connector to be tested by test cases
version
Sets the Action version to be tested
access_token
If a Connector uses OAuth authentication mechanism, provide the name of the OAuth object stored in the creds.json file.
connection
If a Connector uses connection authentication mechanism, provide the name of the connection object stored in the creds.json file
skipSchemaValidation
Set to true for skipping validation of the action input or output against the input or output schema
logLevel
Set the log level to be used by ActionAPI
The ActionAPI uses information set in this method while invoking the action artifact.
Method getTestInfo: This method returns information set by setTestInfo
Signature: getTestInfo()
Return type (Object info)
Method test
This method executes the provided action artifact, and returns the result returned by the connector action.
Signature: test(Object input [optional], Object options [optional])
Return type promise object
input [optional]—Provide an input object accepted by the action artifact that is in accordance with the action input JSON schema
options [optional]—Provide object that includes some or all properties defined in Object info. This options object’s properties value overrides properties set in the info object at the test suite level, by setTestInfo method.
For example, Test suite level info is set for connection action1. You can use this options object to invoke a test method that executes connector action2 instead of action1 by passing property name : action2. This is useful if action2 is used for creating or deleting test data required or created by the test suite for action1.
ConnectionAPI
Information set at a test suite using this method must be passed while testing an individual test case.
Method setTestInfo: This method returns information set by setTestInfo. This method sets test suite level info.
Signature : setTestInfo (Object info)
info = {
name: <string>,
connector: <connector object>,
version: <integer>,
skipSchemaValidation: <boolean>,
logLevel: <string>

The following table explains each parameter in the sample above:
Parameters
Description
name
Sets the Connection to be tested by the test cases
connector
Sets the Connector to be tested by test cases
version
Sets the Connection version to be tested
skipSchemaValidation
Set to true for skipping validation of the action input or output against input or output schema
logLevel
Set the log level to be used by the ConnectionAPI
ConnectionAPI uses information set in this method while invoking the Connection artifact.
Method getTestInfo—Returns information set by setTestInfo
Signature: getTestInfo()—Return type (Object info)
Method test
Method executes provided connection artifact and returns result returned by connector connection artifact.
Signature: test(Object input [optional], Object options [optional])
Return type promise object
input [optional]—Provide input object accepted by connection artifact that is in accordance with connection input JSON schema
options [optional]—Provide object that includes some or all properties defined in Object info. This options object’s properties value overrides properties set in the info object at a test-suite level by setTestInfo method.
For example, Test-suite level info is set for connection connection1. You can use this option’s object to invoke a test method that executes connector connection2 instead of connection1 by passing property name : connection2. This is useful if connection2 is used for creating or deleting test data required or created by the test suite for connection1.
LookupAPI
Method setTestInfo: This method returns information set by setTestInfo. This method sets test suite level info.
Signature :setTestInfo (Object info)
info = {
name: <string>,
connector: <connector object>,
connection: <string>,
access_token: <string>
logLevel: <string>
}
The following table explains each parameter in the sample above:
Parameters
Description
name
Sets the Lookup to be tested by the test cases
connector
Sets the Connector to be tested by test cases
version
Sets the Lookup version to be tested
connection
If a Connector uses connection authentication mechanism, provide name of the connection object stored in the creds.json file
access token
If a Connector uses OAuth authentication mechanism, provide the name of the OAuth object stored in the creds.json file.
skipSchemaValidation
Set to true for skipping validation of the action input or output against input or output schema
logLevel
Set the log level to be used by the LookupAPI
Method test
Method executes the provided lookup artifact and returns the result returned by the connector lookup artifact.
Signature: test(String method, Object input [optional], Object options [optional])
Return type promise object
method: provide the lookup method name that needs to be tested.
input [optional]: provide input object accepted by lookup method.
options [optional]: provide object that includes some or all properties defined in Object info. This options object’s properties value overrides properties set in info object at the test-suite level by setTestInfo method.
Additionally, you can provide the following properties with this object.
searchById
Sets the id to use for search
searchByValue
Sets the value to use for search
filter
Sets the filter to search for items
For example, if you want to execute the lookup method by providing the SearchById value, use the options object to provide this information.
TriggerAPI
Information set at the test suite using this method needs to be passed while testing an individual test case.
Method setTestInfo—Returns information set by setTestInfo. This method sets test suite level info.
Signature : setTestInfo (Object info)
info = {
name: <string>,
connector: <connector object>,
version: <integer>,
access_token: <string>,
connection: <string>,
skipSchemaValidation: <boolean>,
logLevel: <string>
polling: <boolean>
}
The following table explains each parameter in the sample above:
Parameters
Description
name
Sets the Trigger to be tested by the test cases
connector
Sets the Connector to be tested by test cases
version
Sets the Trigger version to be tested
access_token
If a Connector uses OAuth authentication mechanism, provide the name of the OAuth object stored in the creds.json file.
connection
If a Connector uses connection authentication mechanism, provide the name of the connection object stored in the creds.json file
skipSchemaValidation
Set to true for skipping validation of the action input or output against input/ output schema
polling
Set it to True if the type of trigger is a polling trigger.
logLevel
Set the log level to be used by the TriggerAPI
TriggerAPI uses information set in this method while invoking action artifact.
Method getTestInfo—Returns information set by setTestInfo
Signature: getTestInfo()—Return type (Object info)
Method test
Method executes the provided trigger artifact and returns result that I returned by connector trigger artifact.
Signature: test(String method, String event, Object input [optional], Object options [optional])
Return type, promise object
method—Provide the trigger method name that needs to be tested.
event—Provide the trigger event defined in the trigger input schema.
input [optional]—Provide input object accepted by the trigger method.
options [optional]—Provide object that includes some or all properties defined in Object info. This options object’s properties value overrides relevant properties set in info object at test suite level by setTestInfo method.
Additionally, you can provide the following properties with this object for testing the polling trigger.
interval
Sets the interval in seconds after which to trigger.
stopAfter
Sets the maximum number of calls to the trigger.
meta
Sets the meta object.
unixTime
System for describing a point in time, defined as an approximation of the number of seconds
For example, if you want to set the unixTime while testing the polling trigger, use the above options.
CredsAPI
The methods used in this file follow:
getConnectionById—Returns the connection details based on the connection object name provided.
Signature: getConnectionById(uid)
getConnectionByIdWithHandle—Returns the connection details in a handle object.
Signature: getConnectionByIdWithHandle(uid)
getOauthById—Returns the OAuth details based on the OAuth object name provided.
Signature: getOauthById(uid)
getOauthByIdWithHandle—Returns the OAuth details in a handle object.
Signature: getOauthByIdWithHandle()
saveConnection—Saves a connection.
Signature: saveConnection()
saveOauth—Saves the OAuth details in the creds.json file.
Signature: saveOauth()
JSONUtils API
JSON assertion library
compareJSONs (Object actualJSON, Object expectedJSON, Object ignoreDiff [optional]) returnType promise: assertion method for comparing json objects Promise returned by it gets resolved if both json objects match else it rejects promise with an error ignoreDiff = { keys : [array of fields to be ignored from comparison]}
verifyArraySubset (Object actualJSONArray, Object expectedJSONArray, Object ignoreDiff [optional]) returnType promise
Assertion method for comparing if actualJSONArray is subset of expectedJSONArray
Promise returned by it gets resolved if actualJSONArray is subset of expectedJSONArray match else it rejects promise with an error
ignoreDiff = { keys : [array of fields to be ignored from comparison]}
ConnectorSyntaxTestHelper API
This method validates syntax of the connector artifacts.
It can be used in unit test as follows:
/* eslint-env mocha */
const ConnectorSyntaxTestHelperClass = require('ptc-flow-test-helper').ConnectorSyntaxTestHelper
const connector = require('../../index')
const ConnectorSyntaxTestHelper = new ConnectorSyntaxTestHelperClass(connector)

describe('usgeocoderConnectorSyntaxTest', ConnectorSyntaxTestHelper.tests())
Was this helpful?