libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 849bca95be1cd6f772457ab5f974c58c62ecf6bf
parent f5a4772b5d108b5ada2cb7490a1595a66ab48dd7
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue, 28 Jan 2020 20:13:18 +0100

Prefer varchar for "id" columns.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 12+++++++-----
Mnexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 9++-------
Mnexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 2+-
Anexus/src/test/kotlin/DbTest.kt | 40++++++++++++++++++++++++++++++++++++++++
Msandbox/src/test/kotlin/DbTest.kt | 1-
5 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -6,8 +6,11 @@ import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction import java.sql.Connection +const val ID_MAX_LENGTH = 50 -object EbicsSubscribersTable : IntIdTable() { +object EbicsSubscribersTable : IdTable<String>() { + + override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey() val ebicsURL = text("ebicsURL") val hostID = text("hostID") val partnerID = text("partnerID") @@ -20,10 +23,9 @@ object EbicsSubscribersTable : IntIdTable() { val bankAuthenticationPublicKey = blob("bankAuthenticationPublicKey").nullable() } -class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) { - companion object : IntEntityClass<EbicsSubscriberEntity>( - EbicsSubscribersTable - ) +class EbicsSubscriberEntity(id: EntityID<String>) : Entity<String>(id) { + + companion object : EntityClass<String, EbicsSubscriberEntity>(EbicsSubscribersTable) var ebicsURL by EbicsSubscribersTable.ebicsURL var hostID by EbicsSubscribersTable.hostID diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt @@ -170,13 +170,8 @@ fun chunkString(input: String): String { } -fun expectId(param: String?): Int { - - try { - return param!!.toInt() - } catch (e: Exception) { - throw NotAnIdError(HttpStatusCode.BadRequest) - } +fun expectId(param: String?): String { + return param ?: throw NotAnIdError(HttpStatusCode.BadRequest) } fun signOrder( diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt @@ -43,7 +43,7 @@ data class EbicsSubscriberInfoRequest( * Contain the ID that identifies the new user in the Nexus system. */ data class EbicsSubscriberInfoResponse( - val accountID: Int, + val accountID: String, val ebicsURL: String, val hostID: String, val partnerID: String, diff --git a/nexus/src/test/kotlin/DbTest.kt b/nexus/src/test/kotlin/DbTest.kt @@ -0,0 +1,39 @@ +package tech.libeufin.nexus + +import org.jetbrains.exposed.dao.EntityID +import org.junit.Before +import org.junit.Test + +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.transactions.transaction +import org.jetbrains.exposed.sql.SchemaUtils +import javax.sql.rowset.serial.SerialBlob + + +class DbTest { + + @Before + fun connectAndMakeTables() { + Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver") + transaction { + SchemaUtils.create(EbicsSubscribersTable) + } + } + + @Test + fun makeCustomer() { + transaction { + EbicsSubscriberEntity.new(id = "123asdf") { + ebicsURL = "ebics url" + hostID = "host" + partnerID = "partner" + userID = "user" + systemID = "system" + signaturePrivateKey = SerialBlob("signturePrivateKey".toByteArray()) + authenticationPrivateKey = SerialBlob("authenticationPrivateKey".toByteArray()) + encryptionPrivateKey = SerialBlob("encryptionPrivateKey".toByteArray()) + } + assert(EbicsSubscriberEntity.findById("123asdf") != null) + } + } +} +\ No newline at end of file diff --git a/sandbox/src/test/kotlin/DbTest.kt b/sandbox/src/test/kotlin/DbTest.kt @@ -33,7 +33,6 @@ class DbTest { SchemaUtils.create(BankTransactionsTable) SchemaUtils.create(BankCustomersTable) } - }