diff --git a/README.md b/README.md
index 1b467bd4..68557f2a 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,7 @@ file.
```groovy
dependencies {
- implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.10.1-SNAPSHOT"
+ implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.10.2-SNAPSHOT"
implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05"
}
```
@@ -159,8 +159,11 @@ val verifierApiUri = "https://verifier-api-uri"
val config = EudiWalletConfig.Builder(applicationContext)
.logLevel(Logger.LEVEL_DEBUG)
.ktorHttpClientFactory {
- // provide your own Ktor HttpClient
- // this will be used for OpenId4VCI and OpenId4VP communication
+ // Provide your own Ktor HttpClient.
+ // This will be used for OpenId4VCI and OpenId4VP communication.
+ // If a httpClient is not provided, the library will create a default one.
+ // For every httpClientFactory, the result httpClient will be configured
+ // for logging (when logLevel is set to debug) and with json content negotiation
}
.bleTransferMode(
EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE,
diff --git a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/index.md b/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/index.md
index 8c3c4357..c1449732 100644
--- a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/index.md
+++ b/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/index.md
@@ -23,13 +23,13 @@ androidJvm
## Functions
-| Name | Summary |
-|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| [build](build.md) | [androidJvm]
fun [build](build.md)(): [OpenId4VciManager](../index.md)
Build the [OpenId4VciManager](../index.md) |
-| [config](config.md) | [androidJvm]
fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)
Set the [Config](../-config/index.md) to use |
-| [documentManager](document-manager.md) | [androidJvm]
fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)
Set the DocumentManager to use |
-| [ktHttpClientFactory](kt-http-client-factory.md) | [androidJvm]
fun [ktHttpClientFactory](kt-http-client-factory.md)(factory: () -> HttpClient): [OpenId4VciManager.Builder](index.md)
Override the Ktor HTTP client factory |
-| [logger](logger.md) | [androidJvm]
fun [logger](logger.md)(logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md) |
+| Name | Summary |
+|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| [build](build.md) | [androidJvm]
fun [build](build.md)(): [OpenId4VciManager](../index.md)
Build the [OpenId4VciManager](../index.md) |
+| [config](config.md) | [androidJvm]
fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)
Set the [Config](../-config/index.md) to use |
+| [documentManager](document-manager.md) | [androidJvm]
fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)
Set the DocumentManager to use |
+| [ktorHttpClientFactory](ktor-http-client-factory.md) | [androidJvm]
fun [ktorHttpClientFactory](ktor-http-client-factory.md)(factory: () -> HttpClient): [OpenId4VciManager.Builder](index.md)
Override the Ktor HTTP client factory |
+| [logger](logger.md) | [androidJvm]
fun [logger](logger.md)(logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md) |
## Properties
diff --git a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/kt-http-client-factory.md b/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/kt-http-client-factory.md
deleted file mode 100644
index ebc03777..00000000
--- a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/kt-http-client-factory.md
+++ /dev/null
@@ -1,9 +0,0 @@
-//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[OpenId4VciManager](../index.md)/[Builder](index.md)/[ktHttpClientFactory](kt-http-client-factory.md)
-
-# ktHttpClientFactory
-
-[androidJvm]\
-fun [ktHttpClientFactory](kt-http-client-factory.md)(factory: () ->
-HttpClient): [OpenId4VciManager.Builder](index.md)
-
-Override the Ktor HTTP client factory
diff --git a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md b/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
index 839a719e..dc1b0e0a 100644
--- a/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
+++ b/docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
@@ -2,5 +2,11 @@
# ktorHttpClientFactory
+[androidJvm]\
+fun [ktorHttpClientFactory](ktor-http-client-factory.md)(factory: () ->
+HttpClient): [OpenId4VciManager.Builder](index.md)
+
+Override the Ktor HTTP client factory
+
[androidJvm]\
var [ktorHttpClientFactory](ktor-http-client-factory.md): () -> HttpClient?
diff --git a/docs/wallet-core/package-list b/docs/wallet-core/package-list
index 08aa831d..1c314bad 100644
--- a/docs/wallet-core/package-list
+++ b/docs/wallet-core/package-list
@@ -87,8 +87,8 @@ $dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Buil
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/config/#eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Config/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/config.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/documentManager/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/document-manager.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/documentManager/#eu.europa.ec.eudi.wallet.document.DocumentManager/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/document-manager.md
-$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktHttpClientFactory/#kotlin.Function0[io.ktor.client.HttpClient]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/kt-http-client-factory.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktorHttpClientFactory/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
+$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktorHttpClientFactory/#kotlin.Function0[io.ktor.client.HttpClient]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/logger/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/logger.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/logger/#eu.europa.ec.eudi.wallet.logging.Logger/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/logger.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Companion///PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-companion/index.md
diff --git a/gradle.properties b/gradle.properties
index d135a3a7..ff1c3498 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -42,7 +42,7 @@ systemProp.sonar.host.url=https://sonarcloud.io
systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml
systemProp.sonar.projectName=eudi-lib-android-wallet-core
-VERSION_NAME=0.10.1-SNAPSHOT
+VERSION_NAME=0.10.2-SNAPSHOT
SONATYPE_HOST=S01
SONATYPE_AUTOMATIC_RELEASE=false
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/EudiWallet.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/EudiWallet.kt
index 65b911f5..8aaa9332 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/EudiWallet.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/EudiWallet.kt
@@ -154,6 +154,7 @@ object EudiWallet {
openId4VpConfig,
openId4VpCBORResponseGenerator,
).apply {
+ _config.ktorHttpClientFactory?.let { ktorHttpClientFactory = it }
logger = this@EudiWallet.logger
_config.trustedReaderCertificates?.let {
setReaderTrustStore(ReaderTrustStore.getDefault(it))
@@ -255,6 +256,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
+ ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByDocType(docType, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
@@ -289,6 +291,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
+ ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByOffer(offer, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
@@ -322,6 +325,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
+ ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByOfferUri(offerUri, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
@@ -351,6 +355,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
+ ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also {
when (val document = documentManager.getDocumentById(documentId)) {
is DeferredDocument -> it.issueDeferredDocument(document, executor, onResult)
@@ -399,6 +404,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
+ ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.resolveDocumentOffer(offerUri, executor, onResult) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/DefaultOpenId4VciManager.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/DefaultOpenId4VciManager.kt
index dca525e1..74c58b04 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/DefaultOpenId4VciManager.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/DefaultOpenId4VciManager.kt
@@ -25,6 +25,8 @@ import eu.europa.ec.eudi.wallet.document.*
import eu.europa.ec.eudi.wallet.internal.mainExecutor
import eu.europa.ec.eudi.wallet.issue.openid4vci.IssueEvent.Companion.failure
import eu.europa.ec.eudi.wallet.logging.Logger
+import eu.europa.ec.eudi.wallet.util.wrappedWithContentNegotiation
+import eu.europa.ec.eudi.wallet.util.wrappedWithLogging
import io.ktor.client.*
import io.ktor.client.plugins.logging.*
import kotlinx.coroutines.*
@@ -51,7 +53,7 @@ internal class DefaultOpenId4VciManager(
var logger: Logger? = null
var ktorHttpClientFactory: () -> HttpClient = DefaultHttpClientFactory
- get() = field.wrappedWithLogging(logger)
+ get() = field.wrappedWithLogging(logger).wrappedWithContentNegotiation()
private val offerCreator: OfferCreator by lazy {
OfferCreator(config, ktorHttpClientFactory)
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManager.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManager.kt
index ac56f04d..573bcd38 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManager.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManager.kt
@@ -186,7 +186,7 @@ interface OpenId4VciManager {
/**
* Override the Ktor HTTP client factory
*/
- fun ktHttpClientFactory(factory: () -> HttpClient) = apply {
+ fun ktorHttpClientFactory(factory: () -> HttpClient) = apply {
this.ktorHttpClientFactory = factory
}
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/ProcessDeferredOutcome.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/ProcessDeferredOutcome.kt
index a92b4f0d..da59975b 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/ProcessDeferredOutcome.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/ProcessDeferredOutcome.kt
@@ -37,7 +37,6 @@ internal class ProcessDeferredOutcome(
try {
when (outcome) {
is DeferredCredentialQueryOutcome.Errored -> {
- documentManager.deleteDocumentById(deferredDocument.id)
callback(
DeferredIssueResult.DocumentFailed(
deferredDocument.id,
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/Utils.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/Utils.kt
index 9f2c3e59..ea9e96fb 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/Utils.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/issue/openid4vci/Utils.kt
@@ -23,8 +23,6 @@ import eu.europa.ec.eudi.wallet.document.DocumentManager
import eu.europa.ec.eudi.wallet.document.UnsignedDocument
import eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Companion.TAG
import eu.europa.ec.eudi.wallet.logging.Logger
-import io.ktor.client.*
-import io.ktor.client.plugins.logging.*
import org.bouncycastle.util.io.pem.PemObject
import org.bouncycastle.util.io.pem.PemWriter
import java.io.StringWriter
@@ -136,31 +134,4 @@ internal inline fun OpenId4VciManager.OnResult
}
}
-/**
- * Wraps the [HttpClient] with a logging interceptor.
- * @receiver the [HttpClient] factory
- * @param libraryLogger the logger
- * @return the wrapped [HttpClient] factory
- */
-@JvmSynthetic
-internal fun (() -> HttpClient).wrappedWithLogging(libraryLogger: Logger?): (() -> HttpClient) {
- return if (libraryLogger != null) {
- {
- val ktorLogger = object : io.ktor.client.plugins.logging.Logger {
- override fun log(message: String) {
- libraryLogger.d(TAG, message)
- }
- }
- this().let { client ->
- client.config {
- install(Logging) {
- logger = ktorLogger
- level = LogLevel.ALL
- }
- }
- }
- }
- } else this
-}
-
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/transfer/openid4vp/OpenId4vpManager.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/transfer/openid4vp/OpenId4vpManager.kt
index 25c4dbec..5acfd8f5 100644
--- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/transfer/openid4vp/OpenId4vpManager.kt
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/transfer/openid4vp/OpenId4vpManager.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023 European Commission
+ * Copyright (c) 2023-2024 European Commission
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,11 +30,11 @@ import eu.europa.ec.eudi.prex.JsonPath
import eu.europa.ec.eudi.prex.PresentationSubmission
import eu.europa.ec.eudi.wallet.internal.Openid4VpUtils
import eu.europa.ec.eudi.wallet.internal.mainExecutor
-import eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager
import eu.europa.ec.eudi.wallet.logging.Logger
import eu.europa.ec.eudi.wallet.util.CBOR
+import eu.europa.ec.eudi.wallet.util.wrappedWithContentNegotiation
+import eu.europa.ec.eudi.wallet.util.wrappedWithLogging
import io.ktor.client.*
-import io.ktor.client.plugins.logging.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -45,7 +45,6 @@ import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.util.*
import java.util.concurrent.Executor
-import io.ktor.client.plugins.logging.Logger as KtorLogger
/**
* OpenId4vp manager. This class is used to manage the OpenId4vp transfer method. It is used to resolve the request uri and send the response.
@@ -131,22 +130,7 @@ class OpenId4vpManager(
var logger: Logger? = null
var ktorHttpClientFactory: () -> HttpClient = DefaultHttpClientFactory
- get() = {
- logger?.let { l ->
- field().let { client ->
- client.config {
- install(Logging) {
- logger = object : KtorLogger {
- override fun log(message: String) {
- l.d(OpenId4VciManager.TAG, message)
- }
- }
- level = LogLevel.ALL
- }
- }
- }
- } ?: field()
- }
+ get() = field.wrappedWithLogging(logger).wrappedWithContentNegotiation()
private val appContext = context.applicationContext
private val ioScope = CoroutineScope(Job() + Dispatchers.IO)
diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/util/KtorHttpClientFactoryExtensions.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/util/KtorHttpClientFactoryExtensions.kt
new file mode 100644
index 00000000..b7714c62
--- /dev/null
+++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/util/KtorHttpClientFactoryExtensions.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2024 European Commission
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package eu.europa.ec.eudi.wallet.util
+
+import eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Companion.TAG
+import eu.europa.ec.eudi.wallet.logging.Logger
+import io.ktor.client.*
+import io.ktor.client.plugins.contentnegotiation.*
+import io.ktor.client.plugins.logging.*
+import io.ktor.serialization.kotlinx.json.*
+import kotlinx.serialization.json.Json
+
+/**
+ * Wraps the [HttpClient] with a logging interceptor.
+ * @receiver the [HttpClient] factory
+ * @param libraryLogger the logger
+ * @return the wrapped [HttpClient] factory
+ */
+@JvmSynthetic
+internal fun (() -> HttpClient).wrappedWithLogging(libraryLogger: Logger?): (() -> HttpClient) {
+ return if (libraryLogger != null) {
+ {
+ val ktorLogger = object : io.ktor.client.plugins.logging.Logger {
+ override fun log(message: String) {
+ libraryLogger.d(TAG, message)
+ }
+ }
+ this().let { client ->
+ client.config {
+ install(Logging) {
+ logger = ktorLogger
+ level = LogLevel.ALL
+ }
+ }
+ }
+ }
+ } else this
+}
+
+@JvmSynthetic
+internal fun (() -> HttpClient).wrappedWithContentNegotiation(): (() -> HttpClient) {
+ return {
+ val jsonSupport = Json {
+ ignoreUnknownKeys = true
+ prettyPrint = true
+ }
+ this().let { client ->
+ client.config {
+ install(ContentNegotiation) {
+ json(
+ json = jsonSupport,
+ )
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/EudiWalletConfigTest.kt b/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/EudiWalletConfigTest.kt
index c69c09c1..e2debdd0 100644
--- a/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/EudiWalletConfigTest.kt
+++ b/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/EudiWalletConfigTest.kt
@@ -21,30 +21,25 @@ import eu.europa.ec.eudi.wallet.transfer.openid4vp.ClientIdScheme
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionAlgorithm
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionMethod
import eu.europa.ec.eudi.wallet.transfer.openid4vp.PreregisteredVerifier
-import org.junit.Assert.*
-import org.junit.Before
-import org.junit.Test
-import org.mockito.Mockito.mock
-import org.mockito.Mockito.`when`
+import io.mockk.every
+import io.mockk.mockk
+import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.Test
import java.io.File
import java.security.cert.X509Certificate
class EudiWalletConfigTest {
- private lateinit var context: Context
-
- @Before
- fun setUp() {
- context = mock(Context::class.java)
- `when`(context.applicationContext).thenReturn(context)
- `when`(context.noBackupFilesDir).thenReturn(mock(File::class.java))
+ private val context: Context = mockk(relaxed = true) {
+ every { applicationContext } returns this@mockk
+ every { noBackupFilesDir } returns mockk()
}
@Test
fun testInvoke() {
val storageDir = File("/tmp")
- val readerCertificate1 = mock(X509Certificate::class.java)
- val readerCertificate2 = mock(X509Certificate::class.java)
+ val readerCertificate1 = mockk()
+ val readerCertificate2 = mockk()
val config = EudiWalletConfig(context) {
documentsStorageDir(storageDir)
userAuthenticationRequired(true)
@@ -114,38 +109,6 @@ class EudiWalletConfigTest {
assertEquals("eudi-openid4ci://authorize", config.openId4VciConfig?.authFlowRedirectionURI)
}
- @Test
- fun testBuilder() {
- val builder = EudiWalletConfig.Builder(context)
-
- builder.encryptDocumentsInStorage(false)
- builder.useHardwareToStoreKeys(false)
- builder.bleTransferMode(
- EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE,
- EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE
- )
- builder.bleClearCacheEnabled(true)
- builder.userAuthenticationRequired(true)
- builder.userAuthenticationTimeOut(30_000L)
- builder.trustedReaderCertificates(listOf(mock(X509Certificate::class.java)))
-
- val config = builder.build()
-
- assertFalse(config.encryptDocumentsInStorage)
- assertFalse(config.useHardwareToStoreKeys)
- assertEquals(
- EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE or EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE,
- config.bleTransferMode
- )
- assertTrue(config.bleCentralClientModeEnabled)
- assertTrue(config.blePeripheralServerModeEnabled)
- assertTrue(config.bleClearCacheEnabled)
- assertTrue(config.userAuthenticationRequired)
- assertEquals(30_000L, config.userAuthenticationTimeOut)
- assertEquals(1, config.trustedReaderCertificates?.size)
-
- }
-
@Test
fun testDefaultValues() {
val config = EudiWalletConfig(context) {}
diff --git a/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManagerBuilderTest.kt b/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManagerBuilderTest.kt
index 93e11c1c..5f7eca85 100644
--- a/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManagerBuilderTest.kt
+++ b/wallet-core/src/test/java/eu/europa/ec/eudi/wallet/issue/openid4vci/OpenId4VciManagerBuilderTest.kt
@@ -18,9 +18,9 @@ package eu.europa.ec.eudi.wallet.issue.openid4vci
import android.content.Context
import eu.europa.ec.eudi.wallet.document.DocumentManager
+import io.ktor.client.*
import io.mockk.mockk
-import org.junit.jupiter.api.Assertions.assertNotNull
-import org.junit.jupiter.api.Assertions.assertThrows
+import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
@@ -68,4 +68,19 @@ class OpenId4VciManagerBuilderTest {
builder.build()
}
}
+
+ @Test
+ fun `Builder sets the ktorClientFactory`() {
+ val ktorClientFactory: () -> HttpClient = mockk()
+ val builder = OpenId4VciManager.Builder(context)
+ .config(config)
+ .documentManager(documentManager)
+ .ktorHttpClientFactory(ktorClientFactory)
+
+ val manager = builder.build() as DefaultOpenId4VciManager
+
+ assertNotNull(manager)
+
+ assertSame(ktorClientFactory, manager.ktorHttpClientFactory)
+ }
}
\ No newline at end of file