Testing FTP Operations in Ballerina Integrator using Rest Assured Framework
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.
Let’s move into configuring Rest Assured Framework in Eclipse.
- Open Eclipse IDE and create an Mvn Project. Let’s name it as FTPOperationTests.
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.
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.