libeufin

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

commit d2184eeac65907be5c32505ec0ee8297189b8f34
parent e3b67ab317a61b44cf7f40fb83cdca1cf3206411
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue, 18 Feb 2020 22:48:44 +0100

use long to represent date values.

Also, create wrapper class to hold all the
values needed to create a PAIN.001 instance.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 5+++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 27+++++++++++++++++++++++++++
Mnexus/src/test/kotlin/DbTest.kt | 17+++++++++++++++++
3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -4,6 +4,7 @@ import org.jetbrains.exposed.dao.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction +import org.joda.time.DateTime import tech.libeufin.nexus.EbicsSubscribersTable.entityId import tech.libeufin.nexus.EbicsSubscribersTable.primaryKey import tech.libeufin.util.IntIdTableWithAmount @@ -60,7 +61,7 @@ const val ID_MAX_LENGTH = 50 object Pain001Table : IntIdTableWithAmount() { val msgId = integer("msgId").uniqueIndex().autoIncrement() val paymentId = integer("paymentId").uniqueIndex().autoIncrement() // id for this system - val date = date("fileDate").date() + val fileDate = long("fileDate").default(DateTime.now().millis) val sum = amount("sum") val debtorAccount = text("debtorAccount") val endToEndId = integer("EndToEndId").uniqueIndex().autoIncrement() // id for this and the creditor system @@ -77,7 +78,7 @@ class Pain001Entity(id: EntityID<Int>) : IntEntity(id) { var msgId by Pain001Table.msgId var paymentId by Pain001Table.paymentId - var date by Pain001Table.date + var date by Pain001Table.fileDate var sum by Pain001Table.sum var debtorAccount by Pain001Table.debtorAccount var endToEndId by Pain001Table.endToEndId diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -158,6 +158,33 @@ fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails { } } +data class Pain001Entry( + val debtorAccountId: String, + val creditorIban: String, + val creditorBic: String, + val creditorName: String, + val sum: Amount, + val subject: String + +) + +/** + * Insert one row in the database, and leaves it marked as non-submitted. + */ +fun createPain001entry(entry: Pain001Entry) { + transaction { + Pain001Entity.new { + subject = entry.subject + sum = entry.sum + debtorAccount = entry.debtorAccountId + creditorName = entry.creditorName + creditorBic = entry.creditorBic + creditorIban = entry.creditorIban + } + } + +} + fun main() { dbCreateTables() testData() diff --git a/nexus/src/test/kotlin/DbTest.kt b/nexus/src/test/kotlin/DbTest.kt @@ -7,6 +7,8 @@ import org.junit.Test import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.SchemaUtils +import org.joda.time.DateTime +import tech.libeufin.util.Amount import javax.sql.rowset.serial.SerialBlob @@ -17,6 +19,7 @@ class DbTest { Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver") transaction { SchemaUtils.create(EbicsSubscribersTable) + SchemaUtils.create(Pain001Table) } } @@ -36,4 +39,18 @@ class DbTest { assert(EbicsSubscriberEntity.findById("123asdf") != null) } } + + @Test + fun testPain001() { + createPain001entry( + Pain001Entry( + debtorAccountId = "da", + creditorBic = "cb", + creditorIban = "ci", + creditorName = "cn", + sum = Amount(2), + subject = "s" + ) + ) + } } \ No newline at end of file