From fa66114d0124dc27ecd416c530550beaa21116eb Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sat, 17 Jul 2021 15:39:08 +0200 Subject: [PATCH] test call request without args --- .../fr/postgresjson/connexion/Executable.kt | 2 +- .../fr/postgresjson/serializer/Serializer.kt | 4 ++-- .../kotlin/fr/postgresjson/ConnectionTest.kt | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/fr/postgresjson/connexion/Executable.kt b/src/main/kotlin/fr/postgresjson/connexion/Executable.kt index ba4bf69..b7488db 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Executable.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Executable.kt @@ -27,7 +27,7 @@ interface Executable { fun selectOne( sql: String, typeReference: TypeReference, - values: List = emptyList(), + values: List, block: SelectOneCallback = {} ): R? diff --git a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt index ec19f69..df8e250 100644 --- a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt +++ b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt @@ -3,7 +3,7 @@ package fr.postgresjson.serializer import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.PropertyNamingStrategy +import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.datatype.joda.JodaModule @@ -15,7 +15,7 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) { init { val module = SimpleModule() mapper.registerModule(module) - mapper.propertyNamingStrategy = PropertyNamingStrategy.SNAKE_CASE + mapper.propertyNamingStrategy = PropertyNamingStrategies.SNAKE_CASE mapper.registerModule(JodaModule()) mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index 6c1b698..4dd9a5d 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -1,10 +1,12 @@ package fr.postgresjson +import com.fasterxml.jackson.core.type.TypeReference import fr.postgresjson.connexion.Paginated import fr.postgresjson.connexion.select import fr.postgresjson.connexion.selectOne 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 @@ -13,6 +15,7 @@ import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import java.util.UUID +import kotlin.test.assertNull @TestInstance(TestInstance.Lifecycle.PER_CLASS) class ConnectionTest : TestAbstract() { @@ -51,12 +54,27 @@ class ConnectionTest : TestAbstract() { } @Test - fun callRequestWithArgs() { + 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) } + @Test + fun `test call request without args`() { + val result: ObjTest? = connection.selectOne("select json_build_object('id', '2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00', 'name', 'myName')", object : TypeReference() {}) { + assertEquals("myName", this.rows[0].getString(0)?.deserialize()?.name) + } + assertNotNull(result) + assertEquals("myName", result!!.name) + } + + @Test + fun `test call request return null`() { + val result: ObjTest? = connection.selectOne("select null;", object : TypeReference() {}) + assertNull(result) + } + @Test fun callRequestWithArgsEntity() { val o = ObjTest("myName", id = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00"))