diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index da72767..9e50a98 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -11,6 +11,7 @@
+
diff --git a/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt
index 519da48..d4f45a2 100644
--- a/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt
+++ b/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt
@@ -2,19 +2,37 @@ package fr.postgresjson.serializer
import fr.postgresjson.connexion.Connection
import fr.postgresjson.entity.IdEntity
+import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.BeforeEach
-import org.junit.jupiter.api.Test
+import java.io.File
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class ConnectionTest() {
private class ObjTest(var name: String): IdEntity()
private class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
private lateinit var connection: Connection
+ fun getConnextion(): Connection {
+ return Connection(database = "test", username = "test", password = "test")
+ }
+
+ @BeforeAll
+ fun beforeAll() {
+ val initSQL = File(this::class.java.getResource("/fixtures/init.sql").toURI())
+ val promise = getConnextion().connect().sendQuery(initSQL.readText())
+ promise.join()
+ }
+
@BeforeEach
fun before() {
- connection = Connection()
+ connection = getConnextion()
+ }
+
+ @AfterAll
+ fun afterAll() {
+ val downSQL = File(this::class.java.getResource("/fixtures/down.sql").toURI())
+ getConnextion().connect().sendQuery(downSQL.readText()).join()
}
@Test
diff --git a/src/test/resources/fixtures/down.sql b/src/test/resources/fixtures/down.sql
new file mode 100644
index 0000000..2a58ceb
--- /dev/null
+++ b/src/test/resources/fixtures/down.sql
@@ -0,0 +1,2 @@
+drop schema public cascade;
+create schema if not exists public;
\ No newline at end of file
diff --git a/src/test/resources/fixtures/init.sql b/src/test/resources/fixtures/init.sql
index 8a0da48..4b226a3 100644
--- a/src/test/resources/fixtures/init.sql
+++ b/src/test/resources/fixtures/init.sql
@@ -1,3 +1,8 @@
+-- create database test;
+-- create user test with encrypted password 'test';
+-- grant all privileges on database test to test;
+-- ALTER SCHEMA public owner to test;
+
create table if not exists test
(
id serial not null
@@ -14,7 +19,8 @@ create table if not exists test2
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);
\ No newline at end of file
+
+INSERT INTO test (id, name) VALUES (1, 'plop') ON CONFLICT DO NOTHING;
+INSERT INTO test2 (id, title, test_id) VALUES (1, 'plop', 1) ON CONFLICT DO NOTHING;
+INSERT INTO test2 (id, title, test_id) VALUES (2, 'plip', 1) ON CONFLICT DO NOTHING;
+INSERT INTO test2 (id, title, test_id) VALUES (3, 'ttt', null) ON CONFLICT DO NOTHING;