Merge pull request #32 from flecomte/minor_fix
This commit is contained in:
@@ -41,7 +41,7 @@ tasks.test {
|
||||
useJUnit()
|
||||
useJUnitPlatform()
|
||||
systemProperty("junit.jupiter.execution.parallel.enabled", true)
|
||||
if (disableLint.toBoolean() == false) {
|
||||
if (!disableLint.toBoolean()) {
|
||||
finalizedBy(tasks.ktlintCheck)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ services:
|
||||
context: docker/postgresql
|
||||
restart: always
|
||||
ports:
|
||||
- 5555:5432
|
||||
- "5555:5432"
|
||||
environment:
|
||||
POSTGRES_DB: json_test
|
||||
POSTGRES_USER: test
|
||||
|
||||
@@ -14,9 +14,9 @@ data class Paginated<T : EntityI>(
|
||||
val totalPages: Int = (total.toDouble() / limit.toDouble()).ceil()
|
||||
|
||||
init {
|
||||
if (offset < 0) error("offset must be greather or equal than 0")
|
||||
if (limit < 1) error("limit must be greather or equal than 1")
|
||||
if (total < 0) error("total must be greather or equal than 0")
|
||||
if (offset < 0) error("offset must be greater or equal than 0")
|
||||
if (limit < 1) error("limit must be greater or equal than 1")
|
||||
if (total < 0) error("total must be greater or equal than 0")
|
||||
}
|
||||
|
||||
fun isLastPage(): Boolean = currentPage >= totalPages
|
||||
|
||||
@@ -21,7 +21,7 @@ class Function(
|
||||
|
||||
val queryMatch = functionRegex.find(script)
|
||||
if (queryMatch !== null) {
|
||||
val functionName = queryMatch.groups.get("name")?.value?.trim() ?: error("Function name not found")
|
||||
val functionName = queryMatch.groups["name"]?.value?.trim() ?: error("Function name not found")
|
||||
val functionParameters = queryMatch.groups["params"]?.value?.trim()
|
||||
this.returns = queryMatch.groups["return"]?.value?.trim() ?: ""
|
||||
|
||||
@@ -51,15 +51,12 @@ class Function(
|
||||
fun getDefinition(): String {
|
||||
return parameters
|
||||
.filter { it.direction == Parameter.Direction.IN }
|
||||
.joinToString(", ") { "${it.name} ${it.type}" }.let {
|
||||
"$name ($it)"
|
||||
}
|
||||
.joinToString(", ") { "${it.name} ${it.type}" }
|
||||
.let { "$name ($it)" }
|
||||
}
|
||||
|
||||
fun getParametersIndexedByName(): Map<String, Parameter> {
|
||||
return parameters.map {
|
||||
it.name to it
|
||||
}.toMap()
|
||||
return parameters.associateBy { it.name }
|
||||
}
|
||||
|
||||
infix fun `has same definition`(other: Function): Boolean {
|
||||
|
||||
@@ -37,36 +37,44 @@ data class Function(
|
||||
)
|
||||
|
||||
override fun up(): Status {
|
||||
try {
|
||||
connection.sendQuery(up.script)
|
||||
} catch (e: CompletionException) {
|
||||
val cause = e.cause
|
||||
if (cause is GenericDatabaseException && cause.errorMessage.fields['C'] == "42P13") {
|
||||
connection.sendQuery("drop function ${down.getDefinition()}")
|
||||
return try {
|
||||
try {
|
||||
connection.sendQuery(up.script)
|
||||
} catch (e: CompletionException) {
|
||||
val cause = e.cause
|
||||
if (cause is GenericDatabaseException && cause.errorMessage.fields['C'] == "42P13") {
|
||||
connection.sendQuery("drop function ${down.getDefinition()}")
|
||||
connection.sendQuery(up.script)
|
||||
}
|
||||
}
|
||||
|
||||
this::class.java.classLoader
|
||||
.getResource("sql/migration/insertFunction.sql")!!.readText()
|
||||
.let { connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script)) }
|
||||
?.let { function ->
|
||||
executedAt = function.executedAt
|
||||
doExecute = Action.OK
|
||||
}
|
||||
|
||||
Status.OK
|
||||
} catch (e: Throwable) {
|
||||
Status.UP_FAIL
|
||||
}
|
||||
|
||||
this::class.java.classLoader
|
||||
.getResource("sql/migration/insertFunction.sql")!!.readText()
|
||||
.let { connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script)) }
|
||||
?.let { function ->
|
||||
executedAt = function.executedAt
|
||||
doExecute = Action.OK
|
||||
}
|
||||
|
||||
return Status.OK
|
||||
}
|
||||
|
||||
override fun down(): Status {
|
||||
connection.sendQuery(down.script)
|
||||
return try {
|
||||
connection.sendQuery(down.script)
|
||||
|
||||
this::class.java.classLoader
|
||||
.getResource("sql/migration/deleteFunction.sql")!!
|
||||
.readText()
|
||||
.let { connection.sendQuery(it, listOf(down.name)) }
|
||||
this::class.java.classLoader
|
||||
.getResource("sql/migration/deleteFunction.sql")!!
|
||||
.readText()
|
||||
.let { connection.sendQuery(it, listOf(down.name)) }
|
||||
|
||||
return Status.OK
|
||||
Status.OK
|
||||
} catch (e: Throwable) {
|
||||
Status.DOWN_FAIL
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(): Status {
|
||||
|
||||
@@ -29,11 +29,11 @@ interface Migration {
|
||||
fun down(): Status
|
||||
fun test(): Status
|
||||
|
||||
enum class Status(i: Int) { OK(2), UP_FAIL(0), DOWN_FAIL(1) }
|
||||
enum class Status(val i: Int) { OK(2), UP_FAIL(0), DOWN_FAIL(1) }
|
||||
enum class Action { OK, UP, DOWN }
|
||||
}
|
||||
|
||||
data class Migrations private constructor(
|
||||
class Migrations private constructor(
|
||||
private val connection: Connection,
|
||||
private val migrationsScripts: MutableMap<String, MigrationScript> = mutableMapOf(),
|
||||
private val functions: MutableMap<String, Function> = mutableMapOf()
|
||||
@@ -49,7 +49,7 @@ data class Migrations private constructor(
|
||||
reset()
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
private fun reset() {
|
||||
migrationsScripts.clear()
|
||||
functions.clear()
|
||||
|
||||
@@ -76,14 +76,14 @@ data class Migrations private constructor(
|
||||
*/
|
||||
private fun getMigrationFromDB() {
|
||||
this::class.java.classLoader.getResource("sql/migration/findAllFunction.sql")!!.readText().let {
|
||||
connection.select<MigrationEntity>(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||
connection.select(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||
.map { function ->
|
||||
functions[function.filename] = Function(function.up, function.down, connection, function.executedAt)
|
||||
}
|
||||
}
|
||||
|
||||
this::class.java.classLoader.getResource("sql/migration/findAllHistory.sql")!!.readText().let {
|
||||
connection.select<MigrationEntity>(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||
connection.select(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||
.map { query ->
|
||||
migrationsScripts[query.filename] = MigrationScript(query.filename, query.up, query.down, connection, query.executedAt)
|
||||
}
|
||||
@@ -130,7 +130,7 @@ data class Migrations private constructor(
|
||||
enum class Direction { UP, DOWN }
|
||||
|
||||
internal class DownMigrationNotDefined(path: String, cause: FileNotFoundException? = null) :
|
||||
Throwable("The file $path whas not found", cause)
|
||||
Throwable("The file $path was not found", cause)
|
||||
|
||||
fun addFunction(newDefinition: DefinitionFunction, callback: (Function) -> Unit = {}): Migrations {
|
||||
val currentFunction = functions[newDefinition.name]
|
||||
@@ -174,10 +174,10 @@ data class Migrations private constructor(
|
||||
|
||||
private fun initDB() {
|
||||
if (!initialized) {
|
||||
this::class.java.classLoader.getResource("sql/migration/createHistoryShema.sql")!!.readText().let {
|
||||
this::class.java.classLoader.getResource("sql/migration/createHistorySchema.sql")!!.readText().let {
|
||||
connection.sendQuery(it)
|
||||
}
|
||||
this::class.java.classLoader.getResource("sql/migration/createFunctionShema.sql")!!.readText().let {
|
||||
this::class.java.classLoader.getResource("sql/migration/createFunctionSchema.sql")!!.readText().let {
|
||||
connection.sendQuery(it)
|
||||
}
|
||||
initialized = true
|
||||
@@ -297,7 +297,7 @@ data class Migrations private constructor(
|
||||
return list.toMap()
|
||||
}
|
||||
|
||||
fun copy(): Migrations {
|
||||
private fun copy(): Migrations {
|
||||
val queriesCopy = migrationsScripts.map {
|
||||
it.key to it.value.copy()
|
||||
}.toMap().toMutableMap()
|
||||
|
||||
@@ -6,5 +6,5 @@ import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
internal class LoggerDelegate<in R : Any> : ReadOnlyProperty<R, Logger> {
|
||||
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
||||
override fun getValue(thisRef: R, property: KProperty<*>): Logger = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import kotlin.streams.asSequence
|
||||
|
||||
fun URL.searchSqlFiles() = this.toURI().searchSqlFiles()
|
||||
|
||||
fun URI.searchSqlFiles() = sequence<Resource> {
|
||||
fun URI.searchSqlFiles() = sequence {
|
||||
val logger: Logger = LoggerFactory.getLogger("sqlFilesSearch")
|
||||
val uri: URI = this@searchSqlFiles
|
||||
logger.debug("""SQL files found in "${uri.toString().substringAfter('!')}" :""")
|
||||
|
||||
@@ -9,16 +9,15 @@ import fr.postgresjson.entity.Parameter
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.serializer.deserialize
|
||||
import fr.postgresjson.serializer.toTypeReference
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.UUID
|
||||
import kotlin.test.assertContains
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ConnectionTest : TestAbstract() {
|
||||
@@ -32,7 +31,7 @@ class ConnectionTest : TestAbstract() {
|
||||
fun getObject() {
|
||||
val obj: ObjTest? = connection.selectOne("select to_json(a) from test a limit 1")
|
||||
assertTrue(obj is ObjTest)
|
||||
assertTrue(obj!!.id == UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"))
|
||||
assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), obj.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +59,7 @@ class ConnectionTest : TestAbstract() {
|
||||
fun `test call request with args`() {
|
||||
val result: ObjTest? = connection.selectOne("select json_build_object('id', '2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00', 'name', ?::text)", listOf("myName"))
|
||||
assertNotNull(result)
|
||||
assertEquals("myName", result!!.name)
|
||||
assertEquals("myName", result.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +68,7 @@ class ConnectionTest : TestAbstract() {
|
||||
assertEquals("myName", this.rows[0].getString(0)?.deserialize<ObjTest>()?.name)
|
||||
}
|
||||
assertNotNull(result)
|
||||
assertEquals("myName", result!!.name)
|
||||
assertEquals("myName", result.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,9 +88,8 @@ class ConnectionTest : TestAbstract() {
|
||||
val o = ObjTest("myName", id = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00"))
|
||||
val obj: ObjTest? = connection.selectOne("select json_build_object('id', id, 'name', name) FROM json_to_record(?::json) as o(id uuid, name text);", listOf(o))
|
||||
assertNotNull(obj)
|
||||
assertTrue(obj is ObjTest)
|
||||
assertEquals(obj!!.id, UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00"))
|
||||
assertEquals(obj.name, "myName")
|
||||
assertEquals(UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00"), obj.id)
|
||||
assertEquals("myName", obj.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,15 +97,15 @@ class ConnectionTest : TestAbstract() {
|
||||
val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"))
|
||||
val objUpdated: ObjTest? = connection.update("select ?::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), obj)
|
||||
assertTrue(objUpdated is ObjTest)
|
||||
assertTrue(objUpdated!!.id == UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"))
|
||||
assertTrue(objUpdated.name == "after")
|
||||
assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id)
|
||||
assertEquals("after", objUpdated.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun callExec() {
|
||||
val o = ObjTest("myName")
|
||||
val result = connection.exec("select json_build_object('id', '2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00', 'name', ?::json->>'name')", listOf(o))
|
||||
Assertions.assertEquals(1, result.rowsAffected)
|
||||
assertEquals(1, result.rowsAffected)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,9 +118,10 @@ class ConnectionTest : TestAbstract() {
|
||||
"third" to 123
|
||||
)
|
||||
)
|
||||
assertEquals(result!!.first, "ff")
|
||||
assertEquals(result.second, "sec")
|
||||
assertEquals(result.third, 123)
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result.first)
|
||||
assertEquals("sec", result.second)
|
||||
assertEquals(123, result.third)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,7 +133,8 @@ class ConnectionTest : TestAbstract() {
|
||||
"second" to ParameterObject("two")
|
||||
)
|
||||
)
|
||||
assertEquals("one", result!!.first.third)
|
||||
assertNotNull(result)
|
||||
assertEquals("one", result.first.third)
|
||||
assertEquals("two", result.second.third)
|
||||
}
|
||||
|
||||
@@ -153,9 +153,9 @@ class ConnectionTest : TestAbstract() {
|
||||
"second" to "sec"
|
||||
)
|
||||
)
|
||||
assertEquals(result[0].first, "ff")
|
||||
assertEquals(result[0].second, "sec")
|
||||
assertEquals(result[0].third, 123)
|
||||
assertEquals("ff", result[0].first)
|
||||
assertEquals("sec", result[0].second)
|
||||
assertEquals(123, result[0].third)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,9 +171,9 @@ class ConnectionTest : TestAbstract() {
|
||||
"third" to 123,
|
||||
"second" to "sec"
|
||||
)
|
||||
assertEquals(result[0].first, "ff")
|
||||
assertEquals(result[0].second, "sec")
|
||||
assertEquals(result[0].third, 123)
|
||||
assertEquals("ff", result[0].first)
|
||||
assertEquals("sec", result[0].second)
|
||||
assertEquals(123, result[0].third)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,10 +192,10 @@ class ConnectionTest : TestAbstract() {
|
||||
|
||||
)
|
||||
assertNotNull(result)
|
||||
assertEquals(result.result[0].name, "ff")
|
||||
assertEquals(result.result[1].name, "ff-2")
|
||||
assertEquals(result.total, 10)
|
||||
assertEquals(result.offset, 0)
|
||||
assertEquals("ff", result.result[0].name)
|
||||
assertEquals("ff-2", result.result[1].name)
|
||||
assertEquals(10, result.total)
|
||||
assertEquals(0, result.offset)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,8 +214,8 @@ class ConnectionTest : TestAbstract() {
|
||||
assertNotNull(result)
|
||||
assertTrue(result.result.isEmpty())
|
||||
assertEquals(0, result.result.size)
|
||||
assertEquals(result.total, 10)
|
||||
assertEquals(result.offset, 0)
|
||||
assertEquals(10, result.total)
|
||||
assertEquals(0, result.offset)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,8 +242,8 @@ class ConnectionTest : TestAbstract() {
|
||||
assertNotNull(result)
|
||||
assertEquals("myName", result.result[0].name)
|
||||
assertEquals(1, result.result.size)
|
||||
assertEquals(result.total, 10)
|
||||
assertEquals(result.offset, 0)
|
||||
assertEquals(10, result.total)
|
||||
assertEquals(0, result.offset)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,11 +336,12 @@ class ConnectionTest : TestAbstract() {
|
||||
""".trimIndent(),
|
||||
params
|
||||
) {
|
||||
assertEquals("ff", it!!.first)
|
||||
assertNotNull(it)
|
||||
assertEquals("ff", it.first)
|
||||
assertEquals("plop", rows[0].getString("other"))
|
||||
}
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result!!.first)
|
||||
assertEquals("ff", result.first)
|
||||
assertEquals("sec", result.second)
|
||||
assertEquals(123, result.third)
|
||||
}
|
||||
@@ -371,7 +372,8 @@ class ConnectionTest : TestAbstract() {
|
||||
"second" to ParameterObject("two")
|
||||
)
|
||||
).let { result ->
|
||||
assertEquals("one", result!!.first.third)
|
||||
assertNotNull(result)
|
||||
assertEquals("one", result.first.third)
|
||||
assertEquals("two", result.second.third)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import fr.postgresjson.connexion.selectOne
|
||||
import fr.postgresjson.connexion.update
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.serializer.deserialize
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.UUID
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class RequesterTest : TestAbstract() {
|
||||
@@ -83,13 +83,14 @@ class RequesterTest : TestAbstract() {
|
||||
|
||||
@Test
|
||||
fun `add query from string`() {
|
||||
val result: Int = Requester(connection)
|
||||
val result: Int? = Requester(connection)
|
||||
.apply { addQuery("simpleTest", "select 42;") }
|
||||
.getQuery("simpleTest")
|
||||
.exec()
|
||||
.rows[0].getInt(0)!!
|
||||
.rows[0].getInt(0)
|
||||
|
||||
assertEquals(result, 42)
|
||||
assertNotNull(result)
|
||||
assertEquals(42, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,8 +101,9 @@ class RequesterTest : TestAbstract() {
|
||||
.getQuery("selectOne")
|
||||
.selectOne()
|
||||
|
||||
assertEquals(objTest!!.id, UUID.fromString("829b1a29-5db8-47f9-9562-961c561ac528"))
|
||||
assertEquals(objTest.name, "test")
|
||||
assertNotNull(objTest)
|
||||
assertEquals(objTest.id, UUID.fromString("829b1a29-5db8-47f9-9562-961c561ac528"))
|
||||
assertEquals("test", objTest.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +140,9 @@ class RequesterTest : TestAbstract() {
|
||||
.getFunction("test_function")
|
||||
.selectOne(listOf("test", "plip"))
|
||||
|
||||
assertEquals(objTest!!.id, UUID.fromString("457daad5-4f1b-4eb7-80ec-6882adb8cc7d"))
|
||||
assertEquals(objTest.name, "test")
|
||||
assertNotNull(objTest)
|
||||
assertEquals(objTest.id, UUID.fromString("457daad5-4f1b-4eb7-80ec-6882adb8cc7d"))
|
||||
assertEquals("test", objTest.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -284,10 +287,11 @@ class RequesterTest : TestAbstract() {
|
||||
@Test
|
||||
fun `call selectOne on function`() {
|
||||
val resources = this::class.java.getResource("/sql/function/Test")?.toURI()
|
||||
val obj: ObjTest = Requester(connection, functionsDirectory = resources)
|
||||
val obj: ObjTest? = Requester(connection, functionsDirectory = resources)
|
||||
.getFunction("test_function")
|
||||
.selectOne(mapOf("name" to "myName"))!!
|
||||
.selectOne(mapOf("name" to "myName"))
|
||||
|
||||
assertNotNull(obj)
|
||||
assertEquals("myName", obj.name)
|
||||
}
|
||||
|
||||
@@ -295,10 +299,11 @@ class RequesterTest : TestAbstract() {
|
||||
fun `call selectOne on function with object and named argument`() {
|
||||
val resources = this::class.java.getResource("/sql/function/Test")?.toURI()
|
||||
val obj2 = ObjTest("original")
|
||||
val obj: ObjTest = Requester(connection, functionsDirectory = resources)
|
||||
val obj: ObjTest? = Requester(connection, functionsDirectory = resources)
|
||||
.getFunction("test_function_object")
|
||||
.selectOne("resource" to obj2)!!
|
||||
.selectOne("resource" to obj2)
|
||||
|
||||
assertNotNull(obj)
|
||||
assertEquals("changedName", obj.name)
|
||||
assertEquals("original", obj2.name)
|
||||
}
|
||||
@@ -307,10 +312,11 @@ class RequesterTest : TestAbstract() {
|
||||
fun `call selectOne on function with object`() {
|
||||
val resources = this::class.java.getResource("/sql/function/Test")?.toURI()
|
||||
val obj2 = ObjTest("original")
|
||||
val obj: ObjTest = Requester(connection, functionsDirectory = resources)
|
||||
val obj: ObjTest? = Requester(connection, functionsDirectory = resources)
|
||||
.getFunction("test_function_object")
|
||||
.update(obj2)!!
|
||||
.update(obj2)
|
||||
|
||||
assertNotNull(obj)
|
||||
assertEquals("changedName", obj.name)
|
||||
assertEquals("original", obj2.name)
|
||||
}
|
||||
@@ -318,20 +324,22 @@ class RequesterTest : TestAbstract() {
|
||||
@Test
|
||||
fun `call selectOne on function with object and no arguments`() {
|
||||
val resources = this::class.java.getResource("/sql/function/Test")?.toURI()
|
||||
val obj: ObjTest = Requester(connection, functionsDirectory = resources)
|
||||
val obj: ObjTest? = Requester(connection, functionsDirectory = resources)
|
||||
.getFunction("test_function")
|
||||
.selectOne()!!
|
||||
.selectOne()
|
||||
|
||||
assertNotNull(obj)
|
||||
assertEquals("plop", obj.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call selectOne on query`() {
|
||||
val resources = this::class.java.getResource("/sql/query")?.toURI()
|
||||
val obj: ObjTest = Requester(connection, queriesDirectory = resources)
|
||||
val obj: ObjTest? = Requester(connection, queriesDirectory = resources)
|
||||
.getQuery("selectOneWithParameters")
|
||||
.selectOne(mapOf("name" to "myName"))!!
|
||||
.selectOne(mapOf("name" to "myName"))
|
||||
|
||||
assertNotNull(obj)
|
||||
assertEquals("myName", obj.name)
|
||||
}
|
||||
|
||||
@@ -342,6 +350,8 @@ class RequesterTest : TestAbstract() {
|
||||
.getFunction("test_function_multiple")
|
||||
.select(mapOf("name" to "myName"))
|
||||
|
||||
assertNotNull(obj[0])
|
||||
assertEquals("myName", obj[0].name)
|
||||
assertEquals("myName", obj[0].name)
|
||||
}
|
||||
|
||||
@@ -366,7 +376,7 @@ class RequesterTest : TestAbstract() {
|
||||
assertEquals("ff-2", result[1].name)
|
||||
}
|
||||
}.apply {
|
||||
select<ObjTest>(object : TypeReference<List<ObjTest>>() {}, mapOf("name" to "ff")).let { result ->
|
||||
select(object : TypeReference<List<ObjTest>>() {}, mapOf("name" to "ff")).let { result ->
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result[0].name)
|
||||
assertEquals("ff-2", result[1].name)
|
||||
@@ -385,7 +395,7 @@ class RequesterTest : TestAbstract() {
|
||||
assertEquals("ff-2", result[1].name)
|
||||
}
|
||||
}.apply {
|
||||
select<ObjTest>(object : TypeReference<List<ObjTest>>() {}, "name" to "ff").let { result ->
|
||||
select(object : TypeReference<List<ObjTest>>() {}, "name" to "ff").let { result ->
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result[0].name)
|
||||
assertEquals("ff-2", result[1].name)
|
||||
@@ -404,7 +414,7 @@ class RequesterTest : TestAbstract() {
|
||||
assertEquals("aa-2", result[1].name)
|
||||
}
|
||||
}.apply {
|
||||
select<ObjTest>(object : TypeReference<List<ObjTest>>() {}, listOf("ff", "aa")).let { result ->
|
||||
select(object : TypeReference<List<ObjTest>>() {}, listOf("ff", "aa")).let { result ->
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result[0].name)
|
||||
assertEquals("aa-2", result[1].name)
|
||||
@@ -438,7 +448,7 @@ class RequesterTest : TestAbstract() {
|
||||
assertEquals(0, offset)
|
||||
}
|
||||
}.apply {
|
||||
select<ObjTest>(1, 2, object : TypeReference<List<ObjTest>>() {}, mapOf("name" to "ff")).run {
|
||||
select(1, 2, object : TypeReference<List<ObjTest>>() {}, mapOf("name" to "ff")).run {
|
||||
assertNotNull(result)
|
||||
assertEquals("ff", result[0].name)
|
||||
assertEquals("ff-2", result[1].name)
|
||||
@@ -478,17 +488,19 @@ class RequesterTest : TestAbstract() {
|
||||
Requester(connection, queriesDirectory = resources)
|
||||
.getQuery("selectOneWithParameters").apply {
|
||||
selectOne<ObjTest>(mapOf("name" to "myName")) {
|
||||
assertEquals("myName", it!!.name)
|
||||
assertNotNull(it)
|
||||
assertEquals("myName", it.name)
|
||||
assertEquals("plop", rows[0].getString("other"))
|
||||
}!!.run {
|
||||
assertEquals("myName", name)
|
||||
}.run {
|
||||
assertEquals("selectOneWithParameters", name)
|
||||
}
|
||||
}.apply {
|
||||
selectOne<ObjTest>(typeReference = object : TypeReference<ObjTest>() {}, values = mapOf("name" to "myName")) { it ->
|
||||
assertEquals("myName", it!!.name)
|
||||
selectOne(typeReference = object : TypeReference<ObjTest>() {}, values = mapOf("name" to "myName")) {
|
||||
assertNotNull(it)
|
||||
assertEquals("myName", it.name)
|
||||
assertEquals("plop", rows[0].getString("other"))
|
||||
}!!.run {
|
||||
assertEquals("myName", name)
|
||||
}.run {
|
||||
assertEquals("selectOneWithParameters", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user