Testing FTP Operations in Ballerina Integrator using Rest Assured Framework

Image for post
Image for post

As described in my previous article, we can write API services using Ballerina Integrator. In this article let’s focus on how we can automate tests using Rest Assured Framework.

You can refer to the ‘Before You Begin’ section in WSO2 Enterprise Integrator Documentation on configuring Ballerina Integrator and Installing VSCode.

Refer to the FTP use cases in WSO2 EI docs in the below links.

  1. https://ei.docs.wso2.com/en/latest/ballerina-integrator/learn/tutorials/file-based-integrations/file-integration-using-ftp/1/
  2. https://ei.docs.wso2.com/en/latest/ballerina-integrator/learn/tutorials/integration-patterns-and-soa/converting-json-to-xml-and-upload-to-ftp/1/

Let’s move into configuring Rest Assured Framework in Eclipse.

  1. Open Eclipse IDE and create an Mvn Project. Let’s name it as FTPOperationTests.
Image for post
Image for post

2. Add the following dependency to your pom file. Then all your mvn dependencies will get downloaded.

3. Let’s create a package in src/test/java. I will name it as basicOperations.

4. Let’s create a class called Crudoperations.java in that package.

5. First, we will write a JSON file to the remote FTP location through the test. I have already created my API which writes a file to a remote FTP server. The service is up and running at http://localhost:9090/company URL. You can refer to this document on implementing that.

6. In order to create a JSON object, I’m using JSON.simple » 1.1.1 dependency. Add the following dependency to your pom file.

7. Since we are using TestNG annotations let’s include that in the pom as well.

8. My testMethod will be as below.

In this method, I’m creating the JSON object and passing it to the request body. Then it calls the POST method providing the URL as the input. I have concatenated the resource to the base URL.

9. Save all and run this as a TestNG test.

10. Let’s move into writing another test case which is reading the file content from the remote FTP server.

My test method will be as below.

In this method, it is appended the resource name and another parameter to the URL, which is the filename since the API resource accepts the file name as a parameter in the implementation.

You can save all and right-click on the project as run as TestNG test.

The complete source for the test class can be found below.

The priority is added as it needs to run in a priority sequence.

You can refer to the implementation of the FTP Operations using Ballerina Integrator through this.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store