test call request without args
This commit is contained in:
@@ -27,7 +27,7 @@ interface Executable {
|
||||
fun <R : EntityI> selectOne(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?> = emptyList(),
|
||||
values: List<Any?>,
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<ObjTest>() {}) {
|
||||
assertEquals("myName", this.rows[0].getString(0)?.deserialize<ObjTest>()?.name)
|
||||
}
|
||||
assertNotNull(result)
|
||||
assertEquals("myName", result!!.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test call request return null`() {
|
||||
val result: ObjTest? = connection.selectOne("select null;", object : TypeReference<ObjTest>() {})
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun callRequestWithArgsEntity() {
|
||||
val o = ObjTest("myName", id = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00"))
|
||||
|
||||
Reference in New Issue
Block a user