From dca9ee50539911a1625dc90607d8665d70d877c7 Mon Sep 17 00:00:00 2001 From: Andreas Tschabuschnig Date: Fri, 12 Jan 2024 13:55:11 +0800 Subject: [PATCH 1/4] feat(versions) #61: VersionDetails based on registered OcpiModuleServers --- .../common/OcpiSelfRegisteringModuleServer.kt | 31 +++++ .../modules/credentials/CredentialsServer.kt | 19 +++- .../services/CredentialsClientService.kt | 6 +- .../modules/locations/LocationsCpoServer.kt | 23 ++-- .../modules/locations/LocationsEmspServer.kt | 23 ++-- .../modules/sessions/SessionsCpoServer.kt | 24 ++-- .../modules/sessions/SessionsEmspServer.kt | 24 ++-- .../toolkit/modules/tokens/TokensCpoServer.kt | 24 ++-- .../modules/tokens/TokensEmspServer.kt | 24 ++-- .../modules/versions/VersionDetailsServer.kt | 29 ----- .../modules/versions/VersionsServer.kt | 23 +++- .../InMemoryVersionsRepository.kt | 32 ++++++ .../repositories/MutableVersionsRepository.kt | 8 ++ .../repositories/VersionDetailsRepository.kt | 8 -- .../repositories/VersionsRepository.kt | 6 +- .../services/VersionDetailsService.kt | 21 ---- .../versions/services/VersionsService.kt | 25 ++++- .../cpo/LocationsCpoHttpGetConnectorTest.kt | 6 +- .../http/cpo/LocationsCpoHttpGetEvseTest.kt | 6 +- .../cpo/LocationsCpoHttpGetLocationTest.kt | 6 +- .../cpo/LocationsCpoHttpGetLocationsTest.kt | 6 +- .../emsp/LocationsEmspHttpGetConnectorTest.kt | 6 +- .../http/emsp/LocationsEmspHttpGetEvseTest.kt | 6 +- .../emsp/LocationsEmspHttpGetLocationTest.kt | 6 +- .../LocationsEmspHttpPatchConnectorTest.kt | 6 +- .../emsp/LocationsEmspHttpPatchEvseTest.kt | 6 +- .../LocationsEmspHttpPatchLocationTest.kt | 6 +- .../emsp/LocationsEmspHttpPutConnectorTest.kt | 6 +- .../http/emsp/LocationsEmspHttpPutEvseTest.kt | 6 +- .../emsp/LocationsEmspHttpPutLocationTest.kt | 6 +- .../http/cpo/TokensCpoHttpGetTokenTest.kt | 6 +- .../http/cpo/TokensCpoHttpPatchTokenTest.kt | 8 +- .../http/cpo/TokensCpoHttpPutTokenTest.kt | 6 +- .../http/emsp/TokensEmspHttpGetTokensTest.kt | 6 +- .../http/emsp/TokensEmspHttpPostTokenTest.kt | 8 +- .../samples/common/Http4kTransportServer.kt | 4 + .../common/VersionDetailsCacheRepository.kt | 26 ----- .../samples/common/VersionsCacheRepository.kt | 27 +++-- .../credentials/CredentialsReceiver.kt | 21 ++-- .../samples/credentials/CredentialsSender.kt | 19 ++-- .../samples/locations/LocationsCommon.kt | 6 +- .../samples/locations/LocationsCpoServer.kt | 4 +- .../samples/locations/LocationsEmspServer.kt | 6 +- .../CredentialsIntegrationTests.kt | 106 +++++++++--------- .../integration/LocationsIntegrationTest.kt | 6 +- .../ocpi/toolkit/transport/TransportServer.kt | 5 + 46 files changed, 419 insertions(+), 273 deletions(-) create mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt delete mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt create mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/InMemoryVersionsRepository.kt create mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/MutableVersionsRepository.kt delete mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt delete mode 100644 ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionDetailsService.kt delete mode 100644 ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt new file mode 100644 index 00000000..c2c645af --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt @@ -0,0 +1,31 @@ +package com.izivia.ocpi.toolkit.common + +import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository +import com.izivia.ocpi.toolkit.transport.TransportServer + +abstract class OcpiSelfRegisteringModuleServer( + private val versionsRepository: MutableVersionsRepository, + private val ocpiVersion: VersionNumber, + private val moduleID: ModuleID, + private val interfaceRole: InterfaceRole, + basePathOverride: String? = null +) : OcpiModuleServer(basePathOverride ?: "/${ocpiVersion.value}/${moduleID.name}") { + + protected abstract suspend fun doRegisterOn(transportServer: TransportServer) + + override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository.addEndpoint( + ocpiVersion, + Endpoint( + identifier = moduleID, + role = interfaceRole, + url = "${transportServer.baseUrl()}$basePath" + ) + ) + doRegisterOn(transportServer) + } +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt index 0d24d47d..9ec55739 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt @@ -3,14 +3,27 @@ package com.izivia.ocpi.toolkit.modules.credentials import com.izivia.ocpi.toolkit.common.* import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod class CredentialsServer( private val service: CredentialsServerService, - basePath: String = "/2.2.1/credentials" -) : OcpiModuleServer(basePath) { - override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.credentials, + // role irrelevant for module credentials, but docs suggest using SENDER + interfaceRole = InterfaceRole.SENDER, + basePathOverride = basePathOverride +) { + + override suspend fun doRegisterOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, path = basePathSegments diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt index fc89e947..5fdd1544 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt @@ -201,14 +201,14 @@ class CredentialsClientService( .let { it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } - val availableClientVersions = clientVersionsRepository.getVersions() + val availableClientVersionNumbers = clientVersionsRepository.getVersions() // Get available versions and pick latest mutual val latestMutualVersion = availableServerVersions .sortedByDescending { clientVersion -> parseVersionNumber(clientVersion.version)!!.index } .firstOrNull { serverVersion -> - availableClientVersions - .any { clientVersion -> serverVersion.version == clientVersion.version } + availableClientVersionNumbers + .any { clientVersionNumber -> serverVersion.version == clientVersionNumber.value } } ?: throw OcpiServerUnsupportedVersionException( "Could not find mutual version with partner $serverVersionsEndpointUrl" diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt index 704b7d83..e49faf09 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt @@ -1,22 +1,29 @@ package com.izivia.ocpi.toolkit.modules.locations -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment import java.time.Instant -/** - * Receives calls from a CPO - * @property transportServer - */ class LocationsCpoServer( private val service: LocationsCpoInterface, - basePath: String = "/2.2.1/locations" -) : OcpiModuleServer(basePath) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.locations, + interfaceRole = InterfaceRole.SENDER, + basePathOverride = basePathOverride +) { - override suspend fun registerOn(transportServer: TransportServer) { + override suspend fun doRegisterOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, path = basePathSegments, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt index e94e62ea..dac3a2f9 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt @@ -1,23 +1,30 @@ package com.izivia.ocpi.toolkit.modules.locations -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.locations.domain.* +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -/** - * Receives calls from a CPO - * @property transportServer - */ class LocationsEmspServer( private val service: LocationsEmspInterface, - basePath: String = "/2.2.1/locations" -) : OcpiModuleServer(basePath) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.locations, + interfaceRole = InterfaceRole.RECEIVER, + basePathOverride = basePathOverride +) { - override suspend fun registerOn(transportServer: TransportServer) { + override suspend fun doRegisterOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, path = basePathSegments + listOf( diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt index 3d5e1488..799cee15 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt @@ -1,24 +1,32 @@ package com.izivia.ocpi.toolkit.modules.sessions -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferences +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment import java.time.Instant -/** - * Receives calls from a CPO - * @property transportServer - */ class SessionsCpoServer( private val service: SessionsCpoInterface, - basePath: String = "/2.2.1/sessions" -) : OcpiModuleServer(basePath) { - override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.sessions, + interfaceRole = InterfaceRole.SENDER, + basePathOverride = basePathOverride +) { + + override suspend fun doRegisterOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, path = basePathSegments, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt index 2327de27..745b5f4f 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt @@ -1,23 +1,31 @@ package com.izivia.ocpi.toolkit.modules.sessions -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.sessions.domain.Session import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -/** - * Receives calls from a CPO - * @property transportServer - */ class SessionsEmspServer( private val service: SessionsEmspInterface, - basePath: String = "/2.2.1/sessions" -) : OcpiModuleServer(basePath) { - override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.sessions, + interfaceRole = InterfaceRole.RECEIVER, + basePathOverride = basePathOverride +) { + + override suspend fun doRegisterOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, path = basePathSegments + listOf( diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt index a7393619..3bb6aaee 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt @@ -1,24 +1,32 @@ package com.izivia.ocpi.toolkit.modules.tokens -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -/** - * Receives calls from a CPO - * @property transportServer - */ class TokensCpoServer( private val service: TokensCpoInterface, - basePath: String = "/2.2.1/tokens" -) : OcpiModuleServer(basePath) { - override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.tokens, + interfaceRole = InterfaceRole.SENDER, + basePathOverride = basePathOverride +) { + + override suspend fun doRegisterOn(transportServer: TransportServer) { // Get Method transportServer.handle( method = HttpMethod.GET, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt index f4afb319..6b9d461a 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt @@ -1,25 +1,33 @@ package com.izivia.ocpi.toolkit.modules.tokens -import com.izivia.ocpi.toolkit.common.OcpiModuleServer +import com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType +import com.izivia.ocpi.toolkit.modules.versions.domain.InterfaceRole +import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepository import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment import java.time.Instant -/** - * Receives calls from a CPO - * @property transportServer - */ class TokensEmspServer( private val service: TokensEmspInterface, - basePath: String = "/2.2.1/tokens" -) : OcpiModuleServer(basePath) { - override suspend fun registerOn(transportServer: TransportServer) { + versionsRepository: MutableVersionsRepository, + basePathOverride: String? = null +) : OcpiSelfRegisteringModuleServer( + versionsRepository = versionsRepository, + ocpiVersion = VersionNumber.V2_2_1, + moduleID = ModuleID.tokens, + interfaceRole = InterfaceRole.RECEIVER, + basePathOverride = basePathOverride +) { + + override suspend fun doRegisterOn(transportServer: TransportServer) { // GET Token transportServer.handle( method = HttpMethod.GET, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt deleted file mode 100644 index d103ab99..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiModuleServer -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.modules.versions.services.VersionDetailsService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment - -class VersionDetailsServer( - private val service: VersionDetailsService, - basePath: String = "" -) : OcpiModuleServer(basePath) { - - override suspend fun registerOn(transportServer: TransportServer) { - transportServer.handle( - method = HttpMethod.GET, - path = basePathSegments + listOf( - VariablePathSegment("versionNumber") - ) - ) { req -> - req.httpResponse { - service.getVersionDetails( - versionNumber = req.pathParams["versionNumber"]!! - ) - } - } - } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt index 64bd67ae..45b27552 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt @@ -4,21 +4,36 @@ import com.izivia.ocpi.toolkit.common.OcpiModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.modules.versions.services.VersionsService import com.izivia.ocpi.toolkit.transport.TransportServer +import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment import com.izivia.ocpi.toolkit.transport.domain.HttpMethod +import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment class VersionsServer( - private val service: VersionsService, - basePath: String = "/versions" -) : OcpiModuleServer(basePath) { + private val service: VersionsService +) : OcpiModuleServer("") { override suspend fun registerOn(transportServer: TransportServer) { transportServer.handle( method = HttpMethod.GET, - path = basePathSegments + path = listOf(FixedPathSegment(service.versionsBasePath)) ) { req -> req.httpResponse { service.getVersions() } } + + transportServer.handle( + method = HttpMethod.GET, + path = listOf( + FixedPathSegment(service.versionDetailsBasePath), + VariablePathSegment("versionNumber") + ) + ) { req -> + req.httpResponse { + service.getVersionDetails( + versionNumber = req.pathParams["versionNumber"]!! + ) + } + } } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/InMemoryVersionsRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/InMemoryVersionsRepository.kt new file mode 100644 index 00000000..b384cb43 --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/InMemoryVersionsRepository.kt @@ -0,0 +1,32 @@ +package com.izivia.ocpi.toolkit.modules.versions.repositories + +import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber + +class InMemoryVersionsRepository : MutableVersionsRepository { + + private val versions: MutableMap> = mutableMapOf() + + override suspend fun addEndpoint(versionNumber: VersionNumber, endpoint: Endpoint) { + val endpoints = versions.getOrPut(versionNumber) { mutableListOf() } + + endpoints.find { it.identifier == endpoint.identifier && it.role == endpoint.role } + ?.let { throw Exception("duplicate module already registered") } + + endpoints.add(endpoint) + } + + override suspend fun getVersions(): List { + return versions.keys.toList() + } + + override suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? { + return versions[versionNumber]?.let { + VersionDetails( + version = versionNumber.value, + endpoints = it + ) + } + } +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/MutableVersionsRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/MutableVersionsRepository.kt new file mode 100644 index 00000000..e8a4186c --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/MutableVersionsRepository.kt @@ -0,0 +1,8 @@ +package com.izivia.ocpi.toolkit.modules.versions.repositories + +import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber + +interface MutableVersionsRepository : VersionsRepository { + suspend fun addEndpoint(versionNumber: VersionNumber, endpoint: Endpoint) +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt deleted file mode 100644 index 9bbc2921..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber - -interface VersionDetailsRepository { - suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt index 397dd116..14754aca 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt @@ -1,7 +1,9 @@ package com.izivia.ocpi.toolkit.modules.versions.repositories -import com.izivia.ocpi.toolkit.modules.versions.domain.Version +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber interface VersionsRepository { - suspend fun getVersions(): List + suspend fun getVersions(): List + suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionDetailsService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionDetailsService.kt deleted file mode 100644 index b804dc93..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionDetailsService.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.services - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiServerUnsupportedVersionException -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsService( - private val repository: VersionDetailsRepository -) { - suspend fun getVersionDetails( - versionNumber: String - ): OcpiResponseBody = OcpiResponseBody.of { - parseVersionNumber(versionNumber) - ?.let { parsedVersionNumber -> - repository.getVersionDetails(parsedVersionNumber) - } - ?: throw OcpiServerUnsupportedVersionException("Invalid version number: $versionNumber") - } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt index cc5c57be..92c0d105 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt @@ -1,15 +1,36 @@ package com.izivia.ocpi.toolkit.modules.versions.services import com.izivia.ocpi.toolkit.common.OcpiResponseBody +import com.izivia.ocpi.toolkit.common.OcpiServerUnsupportedVersionException import com.izivia.ocpi.toolkit.modules.versions.VersionsInterface import com.izivia.ocpi.toolkit.modules.versions.domain.Version +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails +import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository class VersionsService( - private val repository: VersionsRepository + private val repository: VersionsRepository, + private val baseUrl: String, + val versionsBasePath: String = "/versions", + val versionDetailsBasePath: String = "" ) : VersionsInterface { override suspend fun getVersions(): OcpiResponseBody> = OcpiResponseBody.of { - repository.getVersions() + repository.getVersions().map { + Version( + version = it.value, + url = "$baseUrl$versionDetailsBasePath/${it.value}" + ) + } + } + + suspend fun getVersionDetails( + versionNumber: String + ): OcpiResponseBody = OcpiResponseBody.of { + parseVersionNumber(versionNumber) + ?.let { parsedVersionNumber -> + repository.getVersionDetails(parsedVersionNumber) + } + ?: throw OcpiServerUnsupportedVersionException("Invalid version number: $versionNumber") } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt index 1d6b5c55..a381b170 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt @@ -10,6 +10,7 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.ConnectorType import com.izivia.ocpi.toolkit.modules.locations.domain.PowerType import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -32,7 +33,7 @@ class LocationsCpoHttpGetConnectorTest { var evseUid = slot() var connectorId = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getConnector( capture(slots.locationId), @@ -97,7 +98,8 @@ private fun LocationsCpoRepository.buildServer(): TransportClient { runBlocking { LocationsCpoServer( service = LocationsCpoService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt index 5c474620..2bdc64b5 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt @@ -7,6 +7,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -28,7 +29,7 @@ class LocationsCpoHttpGetEvseTest { var locationId = slot() var evseUid = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getEvse(capture(slots.locationId), capture(slots.evseUid)) } coAnswers { Evse( uid = "3256", @@ -130,7 +131,8 @@ private fun LocationsCpoRepository.buildServer(): TransportClient { runBlocking { LocationsCpoServer( service = LocationsCpoService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt index 39d515d7..eca0939a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt @@ -7,6 +7,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -27,7 +28,7 @@ class LocationsCpoHttpGetLocationTest { val slots = object { var locationId = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getLocation(capture((slots.locationId))) } coAnswers { Location( countryCode = "BE", @@ -215,7 +216,8 @@ private fun LocationsCpoRepository.buildServer(): TransportClient { runBlocking { LocationsCpoServer( service = LocationsCpoService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt index bcd554b6..7231d360 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService import com.izivia.ocpi.toolkit.modules.toSearchResult +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -30,7 +31,7 @@ class LocationsCpoHttpGetLocationsTest { var dateFrom = slot() var dateTo = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getLocations(capture(slots.dateFrom), capture(slots.dateTo), any(), any()) } coAnswers { listOf( Location( @@ -149,7 +150,8 @@ private fun LocationsCpoRepository.buildServer(): TransportClient { runBlocking { LocationsCpoServer( service = LocationsCpoService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt index 8abd8cf9..3e3eb298 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt @@ -10,6 +10,7 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.ConnectorType import com.izivia.ocpi.toolkit.modules.locations.domain.PowerType import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -34,7 +35,7 @@ class LocationsEmspHttpGetConnectorTest { var evseUid = slot() var connectorId = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getConnector( capture(slots.countryCode), @@ -103,7 +104,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt index 5e5c041a..754a233c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt @@ -7,6 +7,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -30,7 +31,7 @@ class LocationsEmspHttpGetEvseTest { var locationId = slot() var evseUid = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getEvse( capture(slots.countryCode), @@ -141,7 +142,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt index 4ca2cfea..84931aad 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt @@ -7,6 +7,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -29,7 +30,7 @@ class LocationsEmspHttpGetLocationTest { var partyId = slot() var locationId = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getLocation( capture(slots.countryCode), @@ -225,7 +226,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt index db19fba3..0c62181a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -33,7 +34,7 @@ class LocationsEmspHttpPatchConnectorTest { var connectorId = slot() var connector = slot() } - val srv = mockk() { + val srv = mockk { coEvery { patchConnector( capture(slots.countryCode), @@ -105,7 +106,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt index 2c57576f..ae719561 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -32,7 +33,7 @@ class LocationsEmspHttpPatchEvseTest { var evseUid = slot() var evse = slot() } - val srv = mockk() { + val srv = mockk { coEvery { patchEvse( capture(slots.countryCode), @@ -126,7 +127,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt index dadac80c..f99cb279 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -31,7 +32,7 @@ class LocationsEmspHttpPatchLocationTest { var locationId = slot() var location = slot() } - val srv = mockk() { + val srv = mockk { coEvery { patchLocation( capture(slots.countryCode), @@ -177,7 +178,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt index 1e15de57..b747fa7c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt @@ -11,6 +11,7 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.ConnectorType import com.izivia.ocpi.toolkit.modules.locations.domain.PowerType import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -46,7 +47,7 @@ class LocationsEmspHttpPutConnectorTest { tariffIds = listOf("11"), lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ) - val srv = mockk() { + val srv = mockk { coEvery { putConnector( capture(slots.countryCode), @@ -97,7 +98,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt index 59d4aa4c..0f6eb51d 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -63,7 +64,7 @@ class LocationsEmspHttpPutEvseTest { physicalReference = "1", lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ) - val srv = mockk() { + val srv = mockk { coEvery { putEvse( capture(slots.countryCode), @@ -112,7 +113,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt index f2670863..379a9dd4 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -104,7 +105,7 @@ class LocationsEmspHttpPutLocationTest { lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) - val srv = mockk() { + val srv = mockk { coEvery { putLocation( capture(slots.countryCode), @@ -151,7 +152,8 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { runBlocking { LocationsEmspServer( service = LocationsEmspService(repo), - basePath = "/locations" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/locations" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt index 97e392a2..b144ca49 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt @@ -11,6 +11,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.modules.tokens.domain.WhitelistType import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensCpoRepository import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -34,7 +35,7 @@ class TokensCpoHttpGetTokenTest { var tokenUID = slot() var type = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getToken( capture(slots.countryCode), @@ -119,7 +120,8 @@ private fun TokensCpoRepository.buildServer(): TransportClient { runBlocking { TokensCpoServer( service = TokensCpoService(repo), - basePath = "/tokens" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/tokens" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt index ed744966..2ffdf61e 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt @@ -9,6 +9,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoServer import com.izivia.ocpi.toolkit.modules.tokens.domain.* import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensCpoRepository import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -52,7 +53,7 @@ class TokensCpoHttpPatchTokenTest { var tokenUID = slot() var type = slot() } - val srv = mockk() { + val srv = mockk { coEvery { patchToken( capture(slots.token), @@ -142,7 +143,7 @@ class TokensCpoHttpPatchTokenTest { var tokenUID = slot() var type = slot() } - val srv = mockk() { + val srv = mockk { coEvery { patchToken( capture(slots.token), @@ -192,7 +193,8 @@ private fun TokensCpoRepository.buildServer(): TransportClient { runBlocking { TokensCpoServer( service = TokensCpoService(repo), - basePath = "/tokens" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/tokens" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt index 00f53a42..866052e2 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt @@ -12,6 +12,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.modules.tokens.domain.WhitelistType import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensCpoRepository import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -55,7 +56,7 @@ class TokensCpoHttpPutTokenTest { var tokenUID = slot() var type = slot() } - val srv = mockk() { + val srv = mockk { coEvery { putToken( capture(slots.token), @@ -102,7 +103,8 @@ private fun TokensCpoRepository.buildServer(): TransportClient { runBlocking { TokensCpoServer( service = TokensCpoService(repo), - basePath = "/tokens" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/tokens" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt index 39cae148..7d1ffb71 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt @@ -12,6 +12,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.modules.tokens.domain.WhitelistType import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensEmspRepository import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -33,7 +34,7 @@ class TokensEmspHttpGetTokensTest { var dateFrom = slot() var dateTo = slot() } - val srv = mockk() { + val srv = mockk { coEvery { getTokens(capture(slots.dateFrom), capture(slots.dateTo), any(), any()) } coAnswers { @@ -115,7 +116,8 @@ private fun TokensEmspRepository.buildServer(): TransportClient { runBlocking { TokensEmspServer( service = TokensEmspService(repo), - basePath = "/tokens" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/tokens" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt index e54f3d49..bbfebcb1 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt @@ -9,6 +9,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.TokensEmspServer import com.izivia.ocpi.toolkit.modules.tokens.domain.* import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensEmspRepository import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod @@ -30,7 +31,7 @@ class TokensEmspHttpPostTokenTest { var tokenUID = slot() var type = slot() } - val srv = mockk() { + val srv = mockk { coEvery { postToken(capture(slots.tokenUID), capture(slots.type), null) } coAnswers { @@ -116,7 +117,7 @@ class TokensEmspHttpPostTokenTest { var type = slot() var locationReferences = slot() } - val srv = mockk() { + val srv = mockk { coEvery { postToken(capture(slots.tokenUID), capture(slots.type), capture(slots.locationReferences)) } coAnswers { @@ -211,7 +212,8 @@ private fun TokensEmspRepository.buildServer(): TransportClient { runBlocking { TokensEmspServer( service = TokensEmspService(repo), - basePath = "/tokens" + versionsRepository = InMemoryVersionsRepository(), + basePathOverride = "/tokens" ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt index 60165baa..a465dc91 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt @@ -107,5 +107,9 @@ class Http4kTransportServer( server.stop() } + override fun baseUrl(): String { + return baseUrl + } + fun initRouterAndBuildClient() = Http4kTransportClient(buildRouter()) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt deleted file mode 100644 index 086ea273..00000000 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.* -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsCacheRepository( - private val baseUrl: String -) : VersionDetailsRepository { - - override suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? = - VersionDetails( - version = VersionNumber.V2_2_1.value, - endpoints = listOf( - Endpoint( - identifier = ModuleID.credentials, - role = InterfaceRole.RECEIVER, - url = "$baseUrl/${VersionNumber.V2_2_1.value}/credentials" - ), - Endpoint( - identifier = ModuleID.locations, - role = InterfaceRole.RECEIVER, - url = "$baseUrl/${VersionNumber.V2_2_1.value}/locations" - ) - ) - ).takeIf { versionNumber.value == it.version } -} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt index 71c4f5ac..fa5f941a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt @@ -1,17 +1,30 @@ package com.izivia.ocpi.toolkit.samples.common -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.domain.* import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository class VersionsCacheRepository( private val baseUrl: String ) : VersionsRepository { - override suspend fun getVersions(): List = listOf( - Version( - version = VersionNumber.V2_2_1.value, - url = "$baseUrl/${VersionNumber.V2_2_1.value}" - ) + override suspend fun getVersions(): List = listOf( + VersionNumber.V2_2_1 ) + + override suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? = + VersionDetails( + version = VersionNumber.V2_2_1.value, + endpoints = listOf( + Endpoint( + identifier = ModuleID.credentials, + role = InterfaceRole.RECEIVER, + url = "$baseUrl/${VersionNumber.V2_2_1.value}/credentials" + ), + Endpoint( + identifier = ModuleID.locations, + role = InterfaceRole.RECEIVER, + url = "$baseUrl/${VersionNumber.V2_2_1.value}/locations" + ) + ) + ).takeIf { versionNumber.value == it.version } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt index ca512643..a0196038 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt @@ -8,12 +8,14 @@ import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleR import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService import com.izivia.ocpi.toolkit.modules.credentials.services.RequiredEndpoints import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer import com.izivia.ocpi.toolkit.modules.versions.VersionsServer import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.services.VersionDetailsService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.modules.versions.services.VersionsService -import com.izivia.ocpi.toolkit.samples.common.* +import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder +import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer +import com.izivia.ocpi.toolkit.samples.common.Partner +import com.izivia.ocpi.toolkit.samples.common.PartnerCacheRepository import kotlinx.coroutines.runBlocking const val receiverPort = 8080 @@ -23,6 +25,7 @@ const val tokenA = "06f7967e-65c3-4def-a966-701ffb362b3c" fun main() { // Add token A associated with the sender + val receiverVersionsRepository = InMemoryVersionsRepository() val receiverPlatformRepository = PartnerCacheRepository() receiverPlatformRepository.partners.add(Partner(tokenA = tokenA)) @@ -51,17 +54,13 @@ fun main() { transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsUrlProvider = { receiverVersionsUrl }, requiredEndpoints = requiredOtherPartEndpoints - ) + ), + receiverVersionsRepository ).registerOn(receiverServer) VersionsServer( service = VersionsService( - repository = VersionsCacheRepository(baseUrl = receiverUrl) - ) - ).registerOn(receiverServer) - - VersionDetailsServer( - service = VersionDetailsService( - repository = VersionDetailsCacheRepository(baseUrl = receiverUrl) + repository = receiverVersionsRepository, + baseUrl = receiverUrl ) ).registerOn(receiverServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt index 99e75135..438e35a9 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt @@ -7,12 +7,14 @@ import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleR import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientService import com.izivia.ocpi.toolkit.modules.credentials.services.RequiredEndpoints import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer import com.izivia.ocpi.toolkit.modules.versions.VersionsServer import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.services.VersionDetailsService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.modules.versions.services.VersionsService -import com.izivia.ocpi.toolkit.samples.common.* +import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder +import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer +import com.izivia.ocpi.toolkit.samples.common.Partner +import com.izivia.ocpi.toolkit.samples.common.PartnerCacheRepository import kotlinx.coroutines.runBlocking const val senderPort = 8081 @@ -21,8 +23,7 @@ const val senderVersionsUrl = "http://localhost:$senderPort/versions" fun main() { // Add token A associated with the sender - val senderVersionsRepository = VersionsCacheRepository(baseUrl = senderUrl) - val senderVersionDetailsRepository = VersionDetailsCacheRepository(baseUrl = senderUrl) + val senderVersionsRepository = InMemoryVersionsRepository() val senderPlatformRepository = PartnerCacheRepository() senderPlatformRepository.partners.add(Partner(url = receiverVersionsUrl, tokenA = tokenA)) @@ -36,12 +37,8 @@ fun main() { runBlocking { VersionsServer( service = VersionsService( - repository = senderVersionsRepository - ) - ).registerOn(senderServer) - VersionDetailsServer( - service = VersionDetailsService( - repository = senderVersionDetailsRepository + repository = senderVersionsRepository, + baseUrl = senderUrl ) ).registerOn(senderServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt index 48cf6c88..590143c4 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt @@ -2,13 +2,13 @@ package com.izivia.ocpi.toolkit.samples.locations import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber import com.izivia.ocpi.toolkit.samples.common.DummyPartnerCacheRepository -import com.izivia.ocpi.toolkit.samples.common.VersionDetailsCacheRepository +import com.izivia.ocpi.toolkit.samples.common.VersionsCacheRepository import kotlinx.coroutines.runBlocking const val CREDENTIALS_TOKEN_C = "e0748bbe-d535-4a6b-8f80-94f2457d5b9d" val DUMMY_PLATFORM_REPOSITORY = DummyPartnerCacheRepository().also { - val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServerUrl) - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServerUrl) + val versionDetailsEmsp = VersionsCacheRepository(baseUrl = emspServerUrl) + val versionDetailsCpo = VersionsCacheRepository(baseUrl = cpoServerUrl) runBlocking { it.saveEndpoints( diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt index cf63a0cc..5850d059 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt @@ -8,6 +8,7 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.Evse import com.izivia.ocpi.toolkit.modules.locations.domain.Location import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import kotlinx.coroutines.runBlocking import java.time.Instant @@ -33,7 +34,8 @@ fun main() { // We implement callbacks for the server using the built-in service and our service implementation runBlocking { LocationsCpoServer( - service = LocationsCpoService(service = service) + service = LocationsCpoService(service = service), + versionsRepository = InMemoryVersionsRepository() ).registerOn(transportServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt index 39ac0326..6587fa43 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt @@ -5,6 +5,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import com.izivia.ocpi.toolkit.samples.common.validLocation import kotlinx.coroutines.runBlocking @@ -30,7 +31,8 @@ fun main() { // We implement callbacks for the server using the built-in service and our repository implementation runBlocking { LocationsEmspServer( - service = LocationsEmspService(service = service) + service = LocationsEmspService(service = service), + versionsRepository = InMemoryVersionsRepository() ).registerOn(transportServer) } @@ -39,7 +41,7 @@ fun main() { } class CacheLocationsEmspRepository : LocationsEmspRepository { - override suspend fun getLocation(countryCode: String, partyId: String, locationId: String): Location? { + override suspend fun getLocation(countryCode: String, partyId: String, locationId: String): Location { return validLocation } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt index 78ffe37f..32f15e39 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt @@ -9,11 +9,12 @@ import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientSer import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService import com.izivia.ocpi.toolkit.modules.credentials.services.RequiredEndpoints import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer import com.izivia.ocpi.toolkit.modules.versions.VersionsClient import com.izivia.ocpi.toolkit.modules.versions.VersionsServer import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.services.VersionDetailsService +import com.izivia.ocpi.toolkit.modules.versions.domain.Version +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.modules.versions.services.VersionsService import com.izivia.ocpi.toolkit.samples.common.* import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest @@ -58,8 +59,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { val receiverPlatformRepo = PartnerMongoRepository(collection = receiverPartnerCollection) val receiverServer = buildTransportServer(receiverPlatformRepo) val receiverServerVersionsUrl = "${receiverServer.baseUrl}/versions" - val receiverVersionsCacheRepository = VersionsCacheRepository(baseUrl = receiverServer.baseUrl) - val receiverVersionDetailsCacheRepository = VersionDetailsCacheRepository(baseUrl = receiverServer.baseUrl) + val receiverVersionsCacheRepository = InMemoryVersionsRepository() runBlocking { CredentialsServer( service = CredentialsServerService( @@ -77,16 +77,13 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsUrlProvider = { receiverServerVersionsUrl }, requiredEndpoints = requiredEndpoints - ) + ), + versionsRepository = receiverVersionsCacheRepository ).registerOn(receiverServer) VersionsServer( service = VersionsService( - repository = receiverVersionsCacheRepository - ) - ).registerOn(receiverServer) - VersionDetailsServer( - service = VersionDetailsService( - repository = receiverVersionDetailsCacheRepository + repository = receiverVersionsCacheRepository, + baseUrl = receiverServer.baseUrl ) ).registerOn(receiverServer) } @@ -114,12 +111,8 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { runBlocking { VersionsServer( service = VersionsService( - repository = VersionsCacheRepository(baseUrl = senderServer.baseUrl) - ) - ).registerOn(senderServer) - VersionDetailsServer( - service = VersionDetailsService( - repository = VersionDetailsCacheRepository(baseUrl = senderServer.baseUrl) + repository = VersionsCacheRepository(baseUrl = senderServer.baseUrl), + baseUrl = senderServer.baseUrl ) ).registerOn(senderServer) } @@ -240,13 +233,14 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { ) { get { data } .isNotNull() + .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository( - baseUrl = - receiverServer.transport.baseUrl - ).getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -293,11 +287,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { @Test fun `should properly run registration process then correct get credentials from receiver`() { - val receiverServer = setupReceiver( - RequiredEndpoints( - receiver = listOf(ModuleID.credentials, ModuleID.locations) - ) - ) + val receiverServer = setupReceiver() val senderServer = setupSender() val credentialsClientService = setupCredentialsSenderClient( @@ -466,10 +456,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -521,10 +513,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -559,10 +553,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = senderServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${senderServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -579,10 +575,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -632,10 +630,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } @@ -661,10 +661,12 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isNotNull() .isNotEmpty() .isEqualTo( - runBlocking { - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - } + listOf( + Version( + version = VersionNumber.V2_2_1.value, + url = "${receiverServer.transport.baseUrl}/2.2.1" + ) + ) ) get { status_code } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt index 9608656d..8de25c7c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt @@ -6,6 +6,7 @@ import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspClient import com.izivia.ocpi.toolkit.modules.locations.domain.Location import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber +import com.izivia.ocpi.toolkit.modules.versions.repositories.InMemoryVersionsRepository import com.izivia.ocpi.toolkit.samples.common.* import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest import com.izivia.ocpi.toolkit.tests.integration.mock.LocationsCpoMongoRepository @@ -33,7 +34,8 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { LocationsCpoServer( LocationsCpoService( service = LocationsCpoMongoRepository(collection) - ) + ), + versionsRepository = InMemoryVersionsRepository() ).registerOn(server) } return server @@ -59,7 +61,7 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { val cpoServerVersionsUrl = "${cpoServer.baseUrl}/versions" val partnerRepo = DummyPartnerCacheRepository().also { - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServer.baseUrl) + val versionDetailsCpo = VersionsCacheRepository(baseUrl = cpoServer.baseUrl) runBlocking { it.saveEndpoints( diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt index b1a8faea..ae57ad70 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt @@ -31,4 +31,9 @@ interface TransportServer { * Stops the server */ fun stop() + + /** + * The configured baseUrl this server listens to, used to generate NextPageUrl and Endpoint Url + */ + fun baseUrl(): String } From a8f15e93cd3878276de3dffd22117ebc5d7940f4 Mon Sep 17 00:00:00 2001 From: Andreas Tschabuschnig Date: Mon, 15 Jan 2024 09:57:25 +0800 Subject: [PATCH 2/4] update transportserver doc --- .../com/izivia/ocpi/toolkit/transport/TransportServer.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt index ae57ad70..28b7fad2 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/TransportServer.kt @@ -33,7 +33,10 @@ interface TransportServer { fun stop() /** - * The configured baseUrl this server listens to, used to generate NextPageUrl and Endpoint Url + * The configured baseUrl this server listens to. + * Used by [com.izivia.ocpi.toolkit.common.OcpiSelfRegisteringModuleServer] to generate Endpoint URL. + * Can be used by implementations of TransportServer to populate the baseUrl of HttpRequest (see example), which in + * turn is used to generate NextPageUrl of SearchResult */ fun baseUrl(): String } From c6b1d623dc7abdceb1d8f201bfadb71408f959a8 Mon Sep 17 00:00:00 2001 From: Andreas Tschabuschnig Date: Mon, 15 Jan 2024 10:25:27 +0800 Subject: [PATCH 3/4] make mutableversionsrepo optional --- .../ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt | 4 ++-- .../ocpi/toolkit/modules/credentials/CredentialsServer.kt | 4 ++-- .../ocpi/toolkit/modules/locations/LocationsCpoServer.kt | 4 ++-- .../ocpi/toolkit/modules/locations/LocationsEmspServer.kt | 4 ++-- .../izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt | 4 ++-- .../ocpi/toolkit/modules/sessions/SessionsEmspServer.kt | 4 ++-- .../com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt | 4 ++-- .../izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt index c2c645af..a8e8c202 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiSelfRegisteringModuleServer.kt @@ -8,17 +8,17 @@ import com.izivia.ocpi.toolkit.modules.versions.repositories.MutableVersionsRepo import com.izivia.ocpi.toolkit.transport.TransportServer abstract class OcpiSelfRegisteringModuleServer( - private val versionsRepository: MutableVersionsRepository, private val ocpiVersion: VersionNumber, private val moduleID: ModuleID, private val interfaceRole: InterfaceRole, + private val versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiModuleServer(basePathOverride ?: "/${ocpiVersion.value}/${moduleID.name}") { protected abstract suspend fun doRegisterOn(transportServer: TransportServer) override suspend fun registerOn(transportServer: TransportServer) { - versionsRepository.addEndpoint( + versionsRepository?.addEndpoint( ocpiVersion, Endpoint( identifier = moduleID, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt index 9ec55739..5d3a51d5 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt @@ -12,14 +12,14 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpMethod class CredentialsServer( private val service: CredentialsServerService, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.credentials, // role irrelevant for module credentials, but docs suggest using SENDER interfaceRole = InterfaceRole.SENDER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt index e49faf09..43c8b2b3 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt @@ -13,13 +13,13 @@ import java.time.Instant class LocationsCpoServer( private val service: LocationsCpoInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.locations, interfaceRole = InterfaceRole.SENDER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt index dac3a2f9..a0a3f251 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt @@ -14,13 +14,13 @@ import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment class LocationsEmspServer( private val service: LocationsEmspInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.locations, interfaceRole = InterfaceRole.RECEIVER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt index 799cee15..6dd8955a 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoServer.kt @@ -16,13 +16,13 @@ import java.time.Instant class SessionsCpoServer( private val service: SessionsCpoInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.sessions, interfaceRole = InterfaceRole.SENDER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt index 745b5f4f..72180d6e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt @@ -15,13 +15,13 @@ import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment class SessionsEmspServer( private val service: SessionsEmspInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.sessions, interfaceRole = InterfaceRole.RECEIVER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt index 3bb6aaee..8c75ac8d 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt @@ -16,13 +16,13 @@ import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment class TokensCpoServer( private val service: TokensCpoInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.tokens, interfaceRole = InterfaceRole.SENDER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt index 6b9d461a..f13fd4f2 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt @@ -17,13 +17,13 @@ import java.time.Instant class TokensEmspServer( private val service: TokensEmspInterface, - versionsRepository: MutableVersionsRepository, + versionsRepository: MutableVersionsRepository? = null, basePathOverride: String? = null ) : OcpiSelfRegisteringModuleServer( - versionsRepository = versionsRepository, ocpiVersion = VersionNumber.V2_2_1, moduleID = ModuleID.tokens, interfaceRole = InterfaceRole.RECEIVER, + versionsRepository = versionsRepository, basePathOverride = basePathOverride ) { From a7d7ad277cc18356e6b2156ce6210b61dcc36653 Mon Sep 17 00:00:00 2001 From: Andreas Tschabuschnig Date: Wed, 17 Jan 2024 09:45:08 +0800 Subject: [PATCH 4/4] provide baseUrl to VersionServer via function --- .../ocpi/toolkit/modules/versions/services/VersionsService.kt | 4 ++-- .../ocpi/toolkit/samples/credentials/CredentialsReceiver.kt | 2 +- .../ocpi/toolkit/samples/credentials/CredentialsSender.kt | 2 +- .../toolkit/tests/integration/CredentialsIntegrationTests.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt index 92c0d105..5d5e28b8 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/services/VersionsService.kt @@ -10,7 +10,7 @@ import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository class VersionsService( private val repository: VersionsRepository, - private val baseUrl: String, + private val baseUrlProvider: suspend () -> String, val versionsBasePath: String = "/versions", val versionDetailsBasePath: String = "" ) : VersionsInterface { @@ -19,7 +19,7 @@ class VersionsService( repository.getVersions().map { Version( version = it.value, - url = "$baseUrl$versionDetailsBasePath/${it.value}" + url = "${baseUrlProvider()}$versionDetailsBasePath/${it.value}" ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt index a0196038..fee68f5a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt @@ -60,7 +60,7 @@ fun main() { VersionsServer( service = VersionsService( repository = receiverVersionsRepository, - baseUrl = receiverUrl + baseUrlProvider = { receiverUrl } ) ).registerOn(receiverServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt index 438e35a9..f5461bd0 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt @@ -38,7 +38,7 @@ fun main() { VersionsServer( service = VersionsService( repository = senderVersionsRepository, - baseUrl = senderUrl + baseUrlProvider = { receiverUrl } ) ).registerOn(senderServer) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt index 32f15e39..46405a74 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt @@ -83,7 +83,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { VersionsServer( service = VersionsService( repository = receiverVersionsCacheRepository, - baseUrl = receiverServer.baseUrl + baseUrlProvider = receiverServer::baseUrl ) ).registerOn(receiverServer) } @@ -112,7 +112,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { VersionsServer( service = VersionsService( repository = VersionsCacheRepository(baseUrl = senderServer.baseUrl), - baseUrl = senderServer.baseUrl + baseUrlProvider = senderServer::baseUrl ) ).registerOn(senderServer) }