clean code
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
package fr.postgresjson
|
package fr.postgresjson
|
||||||
|
|
||||||
import fr.postgresjson.connexion.Connection
|
|
||||||
import fr.postgresjson.connexion.Paginated
|
import fr.postgresjson.connexion.Paginated
|
||||||
import fr.postgresjson.entity.IdEntity
|
import fr.postgresjson.entity.IdEntity
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
|
||||||
@@ -15,13 +13,6 @@ class ConnectionTest(): TestAbstract() {
|
|||||||
private class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
|
private class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
|
||||||
private class ObjTest3(var first: String, var seconde: String, var third: Int): IdEntity()
|
private class ObjTest3(var first: String, var seconde: String, var third: Int): IdEntity()
|
||||||
|
|
||||||
private lateinit var connection: Connection
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
fun before() {
|
|
||||||
connection = getConnextion()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getObject() {
|
fun getObject() {
|
||||||
val obj: ObjTest? = connection.selectOne("select to_json(a) from test a limit 1")
|
val obj: ObjTest? = connection.selectOne("select to_json(a) from test a limit 1")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class MigrationTest(): TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `run up query`() {
|
fun `run up query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
|
||||||
val m = Migrations(resources, getConnextion())
|
val m = Migrations(resources, connection)
|
||||||
m.up().apply {
|
m.up().apply {
|
||||||
this `should contain` Pair("1", Migration.Status.OK)
|
this `should contain` Pair("1", Migration.Status.OK)
|
||||||
size `should be equal to` 1
|
size `should be equal to` 1
|
||||||
@@ -30,14 +30,14 @@ class MigrationTest(): TestAbstract() {
|
|||||||
fun `migration up Query should throw error if no down`() {
|
fun `migration up Query should throw error if no down`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/migration_without_down").toURI())
|
val resources = File(this::class.java.getResource("/sql/migration_without_down").toURI())
|
||||||
invoking {
|
invoking {
|
||||||
Migrations(resources, getConnextion())
|
Migrations(resources, connection)
|
||||||
} shouldThrow Migrations.DownMigrationNotDefined::class
|
} shouldThrow Migrations.DownMigrationNotDefined::class
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `run forced down query`() {
|
fun `run forced down query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
|
||||||
val m = Migrations(resources, getConnextion())
|
val m = Migrations(resources, connection)
|
||||||
repeat(3) {
|
repeat(3) {
|
||||||
m.down(true).apply {
|
m.down(true).apply {
|
||||||
this `should contain` Pair("1", Migration.Status.OK)
|
this `should contain` Pair("1", Migration.Status.OK)
|
||||||
@@ -49,10 +49,10 @@ class MigrationTest(): TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `run dry migrations`() {
|
fun `run dry migrations`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
||||||
Migrations(resources, getConnextion()).apply {
|
Migrations(resources, connection).apply {
|
||||||
runDry().size `should be equal to` 2
|
runDry().size `should be equal to` 2
|
||||||
}
|
}
|
||||||
Migrations(resources, getConnextion()).apply {
|
Migrations(resources, connection).apply {
|
||||||
runDry().size `should be equal to` 2
|
runDry().size `should be equal to` 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ class MigrationTest(): TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `run dry migrations launch twice`() {
|
fun `run dry migrations launch twice`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
||||||
Migrations(resources, getConnextion()).apply {
|
Migrations(resources, connection).apply {
|
||||||
runDry().size `should be equal to` 2
|
runDry().size `should be equal to` 2
|
||||||
runDry().size `should be equal to` 2
|
runDry().size `should be equal to` 2
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class MigrationTest(): TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `run migrations`() {
|
fun `run migrations`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
||||||
Migrations(resources, getConnextion()).apply {
|
Migrations(resources, connection).apply {
|
||||||
run().apply {
|
run().apply {
|
||||||
size `should be equal to` 1
|
size `should be equal to` 1
|
||||||
}
|
}
|
||||||
@@ -80,12 +80,12 @@ class MigrationTest(): TestAbstract() {
|
|||||||
fun `run migrations force down`() {
|
fun `run migrations force down`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
|
||||||
val resourcesFunctions = File(this::class.java.getResource("/sql/function").toURI())
|
val resourcesFunctions = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
Migrations(listOf(resources, resourcesFunctions), getConnextion()).apply {
|
Migrations(listOf(resources, resourcesFunctions), connection).apply {
|
||||||
up().apply {
|
up().apply {
|
||||||
size `should be equal to` 6
|
size `should be equal to` 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Migrations(listOf(resources, resourcesFunctions), getConnextion()).apply {
|
Migrations(listOf(resources, resourcesFunctions), connection).apply {
|
||||||
forceAllDown().apply {
|
forceAllDown().apply {
|
||||||
size `should be equal to` 6
|
size `should be equal to` 6
|
||||||
}
|
}
|
||||||
@@ -95,11 +95,11 @@ class MigrationTest(): TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `run functions migrations`() {
|
fun `run functions migrations`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
Migrations(resources, getConnextion()).apply {
|
Migrations(resources, connection).apply {
|
||||||
run().size `should be equal to` 5
|
run().size `should be equal to` 5
|
||||||
}
|
}
|
||||||
|
|
||||||
val objTest: RequesterTest.ObjTest? = Requester(getConnextion())
|
val objTest: RequesterTest.ObjTest? = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function")
|
.getFunction("test_function")
|
||||||
.selectOne(listOf("test", "plip"))
|
.selectOne(listOf("test", "plip"))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `get query from file`() {
|
fun `get query from file`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val objTest: ObjTest? = Requester(getConnextion())
|
val objTest: ObjTest? = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/selectOne")
|
.getQuery("Test/selectOne")
|
||||||
.selectOne()
|
.selectOne()
|
||||||
@@ -27,7 +27,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `get function from file`() {
|
fun `get function from file`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val objTest: ObjTest? = Requester(getConnextion())
|
val objTest: ObjTest? = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function")
|
.getFunction("test_function")
|
||||||
.selectOne(listOf("test", "plip"))
|
.selectOne(listOf("test", "plip"))
|
||||||
@@ -39,7 +39,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call exec on query`() {
|
fun `call exec on query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val result = Requester(getConnextion())
|
val result = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/selectOne")
|
.getQuery("Test/selectOne")
|
||||||
.exec()
|
.exec()
|
||||||
@@ -50,7 +50,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call exec on function`() {
|
fun `call exec on function`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val result = Requester(getConnextion())
|
val result = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function")
|
.getFunction("test_function")
|
||||||
.exec(listOf("test", "plip"))
|
.exec(listOf("test", "plip"))
|
||||||
@@ -61,7 +61,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call sendQuery on query`() {
|
fun `call sendQuery on query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val result = Requester(getConnextion())
|
val result = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/exec")
|
.getQuery("Test/exec")
|
||||||
.sendQuery()
|
.sendQuery()
|
||||||
@@ -72,7 +72,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call sendQuery on function`() {
|
fun `call sendQuery on function`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val result = Requester(getConnextion())
|
val result = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("function_void")
|
.getFunction("function_void")
|
||||||
.sendQuery(listOf("test"))
|
.sendQuery(listOf("test"))
|
||||||
@@ -83,7 +83,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call selectOne on function`() {
|
fun `call selectOne on function`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val obj: ObjTest = Requester(getConnextion())
|
val obj: ObjTest = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function")
|
.getFunction("test_function")
|
||||||
.selectOne(mapOf("name" to "myName"))!!
|
.selectOne(mapOf("name" to "myName"))!!
|
||||||
@@ -95,7 +95,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
fun `call selectOne on function with object`() {
|
fun `call selectOne on function with object`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val obj2 = ObjTest("original")
|
val obj2 = ObjTest("original")
|
||||||
val obj: ObjTest = Requester(getConnextion())
|
val obj: ObjTest = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function_object")
|
.getFunction("test_function_object")
|
||||||
.selectOne("resource" to obj2)!!
|
.selectOne("resource" to obj2)!!
|
||||||
@@ -107,7 +107,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call selectOne on query`() {
|
fun `call selectOne on query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val obj: ObjTest = Requester(getConnextion())
|
val obj: ObjTest = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/selectOneWithParameters")
|
.getQuery("Test/selectOneWithParameters")
|
||||||
.selectOne(mapOf("name" to "myName"))!!
|
.selectOne(mapOf("name" to "myName"))!!
|
||||||
@@ -118,7 +118,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call select (multiple) on function`() {
|
fun `call select (multiple) on function`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val obj: List<ObjTest>? = Requester(getConnextion())
|
val obj: List<ObjTest>? = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function_multiple")
|
.getFunction("test_function_multiple")
|
||||||
.select(mapOf("name" to "myName"))
|
.select(mapOf("name" to "myName"))
|
||||||
@@ -129,7 +129,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call select paginated on query`() {
|
fun `call select paginated on query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val result: Paginated<ObjTest> = Requester(getConnextion())
|
val result: Paginated<ObjTest> = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/selectPaginated")
|
.getQuery("Test/selectPaginated")
|
||||||
.select(1, 2, mapOf("name" to "ff"))
|
.select(1, 2, mapOf("name" to "ff"))
|
||||||
@@ -143,7 +143,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call select paginated on function`() {
|
fun `call select paginated on function`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
val result: Paginated<ObjTest> = Requester(getConnextion())
|
val result: Paginated<ObjTest> = Requester(connection)
|
||||||
.addFunction(resources)
|
.addFunction(resources)
|
||||||
.getFunction("test_function_paginated")
|
.getFunction("test_function_paginated")
|
||||||
.select(1, 2, mapOf("name" to "ff"))
|
.select(1, 2, mapOf("name" to "ff"))
|
||||||
@@ -157,7 +157,7 @@ class RequesterTest: TestAbstract() {
|
|||||||
@Test
|
@Test
|
||||||
fun `call selectOne on query with extra parameter`() {
|
fun `call selectOne on query with extra parameter`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val obj: ObjTest = Requester(getConnextion())
|
val obj: ObjTest = Requester(connection)
|
||||||
.addQuery(resources)
|
.addQuery(resources)
|
||||||
.getQuery("Test/selectOneWithParameters")
|
.getQuery("Test/selectOneWithParameters")
|
||||||
.selectOne(mapOf("name" to "myName")) {
|
.selectOne(mapOf("name" to "myName")) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test
|
|||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
internal class SerializerTest: TestAbstract() {
|
internal class SerializerTest {
|
||||||
private class ObjTest(var val1: String, var val2: Int) : IdEntity(1)
|
private class ObjTest(var val1: String, var val2: Int) : IdEntity(1)
|
||||||
private class ObjTestDate(var val1: DateTime) : IdEntity(2)
|
private class ObjTestDate(var val1: DateTime) : IdEntity(2)
|
||||||
|
|
||||||
|
|||||||
@@ -9,22 +9,23 @@ import java.io.File
|
|||||||
|
|
||||||
@TestInstance(PER_CLASS)
|
@TestInstance(PER_CLASS)
|
||||||
abstract class TestAbstract {
|
abstract class TestAbstract {
|
||||||
private var connection = Connection(database = "test", username = "test", password = "test")
|
protected val connection = Connection(database = "test", username = "test", password = "test")
|
||||||
|
|
||||||
protected fun getConnextion(): Connection {
|
|
||||||
return connection
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun beforeAll() {
|
fun beforeAll() {
|
||||||
val initSQL = File(this::class.java.getResource("/fixtures/init.sql").toURI())
|
val initSQL = File(this::class.java.getResource("/fixtures/init.sql").toURI())
|
||||||
getConnextion().connect().createStatement().executeUpdate(initSQL.readText())
|
connection
|
||||||
|
.connect()
|
||||||
|
.createStatement()
|
||||||
|
.executeUpdate(initSQL.readText())
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
fun afterAll() {
|
fun afterAll() {
|
||||||
val downSQL = File(this::class.java.getResource("/fixtures/down.sql").toURI())
|
val downSQL = File(this::class.java.getResource("/fixtures/down.sql").toURI())
|
||||||
getConnextion().connect().createStatement().executeUpdate(downSQL.readText())
|
connection.connect().apply {
|
||||||
getConnextion().connect().close()
|
createStatement()
|
||||||
|
.executeUpdate(downSQL.readText())
|
||||||
|
}.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user