add Init and Down script for tests

This commit is contained in:
2019-06-06 14:03:34 +02:00
parent 9b7d2ffa8c
commit f20d349c3d
4 changed files with 34 additions and 7 deletions

1
.idea/gradle.xml generated
View File

@@ -11,6 +11,7 @@
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
</set> </set>
</option> </option>
<option name="testRunner" value="PLATFORM" />
<option name="useAutoImport" value="true" /> <option name="useAutoImport" value="true" />
<option name="useQualifiedModuleNames" value="true" /> <option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings> </GradleProjectSettings>

View File

@@ -2,19 +2,37 @@ package fr.postgresjson.serializer
import fr.postgresjson.connexion.Connection import fr.postgresjson.connexion.Connection
import fr.postgresjson.entity.IdEntity import fr.postgresjson.entity.IdEntity
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach import java.io.File
import org.junit.jupiter.api.Test
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class ConnectionTest() { class ConnectionTest() {
private class ObjTest(var name: String): IdEntity() private class ObjTest(var name: String): IdEntity()
private class ObjTest2(var title: String, var test: ObjTest?): IdEntity() private class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
private lateinit var connection: Connection 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 @BeforeEach
fun before() { 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 @Test

View File

@@ -0,0 +1,2 @@
drop schema public cascade;
create schema if not exists public;

View File

@@ -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 create table if not exists test
( (
id serial not null id serial not null
@@ -14,7 +19,8 @@ create table if not exists test2
constraint test2_test_id_fk constraint test2_test_id_fk
references test 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 test (id, name) VALUES (1, 'plop') ON CONFLICT DO NOTHING;
INSERT INTO public.test2 (id, title, test_id) VALUES (2, 'plip', 1); INSERT INTO test2 (id, title, test_id) VALUES (1, 'plop', 1) ON CONFLICT DO NOTHING;
INSERT INTO public.test2 (id, title, test_id) VALUES (3, 'ttt', null); 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;