-
Notifications
You must be signed in to change notification settings - Fork 0
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
kamil.jedrzejuk
committed
Oct 7, 2024
1 parent
1c83255
commit 7f72fb6
Showing
27 changed files
with
546 additions
and
48 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
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
19 changes: 19 additions & 0 deletions
19
...kotlin/camilyed/github/io/currencyexchangeapi/testing/abilties/ExchangePlnToUsdAbility.kt
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,19 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.abilties | ||
|
||
import camilyed.github.io.currencyexchangeapi.testing.builders.ExchangePlnToUsdJsonBuilder | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.ResponseEntity | ||
|
||
interface ExchangePlnToUsdAbility : MakeRequestAbility { | ||
fun exchangePlnToUsd(builder: ExchangePlnToUsdJsonBuilder): ResponseEntity<String> { | ||
val exchangeJson = builder.build() | ||
val httpHeaders = HttpHeaders() | ||
httpHeaders["X-Request-Id"] = builder.xRequestId | ||
return put( | ||
url = "/api/accounts//exchange-pln-to-usd", | ||
body = exchangeJson, | ||
headers = httpHeaders, | ||
responseType = String::class.java, | ||
) | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
.../camilyed/github/io/currencyexchangeapi/testing/abilties/GetCurrentExchangeRateAbility.kt
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
37 changes: 37 additions & 0 deletions
37
...kotlin/camilyed/github/io/currencyexchangeapi/testing/assertion/ExchangeToUsdAssertion.kt
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,37 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.assertion | ||
|
||
import camilyed.github.io.currencyexchangeapi.testing.utils.parseBodyToType | ||
import org.springframework.http.ResponseEntity | ||
import strikt.api.Assertion.Builder | ||
|
||
fun Builder<ResponseEntity<String>>.hasPlnAmount(expectedPlnAmount: String): Builder<ResponseEntity<String>> = | ||
assert("should contain correct PLN amount") { | ||
val body = parseBodyToType<Map<String, Any>>(it) | ||
|
||
val actualPlnAmount = | ||
body["balancePln"] as? String ?: fail( | ||
"Response does not contain 'balancePln' or 'plnAmount' is not a String", | ||
) | ||
|
||
if (actualPlnAmount == expectedPlnAmount) { | ||
pass() | ||
} else { | ||
fail("Expected PLN amount: $expectedPlnAmount, but got $actualPlnAmount") | ||
} | ||
} | ||
|
||
fun Builder<ResponseEntity<String>>.hasUsdAmount(expectedUsdAmount: String): Builder<ResponseEntity<String>> = | ||
assert("should contain correct USD amount") { | ||
val body = parseBodyToType<Map<String, Any>>(it) | ||
|
||
val actualUsdAmount = | ||
body["balanceUsd"] as? String ?: fail( | ||
"Response does not contain 'balanceUsd' or 'balanceUsd' is not a String", | ||
) | ||
|
||
if (actualUsdAmount == expectedUsdAmount) { | ||
pass() | ||
} else { | ||
fail("Expected USD amount: $expectedUsdAmount, but got $actualUsdAmount") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...in/camilyed/github/io/currencyexchangeapi/testing/builders/ExchangePlnToUsdJsonBuilder.kt
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,46 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.builders | ||
|
||
import java.util.UUID | ||
|
||
class ExchangePlnToUsdJsonBuilder { | ||
var accountId: String? = UUID.randomUUID().toString() | ||
var amount: String? = "100.00" | ||
var xRequestId: String? = UUID.randomUUID().toString() | ||
|
||
fun withAccountId(accountId: String) = apply { | ||
this.accountId = accountId | ||
} | ||
|
||
fun withAmount(amount: String) = apply { | ||
this.amount = amount | ||
} | ||
|
||
fun withXRequestId(xRequestId: String) = apply { | ||
this.xRequestId = xRequestId | ||
} | ||
|
||
fun withoutXRequestId() = apply { | ||
this.xRequestId = null | ||
} | ||
|
||
fun withoutAccountId() = apply { | ||
this.accountId = null | ||
} | ||
|
||
fun withoutAmount() = apply { | ||
this.amount = null | ||
} | ||
|
||
fun build(): Map<String, Any?> { | ||
return mapOf( | ||
"accountId" to accountId, | ||
"amount" to amount, | ||
) | ||
} | ||
|
||
companion object { | ||
fun anExchangePlnToUsd(): ExchangePlnToUsdJsonBuilder { | ||
return ExchangePlnToUsdJsonBuilder() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rationTest/kotlin/camilyed/github/io/currencyexchangeapi/testing/config/WireMockConfig.kt
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,19 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.config | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Primary | ||
|
||
@Configuration | ||
class WireMockConfig { | ||
|
||
@Bean | ||
@Primary | ||
fun wireMockServer(): WireMockServer { | ||
val wireMockServer = WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()) | ||
wireMockServer.start() | ||
return wireMockServer | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...rationTest/kotlin/camilyed/github/io/currencyexchangeapi/testing/utils/DatabaseCleaner.kt
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,16 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.utils | ||
|
||
import org.jetbrains.exposed.sql.transactions.TransactionManager | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
object DatabaseCleaner { | ||
|
||
fun cleanAllTables() { | ||
transaction { | ||
val tables = TransactionManager.current().db.dialect.allTablesNames() | ||
tables.forEach { tableName -> | ||
exec("DELETE FROM $tableName") | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...grationTest/kotlin/camilyed/github/io/currencyexchangeapi/testing/utils/ResponseParser.kt
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,10 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.utils | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.springframework.http.ResponseEntity | ||
|
||
val objectMapper = jacksonObjectMapper() | ||
|
||
inline fun <reified T> parseBodyToType(response: ResponseEntity<String>): T { | ||
return objectMapper.readValue(response.body!!, T::class.java) | ||
} |
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
Oops, something went wrong.