improve-tests #28
@@ -1,6 +1,5 @@
|
|||||||
package fr.postgresjson.definition
|
package fr.postgresjson.definition
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
class Function(
|
class Function(
|
||||||
@@ -70,21 +69,4 @@ class Function(
|
|||||||
infix fun `is different from`(other: Function): Boolean {
|
infix fun `is different from`(other: Function): Boolean {
|
||||||
return other.script != this.script
|
return other.script != this.script
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun build(source: File): List<Function> {
|
|
||||||
return source.readText()
|
|
||||||
.split(
|
|
||||||
"CREATE +(OR REPLACE +)?(PROCEDURE|FUNCTION)".toRegex(
|
|
||||||
setOf(
|
|
||||||
RegexOption.IGNORE_CASE,
|
|
||||||
RegexOption.MULTILINE
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.map {
|
|
||||||
Function("CREATE OR REPLACE FUNCTION $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ import kotlin.test.assertNull
|
|||||||
class ConnectionTest : TestAbstract() {
|
class ConnectionTest : TestAbstract() {
|
||||||
private class ObjTest(val name: String, id: UUID = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00")) : UuidEntity(id)
|
private class ObjTest(val name: String, id: UUID = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00")) : UuidEntity(id)
|
||||||
private class ObjTest2(val title: String, var test: ObjTest?) : UuidEntity()
|
private class ObjTest2(val title: String, var test: ObjTest?) : UuidEntity()
|
||||||
private class ObjTest3(val first: String, var seconde: String, var third: Int) : UuidEntity()
|
private class ObjTest3(val first: String, var second: String, var third: Int) : UuidEntity()
|
||||||
private class ObjTestWithParameterObject(var first: ParameterObject, var seconde: ParameterObject) : UuidEntity()
|
private class ObjTestWithParameterObject(var first: ParameterObject, var second: ParameterObject) : UuidEntity()
|
||||||
private class ParameterObject(var third: String) : Parameter
|
private class ParameterObject(var third: String) : Parameter
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -112,29 +112,29 @@ class ConnectionTest : TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `select one with named parameters`() {
|
fun `select one with named parameters`() {
|
||||||
val result: ObjTest3? = connection.selectOne(
|
val result: ObjTest3? = connection.selectOne(
|
||||||
"SELECT json_build_object('first', :first::text, 'seconde', :seconde::text, 'third', :third::int)",
|
"SELECT json_build_object('first', :first::text, 'second', :second::text, 'third', :third::int)",
|
||||||
mapOf(
|
mapOf(
|
||||||
"first" to "ff",
|
"first" to "ff",
|
||||||
"seconde" to "sec",
|
"second" to "sec",
|
||||||
"third" to 123
|
"third" to 123
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assertEquals(result!!.first, "ff")
|
assertEquals(result!!.first, "ff")
|
||||||
assertEquals(result.seconde, "sec")
|
assertEquals(result.second, "sec")
|
||||||
assertEquals(result.third, 123)
|
assertEquals(result.third, 123)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `select one with named parameters object`() {
|
fun `select one with named parameters object`() {
|
||||||
val result: ObjTestWithParameterObject? = connection.selectOne(
|
val result: ObjTestWithParameterObject? = connection.selectOne(
|
||||||
"SELECT json_build_object('first', :first::json, 'seconde', :seconde::json)",
|
"SELECT json_build_object('first', :first::json, 'second', :second::json)",
|
||||||
mapOf(
|
mapOf(
|
||||||
"first" to ParameterObject("one"),
|
"first" to ParameterObject("one"),
|
||||||
"seconde" to ParameterObject("two")
|
"second" to ParameterObject("two")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assertEquals("one", result!!.first.third)
|
assertEquals("one", result!!.first.third)
|
||||||
assertEquals("two", result.seconde.third)
|
assertEquals("two", result.second.third)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -142,41 +142,22 @@ class ConnectionTest : TestAbstract() {
|
|||||||
val params: Map<String, Any?> = mapOf(
|
val params: Map<String, Any?> = mapOf(
|
||||||
"first" to "ff",
|
"first" to "ff",
|
||||||
"third" to 123,
|
"third" to 123,
|
||||||
"seconde" to "sec"
|
"second" to "sec"
|
||||||
)
|
)
|
||||||
val result: List<ObjTest3> = connection.select(
|
val result: List<ObjTest3> = connection.select(
|
||||||
"""
|
"""
|
||||||
SELECT json_build_array(
|
SELECT json_build_array(
|
||||||
json_build_object('first', :first::text, 'seconde', :seconde::text, 'third', :third::int),
|
json_build_object('first', :first::text, 'second', :second::text, 'third', :third::int),
|
||||||
json_build_object('first', :first::text, 'seconde', :seconde::text, 'third', :third::int)
|
json_build_object('first', :first::text, 'second', :second::text, 'third', :third::int)
|
||||||
)
|
)
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
params
|
params
|
||||||
)
|
)
|
||||||
assertEquals(result[0].first, "ff")
|
assertEquals(result[0].first, "ff")
|
||||||
assertEquals(result[0].seconde, "sec")
|
assertEquals(result[0].second, "sec")
|
||||||
assertEquals(result[0].third, 123)
|
assertEquals(result[0].third, 123)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `selectOne with named parameters`() {
|
|
||||||
val params: Map<String, Any?> = mapOf(
|
|
||||||
"first" to "ff",
|
|
||||||
"third" to 123,
|
|
||||||
"seconde" to "sec"
|
|
||||||
)
|
|
||||||
val result: ObjTest3? = connection.selectOne(
|
|
||||||
"""
|
|
||||||
SELECT json_build_object('first', :first::text, 'seconde', :seconde::text, 'third', :third::int)
|
|
||||||
""".trimIndent(),
|
|
||||||
params
|
|
||||||
)
|
|
||||||
assertNotNull(result)
|
|
||||||
assertEquals(result!!.first, "ff")
|
|
||||||
assertEquals(result.seconde, "sec")
|
|
||||||
assertEquals(result.third, 123)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `select paginated`() {
|
fun `select paginated`() {
|
||||||
val result: Paginated<ObjTest> = connection.select(
|
val result: Paginated<ObjTest> = connection.select(
|
||||||
@@ -255,11 +236,11 @@ class ConnectionTest : TestAbstract() {
|
|||||||
val params: Map<String, Any?> = mapOf(
|
val params: Map<String, Any?> = mapOf(
|
||||||
"first" to "ff",
|
"first" to "ff",
|
||||||
"third" to 123,
|
"third" to 123,
|
||||||
"seconde" to "sec"
|
"second" to "sec"
|
||||||
)
|
)
|
||||||
val result: ObjTest3? = connection.selectOne(
|
val result: ObjTest3? = connection.selectOne(
|
||||||
"""
|
"""
|
||||||
SELECT json_build_object('first', :first::text, 'seconde', :seconde::text, 'third', :third::int), 'plop'::text as other
|
SELECT json_build_object('first', :first::text, 'second', :second::text, 'third', :third::int), 'plop'::text as other
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
params
|
params
|
||||||
) {
|
) {
|
||||||
@@ -268,7 +249,7 @@ class ConnectionTest : TestAbstract() {
|
|||||||
}
|
}
|
||||||
assertNotNull(result)
|
assertNotNull(result)
|
||||||
assertEquals("ff", result!!.first)
|
assertEquals("ff", result!!.first)
|
||||||
assertEquals("sec", result.seconde)
|
assertEquals("sec", result.second)
|
||||||
assertEquals(123, result.third)
|
assertEquals(123, result.third)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user