diff options
author | MS <ms@taler.net> | 2023-03-13 10:06:35 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2023-03-13 10:06:35 +0100 |
commit | 14c2af86551b402627923de5d49006ea1122afef (patch) | |
tree | 9770c105e96a1d6890e39e5abb4ab79bf4fff149 /sandbox | |
parent | d13ac7ba520b7959800905260777f79b5e9bf04c (diff) | |
download | libeufin-14c2af86551b402627923de5d49006ea1122afef.tar.gz libeufin-14c2af86551b402627923de5d49006ea1122afef.tar.bz2 libeufin-14c2af86551b402627923de5d49006ea1122afef.zip |
Testing #7515.
Diffstat (limited to 'sandbox')
-rw-r--r-- | sandbox/src/test/kotlin/BalanceTest.kt | 21 | ||||
-rw-r--r-- | sandbox/src/test/kotlin/DBTest.kt | 67 |
2 files changed, 55 insertions, 33 deletions
diff --git a/sandbox/src/test/kotlin/BalanceTest.kt b/sandbox/src/test/kotlin/BalanceTest.kt index 48497e98..cf9f3918 100644 --- a/sandbox/src/test/kotlin/BalanceTest.kt +++ b/sandbox/src/test/kotlin/BalanceTest.kt @@ -8,24 +8,21 @@ import java.math.BigDecimal import java.time.LocalDateTime class BalanceTest { - @Test fun balanceTest() { + val config = DemobankConfig( + currency = "EUR", + bankDebtLimit = 1000000, + usersDebtLimit = 10000, + allowRegistrations = true, + demobankName = "default", + withSignupBonus = false + ) withTestDatabase { transaction { - SchemaUtils.create( - BankAccountsTable, - BankAccountTransactionsTable, - BankAccountFreshTransactionsTable, - BankAccountStatementsTable - ) + insertConfigPairs(config) val demobank = DemobankConfigEntity.new { - currency = "EUR" - bankDebtLimit = 1000000 - usersDebtLimit = 10000 - allowRegistrations = true name = "default" - withSignupBonus = false } val one = BankAccountEntity.new { iban = "IBAN 1" diff --git a/sandbox/src/test/kotlin/DBTest.kt b/sandbox/src/test/kotlin/DBTest.kt index c74ebce1..c63efd6f 100644 --- a/sandbox/src/test/kotlin/DBTest.kt +++ b/sandbox/src/test/kotlin/DBTest.kt @@ -30,47 +30,72 @@ import java.time.LocalDateTime * Cleans up the DB file afterwards. */ fun withTestDatabase(f: () -> Unit) { - val dbfile = "jdbc:sqlite:/tmp/nexus-test.sqlite3" - File(dbfile).also { + val dbFile = "/tmp/sandbox-test.sqlite3" + val dbConn = "jdbc:sqlite:${dbFile}" + File(dbFile).also { if (it.exists()) { it.delete() } } - Database.connect("$dbfile") - dbDropTables(dbfile) - try { - f() - } + Database.connect(dbConn) + dbDropTables(dbConn) + dbCreateTables(dbConn) + try { f() } finally { - File(dbfile).also { - if (it.exists()) { + File(dbFile).also { + if (it.exists()) it.delete() - } } } } class DBTest { + private var config = DemobankConfig( + currency = "EUR", + bankDebtLimit = 1000000, + usersDebtLimit = 10000, + allowRegistrations = true, + demobankName = "default", + withSignupBonus = false, + ) + + /** + * Storing configuration values into the database, + * then extract them and check that they equal the + * configuration model object. + */ @Test - fun exist() { - println("x") + fun insertPairsTest() { + withTestDatabase { + // Config model. + val config = DemobankConfig( + currency = "EUR", + bankDebtLimit = 1, + usersDebtLimit = 2, + allowRegistrations = true, + demobankName = "default", + withSignupBonus = true + ) + transaction { + DemobankConfigEntity.new { name = "default" } + insertConfigPairs(config) + val db = getDefaultDemobank() + /** + * db.config extracts config values from the database + * and puts them in a fresh config model object. + */ + assert(config.hashCode() == db.config.hashCode()) + } + } } @Test fun betweenDates() { withTestDatabase { transaction { - SchemaUtils.create( - BankAccountTransactionsTable, - BankAccountFreshTransactionsTable - ) + insertConfigPairs(config) val demobank = DemobankConfigEntity.new { - currency = "EUR" - bankDebtLimit = 1000000 - usersDebtLimit = 10000 - allowRegistrations = true name = "default" - withSignupBonus = false } val bankAccount = BankAccountEntity.new { iban = "iban" |