The following sections illustrate how to write an integration test class to test the use-case of integrating Google Spreadsheet Connector and Salesforce Streaming Connector based on Synapse artifacts.
ABC is a company that maintains its invoice details in Salesforce. They need to get their invoice details in real-time and store them in a Google spreadsheet using the G oogle Spreadsheet Connector and Salesforce Streaming Connector. They can test this scenario using the Salesforce Creating Records operation by creating an invoice via the Salesforce API.
The following figure depicts the scenario to be tested:
Creating the Maven project template
Follow the steps below to create the Maven project template.
- Create the required Maven project template using the Maven archetype.
Execute the following command to generate the sample Connector code of the Maven project:
Specify the name of the Maven project in camel case when it prompts for the name of the Connector. (E.g.,
This creates the directory
org.wso2.carbon.scenario.salesforcetospreadsheetin the current location of your machine.
org.wso2.carbon.scenario.salesforcetospreadsheet/src/main/directory in the created project.
- Rename the
org.wso2.carbon.scenario.salesforcetospreadsheet/src/test/java/org/wso2/carbon/connector/directory as 'scenario'. (i.e.
- Rename the package as well.
- Rename the
org.wso2.carbon.scenario.salesforcetospreadsheet/src/test/java/org/wso2/carbon/scenario/SalesforceToSpreadsheetConnectorIntegrationTestjava file as
Creating the testing configurations
Follow the steps below to create the required Java files.
org.wso2.carbon.scenario.salesforcetospreadsheet/src/test/java/org/wso2/carbon/scenario/ScenarioIntegrationTestBaseJ ava class as follows .
ScenarioIntegrationTestBase.javaclass contains all the required methods. It extends the
ConnectorIntegrationTestBaseinterface and overrides relevant methods.
Add the test methods in the
SalesforceToSpreadsheetScenarioIntegrationTest.javafile by extending the
ScenarioIntegrationTestBase.javaclass as follows.
Pom.xmlfile as shown below.
Add the correct test class name in the
testng.xmlfile to run your test as follows.
Executing the integration test
Follow the steps below to execute the integration test.
- Download WSO2 ESB 4.9.0.
Enable the below Axis2 configurations in the
Download the inbound
org.apache.synapse.salesforce.poll.class-1.0.0.jarfile from store and copy it to the
Compress the modified ESB distribution (i.e.,
wso2esb-4.9.0.zip) and copy that ZIP file to the
from OAuth 2.0 Playground using the following URL: https://developers.google.com/oauthplayground/ Create an access token and a refresh token
The application needs access to user data. It inquires Google for a particular scope of access. For OAuth 2.0 scope information for the Google Sheets API, see Feeds.
Set up the Google Spreadsheet environment as follows:
Create the following directories inside the
<SCENARIO_HOME>/src/test/resources/artifacts/ESB/config/directory by adding the corresponding configurations.
inboundEndpoints/scenario/directory and add the Inbound Endpoint configuration file (
saleforceInboundEP.xml) to it with the below content.
saleforceInboundEP.xmlfile acts as a message consumer. It creates a connection to a Salesforce account and in the backend, the Salesforce streaming API receives notifications for changes to Salesforce data that match the SOQL query you define. This
saleforceInboundEPconsumes the Salesforce data from Salesforce streaming API and injects the data to the ESB sequence (i.e.,
proxies/scenario/directory and add the Proxy Service configuration file
(createInvoice.xml)to it with the below content.
createInvoiceproxy service uses the
createoperation from the Salesforce connector to create a record in custom object '
Invoice_Statement__c' in Salesforce API to test this scenario.
- Create the
resources/scenario/directory and add the Connector zip files
(salesforce-connector & googlespreadsheet-connector)to it.
restRequests/scenario/directory and add the JSON request file to invoke the proxy service
(createInvoice.json)to it with the below content.
This request body is used by the
createInvoiceproxy service to make the call from the Salesforce Connector.
sequences/scenario/directory and add the Sequence files (
.xml) to it with the below content.
The consumed data from Salesforce streaming API will be injected to this Sequence. The Sequence does the following actions:
Check the existence of the given Spreadsheet by its name using the
getSpreadsheetByTitleoperation. If that is not already created, this Sequence will break the flow and call the
If the Spreadsheet is available, it checks the existence of the Worksheet in that Spreadsheet by the name of the worksheet using the
getWorksheetByTitleoperation. If that worksheet is not available, this sequence will add a Worksheet with the given name by using the
addWorksheetoperation. It will then break the flow and call the
responsesequencesequence with the message, which adds a header row in the created Worksheet.
- If both the Spreadsheet and Worksheet are available, this sequence will use the
insertRowsoperation to insert a row with the specific fields from the consumed data.
- Rename the
connector/directory as '
- Rename the
propertiesfile as '
Enter valid values for the following properties in the
Use the Refresh token got in step 5.
Use the Client ID used to generate the access token.
Use the Client Secret used to generate the access token.
Use the accessToken got in step 5.
Use appropriate API version.
Use the API URL of the google spreadsheet.
Use the title of the spreadsheet created in step 6.
Use a required number of row to a new worksheet.
Use a required number of column to a new worksheet.
Use the title of worksheet created in step 6.
Follow the steps below to set up the Salesforce environment.
- Create a Salesforce account.
- Create an object in Salesforce using the following URL: https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/create_object.htm#create_object
Create a push topic using the following URL: https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/create_a_pushtopic.htm
Use this push topic name in the Inbound Endpoint configuration.
Update the following properties in the
sfusername: use username of the salesforce account.
sfpassword: use the password of the salesforce account.
loginUrl: use login URL of the salesforce account.
sfstatus: use the status of the invoice e.g: Open, Closed, Negotiating and Pending
sfdescription: use description about that invoice entry
sObjectType: use the type of the sObject created in step 10.
Check if the following relative paths are stated properly in the properties file.
Navigate to the
<SCENARIO_HOME>/directory and execute the following command to execute your test classes and generate the reports in
For the sample, go to Github.