gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Isolating Exposed issue.


From: gnunet
Subject: [libeufin] branch master updated: Isolating Exposed issue.
Date: Fri, 05 Jun 2020 17:55:38 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 7086614  Isolating Exposed issue.
7086614 is described below

commit 708661483b61f2d420a6a51c68220c3f5e141d38
Author: MS <ms@taler.net>
AuthorDate: Fri Jun 5 17:54:07 2020 +0200

    Isolating Exposed issue.
---
 nexus/src/test/kotlin/SelfContainedDBTest.kt | 96 ++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/nexus/src/test/kotlin/SelfContainedDBTest.kt 
b/nexus/src/test/kotlin/SelfContainedDBTest.kt
new file mode 100644
index 0000000..5d7974f
--- /dev/null
+++ b/nexus/src/test/kotlin/SelfContainedDBTest.kt
@@ -0,0 +1,96 @@
+import org.jetbrains.exposed.dao.Entity
+import org.jetbrains.exposed.dao.EntityClass
+import org.jetbrains.exposed.dao.IntEntity
+import org.jetbrains.exposed.dao.IntEntityClass
+import org.jetbrains.exposed.dao.id.EntityID
+import org.jetbrains.exposed.dao.id.IdTable
+import org.jetbrains.exposed.dao.id.IntIdTable
+import org.jetbrains.exposed.sql.Database
+import org.jetbrains.exposed.sql.SchemaUtils
+import org.jetbrains.exposed.sql.StdOutSqlLogger
+import org.jetbrains.exposed.sql.addLogger
+import org.jetbrains.exposed.sql.transactions.transaction
+import org.junit.Test
+import java.io.File
+
+/**
+ * Run a block after connecting to the test database.
+ * Cleans up the DB file afterwards.
+ */
+fun withTestDatabase(f: () -> Unit) {
+    val dbfile = "test-db.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()
+            }
+        }
+    }
+}
+
+object ContainedTableWithIntId : IntIdTable() {
+    val column = text("column")
+}
+class ContainedEntityWithIntId(id: EntityID<Int>) : IntEntity(id) {
+    companion object : 
IntEntityClass<ContainedEntityWithIntId>(ContainedTableWithIntId)
+    var column by ContainedTableWithIntId.column
+}
+
+object ContainedTableWithStringId : IdTable<String>() {
+    override val id = varchar("id", 10).entityId()
+    override val primaryKey = PrimaryKey(id, name = "id")
+    val column = text("column")
+
+}
+class ContainedEntityWithStringId(id: EntityID<String>) : Entity<String>(id) {
+    companion object : EntityClass<String, 
ContainedEntityWithStringId>(ContainedTableWithStringId)
+    var column by ContainedTableWithStringId.column
+}
+
+object ContainingTable : IdTable<String>() {
+    override val id = varchar("id", 10).entityId()
+    override val primaryKey = PrimaryKey(id, name = "id")
+    val referenceStringId = reference("referenceStringId", 
ContainedTableWithStringId)
+    val referenceIntId = reference("referenceIntId", ContainedTableWithIntId)
+}
+class ContainingEntity(id: EntityID<String>) : Entity<String>(id) {
+    companion object : EntityClass<String, ContainingEntity>(ContainingTable)
+    var referenceStringId by ContainedEntityWithStringId referencedOn 
ContainingTable.referenceStringId
+    var referenceIntId by ContainedEntityWithIntId referencedOn 
ContainingTable.referenceIntId
+}
+
+class DBTest {
+    @Test
+    fun facadeConfigTest() {
+        withTestDatabase {
+            transaction {
+                addLogger(StdOutSqlLogger)
+                SchemaUtils.create(
+                    ContainingTable,
+                    ContainedTableWithIntId,
+                    ContainedTableWithStringId
+                )
+                val entityWithIntId = ContainedEntityWithIntId.new {
+                    column = "value"
+                }
+                entityWithIntId.flush()
+                val entityWithStringId = 
ContainedEntityWithStringId.new("contained-id") {
+                    column = "another value"
+                }
+                ContainingEntity.new("containing-id") {
+                    referenceIntId = entityWithIntId
+                    referenceStringId = entityWithStringId
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]