From 11cff350eda3aed66c08003326844bf09d75cd8e Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sun, 18 Jul 2021 02:42:09 +0200 Subject: [PATCH] clean code --- .../fr/postgresjson/definition/Function.kt | 18 ------- .../kotlin/fr/postgresjson/ConnectionTest.kt | 49 ++++++------------- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/src/main/kotlin/fr/postgresjson/definition/Function.kt b/src/main/kotlin/fr/postgresjson/definition/Function.kt index dc095dc..02c6dc1 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Function.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Function.kt @@ -1,6 +1,5 @@ package fr.postgresjson.definition -import java.io.File import java.nio.file.Path class Function( @@ -70,21 +69,4 @@ class Function( infix fun `is different from`(other: Function): Boolean { return other.script != this.script } - - companion object { - fun build(source: File): List { - return source.readText() - .split( - "CREATE +(OR REPLACE +)?(PROCEDURE|FUNCTION)".toRegex( - setOf( - RegexOption.IGNORE_CASE, - RegexOption.MULTILINE - ) - ) - ) - .map { - Function("CREATE OR REPLACE FUNCTION $it") - } - } - } } diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index 7d0165f..6f5ef82 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -23,8 +23,8 @@ import kotlin.test.assertNull class ConnectionTest : TestAbstract() { 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 ObjTest3(val first: String, var seconde: String, var third: Int) : UuidEntity() - private class ObjTestWithParameterObject(var first: ParameterObject, var seconde: ParameterObject) : UuidEntity() + private class ObjTest3(val first: String, var second: String, var third: Int) : UuidEntity() + private class ObjTestWithParameterObject(var first: ParameterObject, var second: ParameterObject) : UuidEntity() private class ParameterObject(var third: String) : Parameter @Test @@ -112,29 +112,29 @@ class ConnectionTest : TestAbstract() { @Test fun `select one with named parameters`() { 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( "first" to "ff", - "seconde" to "sec", + "second" to "sec", "third" to 123 ) ) assertEquals(result!!.first, "ff") - assertEquals(result.seconde, "sec") + assertEquals(result.second, "sec") assertEquals(result.third, 123) } @Test fun `select one with named parameters object`() { 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( "first" to ParameterObject("one"), - "seconde" to ParameterObject("two") + "second" to ParameterObject("two") ) ) assertEquals("one", result!!.first.third) - assertEquals("two", result.seconde.third) + assertEquals("two", result.second.third) } @Test @@ -142,41 +142,22 @@ class ConnectionTest : TestAbstract() { val params: Map = mapOf( "first" to "ff", "third" to 123, - "seconde" to "sec" + "second" to "sec" ) val result: List = connection.select( """ SELECT json_build_array( - json_build_object('first', :first::text, 'seconde', :seconde::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), + json_build_object('first', :first::text, 'second', :second::text, 'third', :third::int) ) """.trimIndent(), params ) assertEquals(result[0].first, "ff") - assertEquals(result[0].seconde, "sec") + assertEquals(result[0].second, "sec") assertEquals(result[0].third, 123) } - @Test - fun `selectOne with named parameters`() { - val params: Map = 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 fun `select paginated`() { val result: Paginated = connection.select( @@ -255,11 +236,11 @@ class ConnectionTest : TestAbstract() { val params: Map = mapOf( "first" to "ff", "third" to 123, - "seconde" to "sec" + "second" to "sec" ) 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(), params ) { @@ -268,7 +249,7 @@ class ConnectionTest : TestAbstract() { } assertNotNull(result) assertEquals("ff", result!!.first) - assertEquals("sec", result.seconde) + assertEquals("sec", result.second) assertEquals(123, result.third) } }