libeufin

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

commit daecfe6cf5ce379a20ec10f9f65262cb770e3447
parent a35b35174a57f4db65807dd83a6c4594495f7056
Author: Florian Dold <florian.dold@gmail.com>
Date:   Mon,  8 Jun 2020 15:01:52 +0530

make test case pass

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 8+++-----
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 2+-
Mnexus/src/test/kotlin/DBTest.kt | 18++++++++----------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 1+
Msandbox/src/test/kotlin/DBTest.kt | 78++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
5 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -143,7 +143,7 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { */ object PreparedPaymentsTable : IdTable<String>() { /** the UUID representing this payment in the system */ - override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey() + override val id = varchar("id", ID_MAX_LENGTH).entityId() val paymentId = long("paymentId") val preparationDate = long("preparationDate") val submissionDate = long("submissionDate").nullable() @@ -188,7 +188,7 @@ class PreparedPaymentEntity(id: EntityID<String>) : Entity<String>(id) { * This table holds triples of <iban, bic, holder name>. */ object NexusBankAccountsTable : IdTable<String>() { - override val id = varchar("id", ID_MAX_LENGTH).primaryKey().entityId() + override val id = varchar("id", ID_MAX_LENGTH).entityId() val accountHolder = text("accountHolder") val iban = text("iban") val bankCode = text("bankCode") @@ -241,7 +241,6 @@ class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) { object NexusUsersTable : IdTable<String>() { override val id = varchar("id", ID_MAX_LENGTH).entityId() - override val primaryKey = PrimaryKey(id, name = "id") val passwordHash = text("password") val superuser = bool("superuser") } @@ -253,7 +252,7 @@ class NexusUserEntity(id: EntityID<String>) : Entity<String>(id) { } object NexusBankConnectionsTable : IdTable<String>() { - override val id = NexusBankConnectionsTable.text("id").entityId().primaryKey() + override val id = NexusBankConnectionsTable.text("id").entityId() val type = text("type") val owner = reference("user", NexusUsersTable) } @@ -266,7 +265,6 @@ class NexusBankConnectionEntity(id: EntityID<String>) : Entity<String>(id) { object FacadesTable : IdTable<String>() { override val id = FacadesTable.text("id").entityId() - override val primaryKey = PrimaryKey(id, name = "id") val type = text("type") val creator = reference("creator", NexusUsersTable) val highestSeenMsgID = long("highestSeenMessageID").default(0) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -430,7 +430,7 @@ fun serverMain(dbName: String) { return@intercept } - schedulePeriodicWork() + //schedulePeriodicWork() routing { /** * Shows information about the requesting user. diff --git a/nexus/src/test/kotlin/DBTest.kt b/nexus/src/test/kotlin/DBTest.kt @@ -44,22 +44,20 @@ class DBTest { TalerFacadeStatesTable, NexusUsersTable ) - val talerConfig = TalerFacadeStateEntity.new { - bankAccount = "b" - bankConnection = "b" - reserveTransferLevel = "any" - intervalIncrement = "any" - } - talerConfig.flush() val user = NexusUserEntity.new("u") { passwordHash = "x" superuser = true } - FacadeEntity.new("my-id") { + val facade = FacadeEntity.new("my-id") { type = "any" creator = user - config = talerConfig - highestSeenMsgID = 0 + } + val talerConfig = TalerFacadeStateEntity.new { + bankAccount = "b" + bankConnection = "b" + reserveTransferLevel = "any" + intervalIncrement = "any" + this.facade = facade } } } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -871,6 +871,7 @@ private fun handleEbicsUploadTransactionInitialization(requestContext: RequestCo this.numSegments = numSegments.toInt() this.transactionKeyEnc = ExposedBlob(transactionKeyEnc) }.flush() + logger.debug("after SQL flush") val sigObj = XMLUtil.convertStringToJaxb<UserSignatureData>(plainSigData.toString(Charsets.UTF_8)) logger.debug("got UserSignatureData: ${plainSigData.toString(Charsets.UTF_8)}") for (sig in sigObj.value.orderSignatureList ?: listOf()) { diff --git a/sandbox/src/test/kotlin/DBTest.kt b/sandbox/src/test/kotlin/DBTest.kt @@ -9,10 +9,35 @@ import tech.libeufin.sandbox.PaymentEntity import tech.libeufin.sandbox.PaymentsTable import tech.libeufin.util.millis import tech.libeufin.util.parseDashedDate +import java.io.File import java.sql.Connection import java.time.Instant import java.time.LocalDateTime +/** + * Run a block after connecting to the test database. + * Cleans up the DB file afterwards. + */ +fun withTestDatabase(f: () -> Unit) { + val dbfile = "nexus-test.sqlite3" + File(dbfile).also { + if (it.exists()) { + it.delete() + } + } + Database.connect("jdbc:sqlite:$dbfile", "org.sqlite.JDBC") + try { + f() + } + finally { + File(dbfile).also { + if (it.exists()) { + it.delete() + } + } + } +} + class DBTest { @Test fun exist() { @@ -21,33 +46,34 @@ class DBTest { @Test fun betweenDates() { - Database.connect("jdbc:sqlite:sandbox-test.sqlite3", "org.sqlite.JDBC") - TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE - transaction { - SchemaUtils.create(PaymentsTable) - PaymentEntity.new { - creditorIban = "earns" - creditorBic = "BIC" - creditorName = "Creditor Name" - debitorIban = "spends" - debitorBic = "BIC" - debitorName = "Debitor Name" - subject = "deal" - amount = "EUR:1" - date = LocalDateTime.now().millis() + withTestDatabase { + transaction { + SchemaUtils.create(PaymentsTable) + PaymentEntity.new { + creditorIban = "earns" + creditorBic = "BIC" + creditorName = "Creditor Name" + debitorIban = "spends" + debitorBic = "BIC" + debitorName = "Debitor Name" + subject = "deal" + amount = "EUR:1" + date = LocalDateTime.now().millis() + currency = "EUR" + } } + val result = transaction { + addLogger(StdOutSqlLogger) + PaymentEntity.find { + PaymentsTable.date.between( + parseDashedDate( + "1970-01-01" + ).millis(), + LocalDateTime.now().millis() + ) + }.firstOrNull() + } + assert(result != null) } - val result = transaction { - addLogger(StdOutSqlLogger) - PaymentEntity.find { - PaymentsTable.date.between( - parseDashedDate( - "1970-01-01" - ).millis(), - LocalDateTime.now().millis() - ) - }.firstOrNull() - } - assert(result != null) } } \ No newline at end of file