This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
forked from iguissouma/chutney-kotlin-dsl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow http client to receive empty response (#135)
- Loading branch information
1 parent
b327e84
commit 9c97741
Showing
8 changed files
with
502 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package blackbox | ||
|
||
import com.chutneytesting.kotlin.util.ChutneyServerInfo | ||
import com.chutneytesting.kotlin.util.HttpClient | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.AfterAll | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.testcontainers.containers.BindMode | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.junit.jupiter.Testcontainers | ||
import java.io.File | ||
import java.nio.file.Files | ||
|
||
@Testcontainers | ||
class IntegrationTest { | ||
|
||
companion object { | ||
var chutneyServer: GenericContainer<Nothing>? = null | ||
var adminServerInfo: ChutneyServerInfo? = null | ||
var userServerInfo: ChutneyServerInfo? = null | ||
|
||
@JvmStatic | ||
@BeforeAll | ||
fun setUp() { | ||
val tempDirectory = Files.createTempDirectory("chutney-kotlin-blackbox") | ||
val memAuthConfigFile = File( | ||
IntegrationTest::class.java.getResource("/blackbox/application-mem-auth.yml")!!.path | ||
) | ||
|
||
// Copy mem-auth config | ||
Files.copy(memAuthConfigFile.toPath(), tempDirectory.resolve("application-mem-auth.yml")) | ||
|
||
// Start server | ||
chutneyServer = GenericContainer<Nothing>("ghcr.io/chutney-testing/chutney/server:latest") | ||
.apply { | ||
//withStartupTimeout(Duration.ofSeconds(30)) | ||
withExposedPorts(8443) | ||
withFileSystemBind(tempDirectory.toString(), "/config", BindMode.READ_WRITE) | ||
} | ||
chutneyServer!!.start() | ||
adminServerInfo = | ||
ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "admin", "admin") | ||
userServerInfo = | ||
ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "user", "user") | ||
|
||
// Set authorizations | ||
val roles = IntegrationTest::class.java.getResource("/blackbox/roles.json")!!.path | ||
HttpClient.post<Any>(adminServerInfo!!, "/api/v1/authorizations", File(roles).readText()) | ||
} | ||
|
||
@JvmStatic | ||
@AfterAll | ||
fun cleanUp() { | ||
chutneyServer?.stop() | ||
} | ||
} | ||
|
||
@Test | ||
fun create_update_scenario_with_specific_ids() { | ||
// Given | ||
var body = """ | ||
{ | ||
"id": "1234", | ||
"title": "My scenario", | ||
"content": "{\"when\": {}}", | ||
"description": "My scenario description", | ||
"tags": [], | ||
"defaultDataset": null | ||
} | ||
""".trimIndent() | ||
|
||
// Create scenario | ||
var result = HttpClient.post<String>(adminServerInfo!!, "/api/scenario/v2/raw", body) | ||
assertThat(result).isEqualTo("1234") | ||
|
||
// Update scenario | ||
body = """ | ||
{ | ||
"id": "1234", | ||
"title": "My new title", | ||
"content": "{\"when\": {}}", | ||
"description": "My new scenario description", | ||
"tags": ["A_TAG"], | ||
"defaultDataset": null, | ||
"version": 1 | ||
} | ||
""".trimIndent() | ||
result = HttpClient.post<String>(adminServerInfo!!, "/api/scenario/v2/raw", body) | ||
assertThat(result).isEqualTo("1234") | ||
|
||
// Then | ||
val resultRaw = HttpClient.get<Map<String, Any>>(userServerInfo!!, "/api/scenario/v2/raw/1234") | ||
assertThat(resultRaw) | ||
.containsEntry("id", "1234") | ||
.containsEntry("title", "My new title") | ||
.containsEntry("description", "My new scenario description") | ||
.containsEntry("tags", listOf("A_TAG")) | ||
} | ||
|
||
@Test | ||
fun create_update_campaign_with_specific_ids() { | ||
// Given | ||
val scenarioIdA = createEmptyScenario() | ||
val scenarioIdB = createEmptyScenario() | ||
|
||
// Create campaign | ||
var body = """ | ||
{ | ||
"id": 1234, | ||
"title": "My campaign", | ||
"description": "", | ||
"scenarioIds": ["$scenarioIdA"], | ||
"environment": "DEFAULT", | ||
"parallelRun": false, | ||
"retryAuto": false, | ||
"datasetId": null, | ||
"tags": [] | ||
} | ||
""".trimIndent() | ||
var result = HttpClient.post<HashMap<String, Any>>(adminServerInfo!!, "/api/ui/campaign/v1", body) | ||
assertThat(result) | ||
.containsEntry("id", 1234) | ||
.containsEntry("scenarioIds", listOf(scenarioIdA)) | ||
|
||
// Update campaign | ||
body = """ | ||
{ | ||
"id": 1234, | ||
"title": "My new campaign", | ||
"description": "My new campaign description", | ||
"scenarioIds": ["$scenarioIdB"], | ||
"environment": "DEFAULT", | ||
"parallelRun": false, | ||
"retryAuto": false, | ||
"datasetId": null, | ||
"tags": ["A_TAG"] | ||
} | ||
""".trimIndent() | ||
result = HttpClient.post<HashMap<String, Any>>(adminServerInfo!!, "/api/ui/campaign/v1", body) | ||
assertThat(result) | ||
.containsEntry("id", 1234) | ||
.containsEntry("scenarioIds", listOf(scenarioIdB)) | ||
|
||
// Then | ||
val resultRaw = HttpClient.get<Map<String, Any>>(userServerInfo!!, "/api/ui/campaign/v1/1234") | ||
assertThat(resultRaw) | ||
.containsEntry("id", 1234) | ||
.containsEntry("title", "My new campaign") | ||
.containsEntry("description", "My new campaign description") | ||
.containsEntry("scenarioIds", listOf(scenarioIdB)) | ||
.containsEntry("tags", listOf("A_TAG")) | ||
} | ||
|
||
private fun createEmptyScenario(): String { | ||
val body = """ | ||
{ | ||
"title": "Empty scenario", | ||
"content": "{\"when\": {}}", | ||
"tags": [] | ||
} | ||
""".trimIndent() | ||
return HttpClient.post<String>(adminServerInfo!!, "/api/scenario/v2/raw", body) | ||
} | ||
} |
Oops, something went wrong.