implement SelectOne and multiple
add Fixtures
This commit is contained in:
@@ -16,15 +16,32 @@ class ConnectionTest() {
|
||||
|
||||
@Test
|
||||
fun getObject() {
|
||||
val obj: ObjTest? = connection.execute<Int?, ObjTest>("select to_json(a) from test a limit 1")
|
||||
val obj: ObjTest? = connection.selectOne<Int?, ObjTest>("select to_json(a) from test a limit 1")
|
||||
assertTrue(obj is ObjTest)
|
||||
assertTrue(obj!!.id == 1)
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun getExistingObject() {
|
||||
// val obj: ObjTest? = connection.execute<Int?, ObjTest>("select to_json(a) from test a limit 1")
|
||||
// assertTrue(obj is ObjTest)
|
||||
// }
|
||||
@Test
|
||||
fun getExistingObject() {
|
||||
val objs: List<ObjTest2> = connection.select("""
|
||||
select
|
||||
json_agg(j)
|
||||
FROM (
|
||||
SELECT
|
||||
t.id, t.title,
|
||||
t2 as test
|
||||
from test2 t
|
||||
JOIN test t2 ON t.test_id = t2.id
|
||||
) j;
|
||||
"""
|
||||
)
|
||||
assertTrue(objs !== null)
|
||||
assertTrue(objs is List<ObjTest2>)
|
||||
assertTrue(objs!!.size == 2)
|
||||
assertTrue(objs[0].id == 1)
|
||||
assertTrue(objs[0].test!!.id == 1)
|
||||
}
|
||||
}
|
||||
|
||||
class ObjTest(var name: String): IdEntity()
|
||||
class ObjTest(var name: String): IdEntity()
|
||||
class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.postgresjson.serializer
|
||||
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.IdEntity
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
@@ -9,17 +9,18 @@ import org.junit.jupiter.api.TestInstance
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
internal class SerializerTest {
|
||||
class ObjTest(var val1: String, var val2: Int) : UuidEntity()
|
||||
class ObjTest(var val1: String, var val2: Int) : IdEntity(1)
|
||||
|
||||
private val serializer = Serializer()
|
||||
|
||||
private val objSerialized: String = """{"val1":"plop","val2":123,"id":"1362a162-df75-4995-ab46-4ad55fa07de2"}"""
|
||||
private val objSerialized: String = """{"val1":"plop","val2":123,"id":2}"""
|
||||
private val objSerializedUpdate = """{"val1":"update","val2":123}"""
|
||||
private lateinit var obj: ObjTest
|
||||
|
||||
@BeforeEach
|
||||
fun before() {
|
||||
obj = ObjTest("plop", 123)
|
||||
obj.id = 2
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -36,7 +37,7 @@ internal class SerializerTest {
|
||||
|
||||
@Test
|
||||
fun deserialize() {
|
||||
val objDeserialized: ObjTest = serializer.deserialize(objSerialized)
|
||||
val objDeserialized = serializer.deserialize<Int?, ObjTest>(objSerialized)
|
||||
assertEquals(obj.val1, objDeserialized.val1)
|
||||
assertEquals(obj.val2, objDeserialized.val2)
|
||||
}
|
||||
|
||||
20
src/test/resources/fixtures/init.sql
Normal file
20
src/test/resources/fixtures/init.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
create table if not exists test
|
||||
(
|
||||
id serial not null
|
||||
constraint test_pk
|
||||
primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table if not exists test2
|
||||
(
|
||||
id serial not null,
|
||||
title text,
|
||||
test_id integer
|
||||
constraint test2_test_id_fk
|
||||
references test
|
||||
);
|
||||
INSERT INTO public.test (id, name) VALUES (1, 'plop');
|
||||
INSERT INTO public.test2 (id, title, test_id) VALUES (1, 'plop', 1);
|
||||
INSERT INTO public.test2 (id, title, test_id) VALUES (2, 'plip', 1);
|
||||
INSERT INTO public.test2 (id, title, test_id) VALUES (3, 'ttt', null);
|
||||
Reference in New Issue
Block a user