forked from medeirosdev/API-MusicBlender-Java
- Notifications
You must be signed in to change notification settings - Fork 1
Rest Assured test generated by RoostGPT #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BhhavyaRSureka wants to merge 2 commits into master Choose a base branch from roost-1706858441
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits Select commit Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions 111 src/test/java/com/medeiros/RoostTest/TestdataLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| | ||
| package com.medeiros.RoostTest; | ||
| import java.io.BufferedReader; | ||
| import java.io.FileReader; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import java.util.Arrays; | ||
| | ||
| public class TestdataLoader { | ||
| | ||
| private String fromENV(String name) { | ||
| return System.getenv(name); | ||
| } | ||
| | ||
| private String fromPropertiesFile(String name) { | ||
| Properties properties = new Properties(); | ||
| try (InputStream input = getClass().getClassLoader().getResourceAsStream("application.properties")) { | ||
| if (input == null) { | ||
| System.out.println("Sorry, unable to find application.properties"); | ||
| return null; | ||
| } | ||
| properties.load(input); | ||
| return properties.getProperty(name); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| return null; | ||
| } | ||
| } | ||
| | ||
| private List<Map<String, String>> fromCSVFile(String filePath) { | ||
| List<Map<String, String>> data = new ArrayList<>(); | ||
| | ||
| try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { | ||
| String line; | ||
| boolean headerSkipped = false; | ||
| List<String> headers = new ArrayList<>(); | ||
| | ||
| while ((line = br.readLine()) != null) { | ||
| if (!headerSkipped) { | ||
| headers.addAll(List.of(line.split(","))); | ||
| headerSkipped = true; | ||
| continue; | ||
| } | ||
| | ||
| String[] values = line.split(","); | ||
| if (values.length > 0) { | ||
| Map<String, String> row = new HashMap<>(); | ||
| for (int i = 0; i < Math.min(headers.size(), values.length); i++) { | ||
| row.put(headers.get(i), values[i].trim()); | ||
| } | ||
| data.add(row); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| | ||
| return data; | ||
| } | ||
| | ||
| public List<Map<String, String>> loadData(String csvFileName) { | ||
| Map<String, String> envMap = new HashMap<>(); | ||
| List<Map<String, String>> csvData = this.fromCSVFile(csvFileName); | ||
| Map<String, String> envMapwithCSV = new HashMap<>(); | ||
| List<Map<String, String>> envVars = new ArrayList<>(); | ||
| String[] envVarsList = this.getEnvVariableList(csvFileName); | ||
| | ||
| for (String key : envVarsList) { | ||
| envMap.put(key, ""); | ||
| String value = this.fromENV(key); | ||
| if (value != null) { | ||
| envMap.put(key, value); | ||
| } | ||
| value = this.fromPropertiesFile(key); | ||
| if (value != null) { | ||
| envMap.put(key, value); | ||
| } | ||
| } | ||
| for (Map<String, String> row : csvData) { | ||
| envMapwithCSV.putAll(envMap); | ||
| for (Map.Entry<String, String> entry : row.entrySet()) { | ||
| String key = entry.getKey(); | ||
| String value = entry.getValue(); | ||
| if (!value.equals("")) { | ||
| envMapwithCSV.put(key, value); | ||
| } | ||
| } | ||
| envVars.add(envMapwithCSV); | ||
| } | ||
| return envVars; | ||
| } | ||
| | ||
| private String[] getEnvVariableList(String csvFileName) { | ||
| String[] envVars = { "BASE_URL", "API_KEY" }; | ||
| try (BufferedReader reader = new BufferedReader(new FileReader(csvFileName))) { | ||
| String headerLine = reader.readLine(); | ||
| String[] csvHeaders = headerLine.split(","); | ||
| String[] finalEnvArray = Arrays.copyOfRange(envVars, 0, envVars.length + csvHeaders.length); | ||
| System.arraycopy(csvHeaders, 0, finalEnvArray, envVars.length, csvHeaders.length); | ||
| return finalEnvArray; | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return envVars; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions 11 src/test/java/com/medeiros/RoostTest/transactionsGetTest.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| company,from,offset,limit,statusCode | ||
| 23495,2023-11-27T11:28:37+01:00,0,25,200 | ||
| 38492,2024-05-15T10:18:23+01:00,10,15,200 | ||
| 57843,2022-12-30T15:45:12+01:00,20,30,200 | ||
| 12984,2025-01-20T09:30:45+01:00,30,20,200 | ||
| 64921,2023-06-10T08:25:50+01:00,40,10,200 | ||
| 39284,2022-08-01T07:14:35+01:00,50,5,200 | ||
| 28493,2024-02-28T16:38:29+01:00,60,40,200 | ||
| 94823,2025-07-25T13:52:41+01:00,70,35,200 | ||
| 58392,2023-03-15T12:46:53+01:00,80,45,200 | ||
| 49238,2022-09-10T11:41:06+01:00,90,50,200 |
65 changes: 65 additions & 0 deletions 65 src/test/java/com/medeiros/RoostTest/transactionsGetTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // ********RoostGPT******** | ||
| /* | ||
| Test generated by RoostGPT for test ReatAssured-Test using AI Type Open AI and AI Model gpt-4 | ||
| | ||
| Test generated for /api/customer/transactions_get for http method type GET in rest-assured framework | ||
| | ||
| RoostTestHash=c35c7610a4 | ||
| | ||
| | ||
| */ | ||
| | ||
| // ********RoostGPT******** | ||
| package com.medeiros.RoostTest; | ||
| import io.restassured.RestAssured; | ||
| import io.restassured.http.ContentType; | ||
| import io.restassured.response.Response; | ||
| import org.junit.Before; | ||
| import org.junit.jupiter.api.Test; | ||
| import static io.restassured.RestAssured.given; | ||
| import static org.junit.Assert.*; | ||
| import java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.hamcrest.MatcherAssert; | ||
| import static org.hamcrest.Matchers.*; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| | ||
| public class transactionsGetTest { | ||
| | ||
| List<Map<String, String>> envList = new ArrayList<>(); | ||
| | ||
| | ||
| @Before | ||
| public void setUp() { | ||
| TestdataLoader dataloader = new TestdataLoader(); | ||
| envList = dataloader.loadData("src/test/java/com/medeiros/RoostTest/transactionsGetTest.csv"); | ||
| } | ||
| | ||
| | ||
| @Test | ||
| public void transactionsGet_Test() { | ||
| this.setUp(); | ||
| for (Map<String, String> map : envList) { | ||
| RestAssured.baseURI = map.get("BASE_URL"); | ||
| | ||
| Response response = given() | ||
| .queryParam("company", map.get("company") != null ? map.get("company") : "") | ||
| .header("Authorization", "Bearer " + map.get("AUTH_TOKEN")) | ||
| .when() | ||
| .get("/api/customer/transactions") | ||
| .then() | ||
| .extract().response(); | ||
| | ||
| if (response.statusCode() == 200) { | ||
| System.out.println("Description: Get CustomerTransaction"); | ||
| } | ||
| | ||
| } | ||
| } | ||
| } |
16 changes: 8 additions & 8 deletions 16 src/test/java/com/medeiros/SPRINGProject/SpringProjectApplicationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| package com.medeiros.SPRINGProject; | ||
| | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| // import org.junit.jupiter.api.Test; | ||
| // import org.springframework.boot.test.context.SpringBootTest; | ||
| | ||
| @SpringBootTest | ||
| class SpringProjectApplicationTests { | ||
| // @SpringBootTest | ||
| // class SpringProjectApplicationTests { | ||
| | ||
| @Test | ||
| void contextLoads() { | ||
| } | ||
| // @Test | ||
| // void contextLoads() { | ||
| // } | ||
| | ||
| } | ||
| // } |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added dependencies were missing.
FIX :- Added the necessary dependencies needed for the imports.