-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
393 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
164 changes: 164 additions & 0 deletions
164
judge-d-server/src/test/functional/com/hltech/judged/server/EnvironmentControllerFT.groovy
This file contains 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,164 @@ | ||
package com.hltech.judged.server | ||
|
||
import io.restassured.RestAssured | ||
import org.springframework.boot.web.server.LocalServerPort | ||
import org.springframework.test.context.jdbc.Sql | ||
|
||
@FunctionalTest | ||
class EnvironmentControllerFT extends PostgresDatabaseSpecification { | ||
|
||
@LocalServerPort | ||
int serverPort | ||
|
||
def "should update environment"() { | ||
given: | ||
def environmentName = 'TEST' | ||
|
||
when: | ||
RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.body("""[ | ||
{ | ||
"name": "test1", | ||
"version": "1.0" | ||
}, | ||
{ | ||
"name": "test2", | ||
"version": "1.3" | ||
} | ||
]""") | ||
.when() | ||
.put("/environments/${environmentName}") | ||
.then() | ||
.statusCode(200) | ||
|
||
then: | ||
dbHelper.fetchEnvironments()[0]['name'] == environmentName | ||
def serviceVersions = dbHelper.fetchServiceVersions() | ||
serviceVersions.any { | ||
it['name'] == 'test1' && | ||
it['version'] == "1.0" && | ||
it['environment_name'] == environmentName && | ||
it['space'] == 'default' | ||
} | ||
} | ||
|
||
def "should update environment and replace namespace"() { | ||
given: | ||
def environmentName = 'TEST' | ||
def space = 'testSpace' | ||
|
||
when: | ||
RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.header('X-JUDGE-D-AGENT-SPACE', space) | ||
.body("""[ | ||
{ | ||
"name": "test-service-1", | ||
"version": "1.0" | ||
}, | ||
{ | ||
"name": "test-service-2", | ||
"version": "1.3" | ||
} | ||
]""") | ||
.when() | ||
.put("/environments/${environmentName}") | ||
.then() | ||
.statusCode(200) | ||
|
||
then: | ||
dbHelper.fetchEnvironments()[0]['name'] == environmentName | ||
def serviceVersions = dbHelper.fetchServiceVersions() | ||
serviceVersions.any { | ||
it['name'] == 'test-service-1' && | ||
it['version'] == "1.0" && | ||
it['environment_name'] == environmentName && | ||
it['space'] == space | ||
} | ||
serviceVersions.any { | ||
it['name'] == 'test-service-2' && | ||
it['version'] == "1.3" && | ||
it['environment_name'] == environmentName && | ||
it['space'] == space | ||
} | ||
} | ||
|
||
@Sql("EnvironmentControllerFT.sql") | ||
def "should get all environments"() { | ||
when: | ||
def response = RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.when() | ||
.get("/environments") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.extract().body().jsonPath().getList('$') | ||
|
||
then: | ||
response.containsAll("TEST1", "TEST2") | ||
} | ||
|
||
def "should return empty list if there are no environments"() { | ||
when: | ||
def response = RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.when() | ||
.get("/environments") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.extract().body().jsonPath().getList('$') | ||
|
||
then: | ||
response.size() == 0 | ||
} | ||
|
||
@Sql("EnvironmentControllerFT.sql") | ||
def "should get service names and versions for selected environment"() { | ||
given: | ||
def environmentName = 'TEST1' | ||
when: | ||
def response = RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.when() | ||
.get("/environments/${environmentName}") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.extract().body().jsonPath().getList('$') | ||
|
||
then: | ||
response.any{ | ||
it['name'] == "test-service-1" && | ||
it['version'] == "1.0" | ||
} | ||
response.any{ | ||
it['name'] == "test-service-2" && | ||
it['version'] == "2.0" | ||
} | ||
} | ||
|
||
@Sql("EnvironmentControllerFT.sql") | ||
def "should return empty list when there are no services for selected environment"() { | ||
when: | ||
def response = RestAssured.given() | ||
.port(serverPort) | ||
.contentType("application/json") | ||
.when() | ||
.get("/environments/TEST3") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.extract().body().jsonPath().getList('$') | ||
|
||
then: | ||
response.size() == 0 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
judge-d-server/src/test/functional/com/hltech/judged/server/FileHelper.groovy
This file contains 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,8 @@ | ||
package com.hltech.judged.server | ||
|
||
class FileHelper { | ||
|
||
static loadFromFileAndFormat(String filePath) { | ||
new File("src/test/resources/$filePath").text.replaceAll('\n','').replaceAll('\r','') | ||
} | ||
} |
Oops, something went wrong.