Skip to content
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

API test (Using API Spec) generated by RoostGPT #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
</build>
<dependencies>
Expand Down Expand Up @@ -61,5 +67,24 @@
<scope>compile</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
<version>1.4.1</version>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>io.karatelabs</groupId>
<artifactId>karate-debugserver</artifactId>
<version>0.1.0</version>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>1.4.1</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>
</project>
26 changes: 26 additions & 0 deletions src/test/java/org/springframework/api_tests/ApiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

package org.springframework.api_tests;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
// import com.intuit.karate.http.HttpServer;
// import com.intuit.karate.http.ServerConfig;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ApiTest {

@Test
void testAll() {
String apiHostServer = System.getenv().getOrDefault("API_HOST", "https://api.nobelprize.org/");
String authtoken = System.getenv().getOrDefault("AUTH_TOKEN", "dummy AUTH_TOKEN");
Results results = Runner.path("classpath:org/springframework/api_tests")
.systemProperty("url.base", apiHostServer)
.systemProperty("AUTH_TOKEN", authtoken)
.reportDir("testReport")
.parallel(1);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# ********RoostGPT********

# Test generated by RoostGPT for test claude-karate-apitest using AI Type Claude AI and AI Model claude-3-opus-20240229
#
# Feature file generated for /laureate/{laureateID}_get for http method type GET
# RoostTestHash=3a8d014c99
#
#

# ********RoostGPT********
Feature: Nobel Prize Laureate API

Background:
* def urlBase = karate.properties['url.base'] || karate.get('urlBase', 'http://localhost:8080')
* url urlBase
* def authToken = karate.properties['AUTH_TOKEN']
* configure headers = { 'Authorization': '#(authToken)' }

Scenario Outline: Get Laureate by ID - Successful Response
Given path '/2.1/laureate/<laureateID>'
When method GET
Then status 200
And match response ==
"""
{
"laureate": {
"id": "#number",
"laureateIfPerson": {
"knownName": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"givenName": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"familyName": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"fullName": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"filename": "#string",
"penname": "##string",
"gender": "##string",
"birth": {
"date": "#string",
"place": {
"city": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"country": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"cityNow": {
"en": "#string",
"se": "#string",
"false": "##string",
"sameAs": "##array"
},
"countryNow": {
"en": "#string",
"se": "#string",
"false": "##string",
"sameAs": "##array"
},
"continent": {
"en": "#string",
"se": "#string",
"false": "##string"
},
"locationString": {
"en": "#string",
"se": "#string",
"false": "##string"
}
}
},
"death": "##object"
},
"laureateIfOrg": "##object",
"nobelPrizes": "#array"
}
}
"""
And match response.laureate.id == <laureateID>
And match response.laureate.nobelPrizes[*].awardYear contains <awardYear>
And match response.laureate.nobelPrizes[*].category.en contains <category>

Examples:
| laureateID | awardYear | category |
| 1 | 1901 | "Peace" |
| 100 | 1970 | "Physics" |
| 500 | 2000 | "Literature" |

Scenario: Get Laureate by ID - Invalid ID
Given path '/2.1/laureate/0'
When method GET
Then status 400
And match response ==
"""
{
"code": "#string",
"message": "#string"
}
"""
And match response.code == "400"
And match response.message contains "malformed syntax"

Scenario: Get Laureate by ID - Non-existent ID
Given path '/2.1/laureate/9999'
When method GET
Then status 404
And match response ==
"""
{
"code": "#string",
"message": "#string"
}
"""
And match response.code == "404"
And match response.message contains "could not be found"
96 changes: 96 additions & 0 deletions src/test/java/org/springframework/api_tests/laureates_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ********RoostGPT********

# Test generated by RoostGPT for test claude-karate-apitest using AI Type Claude AI and AI Model claude-3-opus-20240229
#
# Feature file generated for /laureates_get for http method type GET
# RoostTestHash=bb9ad621b1
#
#

# ********RoostGPT********
Feature: Nobel Prize Laureates API

Background:
* url 'https://api.nobelprize.org/2.1'
* def authToken = karate.properties['AUTH_TOKEN']
* def defaultOffset = 0
* def defaultLimit = 20
* def defaultSort = 'asc'

Scenario: Get all Nobel Prize Laureates
Given path '/laureates'
And header Authorization = 'Bearer ' + authToken
When method GET
Then status 200
And match response.laureates == '#array'
And match each response.laureates contains { id: '#number', knownName: '#object' }
And match response.meta.count == '#number'

Scenario Outline: Get Nobel Prize Laureates with query parameters
Given path '/laureates'
And header Authorization = 'Bearer ' + authToken
And param offset = <offset>
And param limit = <limit>
And param sort = <sort>
And param name = <name>
And param gender = <gender>
And param motivation = <motivation>
And param affiliation = <affiliation>
And param residence = <residence>
And param birthDate = <birthDate>
And param birthDateTo = <birthDateTo>
And param deathDate = <deathDate>
And param deathDateTo = <deathDateTo>
And param foundedDate = <foundedDate>
And param birthCity = <birthCity>
And param birthCountry = <birthCountry>
And param birthContinent = <birthContinent>
And param deathCity = <deathCity>
And param deathCountry = <deathCountry>
And param deathContinent = <deathContinent>
And param foundedCity = <foundedCity>
And param foundedCountry = <foundedCountry>
And param foundedContinent = <foundedContinent>
And param headquartersCity = <headquartersCity>
And param headquartersCountry = <headquartersCountry>
And param headquartersContinent = <headquartersContinent>
And param nobelPrizeYear = <nobelPrizeYear>
And param yearTo = <yearTo>
And param nobelPrizeCategory = <nobelPrizeCategory>
And param format = <format>
And param csvLang = <csvLang>
When method GET
Then status 200
And match response.laureates == '#array'
And match each response.laureates contains { id: '#number', knownName: '#object' }
And match response.meta.count == '#number'

Examples:
| offset | limit | sort | name | gender | motivation | affiliation | residence | birthDate | birthDateTo | deathDate | deathDateTo | foundedDate | birthCity | birthCountry | birthContinent | deathCity | deathCountry | deathContinent | foundedCity | foundedCountry | foundedContinent | headquartersCity | headquartersCountry | headquartersContinent | nobelPrizeYear | yearTo | nobelPrizeCategory | format | csvLang |
| 0 | 10 | "asc" | "Albert" | "male" | "peace" | "CERN" | "Geneva" | "1950" | "1960" | "2000" | "2010" | "1980" | "Ulm" | "Germany" | "Europe" | "Bern" | "Switzerland" | "Europe" | "Geneva" | "Switzerland" | "Europe" | "Geneva" | "Switzerland" | "Europe" | 1921 | 1950 | "phy" | "json" | "en" |

Scenario: Get Nobel Prize Laureate by ID
Given path '/laureates'
And header Authorization = 'Bearer ' + authToken
And param id = 123
When method GET
Then status 200
And match response.laureates == '#array'
And match response.laureates[0].id == 123

Scenario: Get Nobel Prize Laureates with invalid query parameters
Given path '/laureates'
And header Authorization = 'Bearer ' + authToken
And param invalidParam = "invalidValue"
When method GET
Then status 400
And match response.code == "400"
And match response.message == "Bad Request"

Scenario: Get Nobel Prize Laureates with non-existent resource
Given path '/laureates/non-existent'
And header Authorization = 'Bearer ' + authToken
When method GET
Then status 404
And match response.code == "404"
And match response.message == "Not Found"
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ********RoostGPT********

# Test generated by RoostGPT for test claude-karate-apitest using AI Type Claude AI and AI Model claude-3-opus-20240229
#
# Feature file generated for /nobelPrize/{category}/{year}_get for http method type GET
# RoostTestHash=adfce3f1d2
#
#

# ********RoostGPT********
Feature: Nobel Prize API

Background:
* def urlBase = karate.properties['url.base'] || karate.get('urlBase', 'http://localhost:8080')
* url urlBase
* def authToken = karate.properties['AUTH_TOKEN']

Scenario Outline: Get Nobel Prize information by category and year
Given path '/2.1/nobelPrize/<category>/<year>'
And header Authorization = authToken
When method GET
Then status 200
And match response.nobelPrize.awardYear == <year>
And match response.nobelPrize.category.en == '#string'
And match response.nobelPrize.categoryFullName.en == '#string'
And match response.nobelPrize.dateAwarded == '#regex \\d{4}-\\d{2}-\\d{2}'
And match response.nobelPrize.prizeAmount == '#number'
And match response.nobelPrize.prizeAmountAdjusted == '#number'
And match response.nobelPrize.topMotivation.en == '#string'
And match each response.nobelPrize.laureates ==
"""
{
id: '#number',
name: {
en: '#string'
},
portion: '#regex (1|1/2|1/3|1/4)',
sortOrder: '#regex (1|2|3)',
motivation: {
en: '#string'
},
links: '#array'
}
"""

Examples:
| category | year |
| che | 1901 |
| eco | 2010 |
| lit | 1950 |
| pea | 2000 |
| phy | 1980 |
| med | 1990 |

Scenario Outline: Get Nobel Prize information with invalid category or year
Given path '/2.1/nobelPrize/<category>/<year>'
And header Authorization = authToken
When method GET
Then status 400
And match response ==
"""
{
code: '#string',
message: '#string'
}
"""

Examples:
| category | year |
| invalid | 1901 |
| che | 1800 |
| eco | 99999 |

Scenario: Get Nobel Prize information with missing authorization token
Given path '/2.1/nobelPrize/che/1901'
When method GET
Then status 401
Loading