aboutsummaryrefslogtreecommitdiff
path: root/merchant-lib/src/test/java/net/taler
diff options
context:
space:
mode:
Diffstat (limited to 'merchant-lib/src/test/java/net/taler')
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt3
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt12
2 files changed, 13 insertions, 2 deletions
diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
index 8a45c9f..a89e2d3 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
@@ -20,6 +20,7 @@ import io.ktor.http.HttpStatusCode.Companion.NotFound
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
+import kotlinx.coroutines.test.UnconfinedTestDispatcher
import net.taler.common.Amount
import net.taler.common.ContractProduct
import net.taler.common.ContractTerms
@@ -33,7 +34,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class MerchantApiTest {
- private val api = MerchantApi(httpClient, TestCoroutineDispatcher())
+ private val api = MerchantApi(httpClient, UnconfinedTestDispatcher())
private val merchantConfig = MerchantConfig(
baseUrl = "http://example.net/instances/testInstance",
apiKey = "apiKeyFooBar"
diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
index 880228c..32c7ee1 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
@@ -20,6 +20,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.engine.mock.MockEngine
import io.ktor.client.engine.mock.MockEngineConfig
import io.ktor.client.engine.mock.respond
+import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpStatusCode
import io.ktor.http.Url
@@ -27,6 +28,8 @@ import io.ktor.http.content.TextContent
import io.ktor.http.fullPath
import io.ktor.http.headersOf
import io.ktor.http.hostWithPort
+import io.ktor.serialization.kotlinx.json.json
+import kotlinx.serialization.json.Json
import kotlinx.serialization.json.Json.Default.parseToJsonElement
import org.junit.Assert.assertEquals
@@ -36,13 +39,20 @@ object MockHttpClient {
engine {
addHandler { error("No response handler set") }
}
+ expectSuccess = true
+ install(ContentNegotiation) {
+ json(Json {
+ encodeDefaults = false
+ ignoreUnknownKeys = true
+ })
+ }
}
fun HttpClient.giveJsonResponse(
url: String,
expectedBody: String? = null,
statusCode: HttpStatusCode = HttpStatusCode.OK,
- jsonProducer: () -> String
+ jsonProducer: () -> String,
) {
val httpConfig = engineConfig as MockEngineConfig
httpConfig.requestHandlers.removeAt(0)