ThingWorx Flow > ThingWorx Flow SDK > Testing Connectors
Testing Connectors
test command
The test command is used to test the connector artifacts. The artifacts have some common and some specific options. The test command takes the type of the artifact as a sub-command. The test command has the following commands:
Commands
Description
flow test action <name>
Tests the action named <name>.
flow test connection <name>
Tests the connection named <name>.
flow test lookup <name> <method>
Tests the lookup function named <method> in lookup <name>.
flow test oauth <name>
Tests the oauth named <name>.
flow test trigger <name> <method>
Tests the trigger named <name>.
The test command has the following options:
Options
Description
Data Type
--version
Displays the version number.
[boolean]
--help
Displays the help.
[boolean]
--timeout
The timeout for the operation. The --timeout option specifies a time-out in milliseconds (defaults to 30000 ms). This option ensures that the code finishes within the specified time and it captures errors, such as missed invocation of callbacks.
[default: 30000]
--logLevel,-1
Sets the log level.
[default: “info”]
ThingWorx Flow CLI allows you to test individual artifacts before deploying the connector on the server. This helps you to check if your artifacts are correctly before.
The test cases are written using the mocha-cha framework. Mocha is used to define the test suite and chai is used as an assertion library. All test cases are defined under the testData folder under a particular an artifact test folder.
The test command allows testing of artifacts in ThingWorx Flow CLI.
To test an artifact, execute the following commands from your command prompt:
1. cd <user project root directory>
2. flow test <artifactType> <name>
Testing an OAuth Configuration
OAuth configuration testing is done through a browser since each OAuth provider has a different form on which to accept user credentials. The CLI internally runs an express web server to process the responses that are sent by the IdP on successful or unsuccessful authentication.
To test an oauth configuration, do the following:
1. From your project directory, execute the following command:
flow test oauth <oauth name>
After successful login, the OAuth validator browser window opens. For more information, refer to the example in the tutorial.
2. Select the configuration to be tested and then click Validate OAuth configuration or click Exit.
Testing a Connection
To test a connection, do the following:
1. From your project directory, execute the following command:
npm install
2. Create a test data file in the package and populate its data with your service provider information.
The file contains sample data for the test connectionTestData in<projectDir>\test\testData as shown in the code that follows.
module.exports = {
sampleInput : {
email : 'your-email-id-here',
subscription_id:'your-subscription-id',
account_url: 'your-account-url',
token: 'your-token'
},
sampleOutput : {
handle: {
email : 'your-email-id-here',
subscription_id:'your-subscription-id',
account_url: 'your-account-url',
token: 'your-token'
} }
}
3. Execute the test command using the following options:
Options
Description
Data Type
--version
Displays the version number.
[boolean]
--help
Displays the help.
[boolean]
--timeout
The timeout for the operation. The --timeout option specifies a time-out in milliseconds (defaults to 30000 ms). This option ensures that the code finishes within the specified time and it captures errors, such as missed invocation of callbacks.
[default: 30000]
--logLevel,-1
Sets the log level.
[default: “info”]
--artifactVersion,-v
Version of the artifact to test.
NA
--projectDir,-d
The parent directory of the project.
NA
--input,-i
Name of the input variable.
NA
--output,-o
Name of the expected output variable.
NA
--testDataFile,-f
Path of the testData file.
NA
--save,-s
Saves to the credential store for a user.
NA
--noSchemaValidation,-n
Disables the schema validation.
[default: false]
Running the test produces output if both the connect and validate method succeed. The command also checks that the input matches the input schema and the output matches the expected output.
Testing Lookups
Lookups have a different structure than other artifacts and are not versioned in the same way as other artifacts. The name itself serves as the version. If newer functionality is required, a new Lookup with a new name is created in the Lookup JavasSript file.using the following command:
flow test lookup <name> <method>
The following options are available:
Options
Description
Data Type
--version
Displays the version number.
[boolean]
--help
Displays the help.
[boolean]
--timeout
The timeout for the operation. The --timeout option specifies a time-out in milliseconds (defaults to 30000 ms). This option ensures that the code finishes within the specified time and it captures errors, such as missed invocation of callbacks.
[default: 30000]
--logLevel,-1
Sets the log level.
[default: “info”]
--projectDir,-d
The parent directory of the project.
NA
--connection,-c
The uid of the connection to inject.
NA
--access_token,-a
Name of the expected output variable.
NA
--input,-i
Path of the testData file.
NA
--output,-o
Name of the expected output variable.
NA
--testDataFile,-f
Path of the testData file.
NA
--searchById
The id to use for search.
NA
--searchByValue
The value to use for search.
NA
--filter
The filter to use to search for items.
NA
Lookups have two search options, searchById, searchByValue and the following three options with respect to pagination.
Lookup returns all data at onceo action required for this option.
Pagination API supported by the applicationhe lookup code calls the getNextPage api and passes it arguments that can help the service return data from the next page. This information is passed to the lookup when the user clicks Load More in the list for the lookup field values.
Pagination not supportedThe application queries the data and the lookup service truncate the data to show only records for the current page and all previous pages.
Testing Actions
Testing actions is similar to testing Lookups.
To test an Action, do the following:
1. Write a sample input and sample output JSON in a test data file. For input and output samples, refer to Appendix B
2. From your project directory, execute the test command using the following options:
Options
Description
Data Type
--version
Displays the version number.
[boolean]
--help
Displays the help.
[boolean]
--timeout
The timeout for the operation. The --timeout option specifies a time-out in milliseconds (defaults to 30000 ms). This option ensures that the code finishes within the specified time and it captures errors, such as missed invocation of callbacks.
[default: 30000]
--logLevel,-1
Sets the log level.
[default: “info”]
--artifactVersion,-v
Version of the artifact to test.
[default: “v1”]
--connection,-c
The uid of the connection to inject.
NA
--access_token,-a
Name of the expected output variable.
NA
--projectDir,-d
The parent directory of the project.
[default: “.”]
--input,-i
Path of the testData file.
NA
--output,-o
Name of the expected output variable.
NA
--testDataFile,-f
Path of the testData file.
NA
--noSchemaValidation,-n
Disables the schema validation.
[default: false]
Testing Triggers
Testing a trigger is slightly different from Actions, Connections, and Lookups. You can execute the test command using the following options:
The following table describes the various options available to test Triggers.
Options
Description
Data Type
--version
Displays the version number.
[boolean]
--help
Displays the help.
[boolean]
--timeout
The timeout for the operation. The --timeout option specifies a time-out in milliseconds (defaults to 30000 ms). This option ensures that the code finishes within the specified time and it captures errors, such as missed invocation of callbacks.
[default: 30000]
--logLevel,-1
Sets the log level.
[default: “info”]
--artifactVersion,-v
Version of the artifact to test.
[default: “v1”]
--connection,-c
The uid of the connection to inject.
NA
--access_token,-a
Name of the expected output variable.
NA
--projectDir,-d
The parent directory of the project.
[default: “.”]
--input,-i
Name of the input variable.
NA
--output,-o
Name of the expected output variable.
NA
--testDataFile,-f
Path of the testData file.
NA
--noSchemaValidation,-n
Disables the schema validation.
[default: false]
--polling,-p
Indicates that the trigger is a polling trigger.
NA
--event,-e
The event to test.
NA
--mockData,-m
The name of the variable holding the mockdata for an event.
NA
--interval,-t
The interval in seconds after which to trigger.
[default: 15]
--stopAfter,-s
Maximum number of calls to the trigger.
[default: 1]
You must specify what method you want to test. For polling triggers, the methods are execute, and activate.
For examples on testing various artifacts, refer to the .
Was this helpful?