libeufin

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

commit d213843ce31f97d68c76ffc3602b4c649a832a5e
parent 06a57bdce3d5afad3e2f82f0c86180eba61825f9
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Fri, 18 Oct 2019 16:54:57 +0200

nested DB queries

Diffstat:
Msandbox/src/main/kotlin/DB.kt | 14++++++++------
Msandbox/src/test/kotlin/DbTest.kt | 22++++++++++++++++++++++
2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/sandbox/src/main/kotlin/DB.kt b/sandbox/src/main/kotlin/DB.kt @@ -71,7 +71,7 @@ enum class KeyStates { */ object BankCustomers: IntIdTable() { // Customer ID is the default 'id' field provided by the constructor. - val name = varchar("name", CUSTOMER_NAME_MAX_LENGTH) + val name = varchar("name", CUSTOMER_NAME_MAX_LENGTH).primaryKey() val ebicsSubscriber = reference("ebicsSubscriber", EbicsSubscribers) } @@ -93,7 +93,7 @@ class BankCustomer(id: EntityID<Int>) : IntEntity(id) { object EbicsUsers: IntIdTable() { /* EBICS user ID in the string form. */ - val userId = varchar("userId", EBICS_USER_ID_MAX_LENGTH).nullable() + val userId = varchar("userId", EBICS_USER_ID_MAX_LENGTH).primaryKey().nullable() } @@ -112,7 +112,7 @@ class EbicsUser(id: EntityID<Int>) : IntEntity(id){ * Table for UserID. */ object EbicsPartners: IntIdTable() { - val partnerId = varchar("partnerId", EBICS_PARTNER_ID_MAX_LENGTH).nullable() + val partnerId = varchar("partnerId", EBICS_PARTNER_ID_MAX_LENGTH).primaryKey().nullable() } @@ -174,9 +174,11 @@ class EbicsPublicKey(id: EntityID<Int>) : IntEntity(id) { * and systems. Each value can appear multiple times in the same column. */ object EbicsSubscribers: IntIdTable() { - val userId = reference("UserId", EbicsUsers) - val partnerId = reference("PartnerId", EbicsPartners) - val systemId = reference("SystemId", EbicsSystems) + + + val userId = reference("userId", EbicsUsers) + val partnerId = reference("partnerId", EbicsPartners) + val systemId = reference("systemId", EbicsSystems) val signatureKey = reference("signatureKey", EbicsPublicKeys).nullable() val encryptionKey = reference("encryptionKey", EbicsPublicKeys).nullable() diff --git a/sandbox/src/test/kotlin/DbTest.kt b/sandbox/src/test/kotlin/DbTest.kt @@ -1,9 +1,12 @@ package tech.libeufin.sandbox +import junit.framework.TestCase.assertFalse import org.jetbrains.exposed.dao.EntityID +import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.sql.Column import org.jetbrains.exposed.sql.transactions.transaction import org.junit.BeforeClass +import junit.framework.TestCase.assertTrue import org.junit.Test import org.junit.Before @@ -33,6 +36,8 @@ class DbTest { } } + + @Test fun nestedQuery() { @@ -43,5 +48,22 @@ class DbTest { * EbicsSubscribers.userId.userId eq "u1" * }.first() */ + + transaction { + createSubscriber() + + val tmp = EbicsUser.find { EbicsUsers.userId eq "u1" }.firstOrNull() + if (tmp == null) { + logger.error("No such user found in database.") + return@transaction + } + println("Found user with id: ${tmp.id.value}") + + val found = EbicsSubscriber.find { + EbicsSubscribers.userId eq EntityID(tmp.id.value, EbicsUsers) + } + + assertFalse(found.empty()) + } } } \ No newline at end of file