From 41b1f75cfb691558010fd993d47f048600f5ea79 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Thu, 8 Aug 2019 13:40:05 +0200 Subject: [PATCH] Add RepositityTest --- build.gradle.kts | 8 ++++++ src/main/kotlin/fr/dcproject/Module.kt | 2 +- src/test/kotlin/RepositoryTest.kt | 40 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/RepositoryTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 5341ce3..8044e21 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + val ktor_version: String by project val kotlin_version: String by project val logback_version: String by project @@ -16,6 +18,12 @@ application { mainClassName = "io.ktor.server.netty.EngineMain" } +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + repositories { mavenLocal() jcenter() diff --git a/src/main/kotlin/fr/dcproject/Module.kt b/src/main/kotlin/fr/dcproject/Module.kt index bf1e31a..134f4fd 100644 --- a/src/main/kotlin/fr/dcproject/Module.kt +++ b/src/main/kotlin/fr/dcproject/Module.kt @@ -22,7 +22,7 @@ val Module = module { functionsDirectory = config.sqlFiles.resolve("functions") ).createRequester() } - // create generic declaration + // TODO: create generic declaration single { ArticleRepository(get()) } single { ConstitutionRepository(get()) } diff --git a/src/test/kotlin/RepositoryTest.kt b/src/test/kotlin/RepositoryTest.kt new file mode 100644 index 0000000..a8fe8ed --- /dev/null +++ b/src/test/kotlin/RepositoryTest.kt @@ -0,0 +1,40 @@ +import fr.dcproject.Module +import fr.dcproject.entity.Article +import fr.dcproject.entity.Constitution +import io.ktor.locations.KtorExperimentalLocationsAPI +import io.ktor.util.KtorExperimentalAPI +import org.amshove.kluent.`should equal` +import org.amshove.kluent.shouldBe +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS +import org.koin.core.context.startKoin +import org.koin.dsl.koinApplication +import org.koin.test.KoinTest +import org.koin.test.get +import fr.dcproject.repository.Article as RepositoryArticle +import fr.dcproject.repository.Constitution as RepositoryConstitution + +@KtorExperimentalLocationsAPI +@KtorExperimentalAPI +@TestInstance(PER_CLASS) +class RepositoryTest: KoinTest { + @BeforeAll + fun beforeAll() { + startKoin { modules(Module) } + } + + @Test + fun `test get repository`() { + koinApplication { + val repoArticle = get() + (repoArticle is RepositoryArticle) shouldBe true + repoArticle.entityName `should equal` Article::class + + val repoConstitution = get() + (repoConstitution is RepositoryConstitution) shouldBe true + repoConstitution.entityName `should equal` Constitution::class + } + } +}