Move tests and create a command to run all tests
This commit is contained in:
41
src/test/kotlin/functional/MailerTest.kt
Normal file
41
src/test/kotlin/functional/MailerTest.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package functional
|
||||
|
||||
import com.sendgrid.helpers.mail.Mail
|
||||
import com.sendgrid.helpers.mail.objects.Content
|
||||
import com.sendgrid.helpers.mail.objects.Email
|
||||
import fr.dcproject.Env
|
||||
import fr.dcproject.messages.Mailer
|
||||
import fr.dcproject.module
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.server.testing.*
|
||||
import io.ktor.util.*
|
||||
import kotlinx.coroutines.InternalCoroutinesApi
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.koin.test.AutoCloseKoinTest
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@KtorExperimentalAPI
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class MailerTest : KoinTest, AutoCloseKoinTest() {
|
||||
@InternalCoroutinesApi
|
||||
@Test
|
||||
@Tag("online, functional")
|
||||
fun `can be send an email`() {
|
||||
withTestApplication({ module(Env.TEST) }) {
|
||||
get<Mailer>().sendEmail {
|
||||
Mail(
|
||||
Email("sso@dc-project.fr"),
|
||||
"Test",
|
||||
Email("fabrice.lecomte.be@gmail.com"),
|
||||
Content("text/plain", "Email Work !")
|
||||
).apply {
|
||||
addContent(Content("text/html", "Email <b>Work</b> !"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/test/kotlin/functional/ResourcesKtTest.kt
Normal file
22
src/test/kotlin/functional/ResourcesKtTest.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package functional
|
||||
|
||||
import fr.dcproject.utils.readResource
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ResourcesKtTest {
|
||||
@Test
|
||||
fun readResource() {
|
||||
"/simpleTextFile.txt".readResource {
|
||||
assertEquals("Hello", it)
|
||||
}.let {
|
||||
assertEquals("Hello", it)
|
||||
}
|
||||
|
||||
"/simpleTextFile.txt".readResource().let {
|
||||
assertEquals("Hello", it)
|
||||
}
|
||||
}
|
||||
}
|
||||
72
src/test/kotlin/functional/ViewTest.kt
Normal file
72
src/test/kotlin/functional/ViewTest.kt
Normal file
@@ -0,0 +1,72 @@
|
||||
package functional
|
||||
|
||||
import fr.dcproject.Env
|
||||
import fr.dcproject.component.article.ArticleRefVersioning
|
||||
import fr.dcproject.component.article.ArticleViewManager
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.module
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.server.testing.*
|
||||
import io.ktor.util.*
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
|
||||
import org.koin.ktor.ext.get
|
||||
import java.util.*
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@KtorExperimentalAPI
|
||||
@TestInstance(PER_CLASS)
|
||||
@Tag("functional")
|
||||
class ViewTest {
|
||||
@Test
|
||||
fun `test View Article`() {
|
||||
val article = ArticleRefVersioning(id = UUID.randomUUID(), versionId = UUID.randomUUID())
|
||||
val citizenRef = CitizenRef()
|
||||
|
||||
withTestApplication({ module(Env.TEST) }) {
|
||||
val viewManager: ArticleViewManager = application.get()
|
||||
|
||||
/* Get view before */
|
||||
val startView = viewManager.getViewsCount(article)
|
||||
|
||||
/* Add View */
|
||||
viewManager.addView(
|
||||
"1.2.3.4",
|
||||
article,
|
||||
citizenRef
|
||||
)
|
||||
|
||||
/* Add View */
|
||||
viewManager.addView(
|
||||
"10.10.10.10",
|
||||
article,
|
||||
citizenRef
|
||||
)
|
||||
|
||||
/* Add View */
|
||||
viewManager.addView(
|
||||
"8.8.8.8",
|
||||
article
|
||||
)
|
||||
|
||||
/* Add View */
|
||||
viewManager.addView(
|
||||
"1.1.1.1",
|
||||
article
|
||||
)
|
||||
|
||||
/* Sleep because ES is not sync ! */
|
||||
Thread.sleep(1000)
|
||||
|
||||
/* Get view */
|
||||
val afterView = viewManager.getViewsCount(article)
|
||||
|
||||
/* Check if view has increment */
|
||||
afterView.total `should be equal to` startView.total + 4
|
||||
afterView.unique `should be equal to` startView.unique + 3
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user