summaryrefslogtreecommitdiff
path: root/nexus/src/test/kotlin/DBTest.kt
blob: 3b818942d7e946c95a83cd3ecd7a4844d1bad3b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package tech.libeufin.nexus

import org.jetbrains.exposed.exceptions.ExposedSQLException
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.Test
import withTestDatabase
import java.io.File

object MyTable : Table() {
    val col1 = text("col1")
    val col2 = text("col2")
    override val primaryKey = PrimaryKey(col1, col2)
}

class DBTest {
    @Test(expected = ExposedSQLException::class)
    fun sqlDslTest() {
        withTestDatabase {
            transaction {
                addLogger(StdOutSqlLogger)
                SchemaUtils.create(MyTable)
                MyTable.insert {
                    it[col1] = "foo"
                    it[col2] = "bar"
                }
                // should throw ExposedSQLException
                MyTable.insert {
                    it[col1] = "foo"
                    it[col2] = "bar"
                }
                MyTable.insert {  } // shouldn't it fail for non-NULL constraint violation?
            }
        }
    }

    @Test
    fun facadeConfigTest() {
        withTestDatabase {
            transaction {
                addLogger(StdOutSqlLogger)
                SchemaUtils.create(
                    FacadesTable,
                    FacadeStateTable,
                    NexusUsersTable
                )
                val user = NexusUserEntity.new {
                    username = "testuser"
                    passwordHash = "x"
                    superuser = true
                }
                val facade = FacadeEntity.new {
                    facadeName = "testfacade"
                    type = "any"
                    creator = user
                }
                FacadeStateEntity.new {
                    bankAccount = "b"
                    bankConnection = "b"
                    reserveTransferLevel = "any"
                    this.facade = facade
                    currency = "UNUSED"
                }
            }
        }
    }
}