Fix tests
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import io.gitlab.arturbosch.detekt.Detekt
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.owasp.dependencycheck.reporting.ReportGenerator
|
||||
import org.slf4j.LoggerFactory
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import fr.postgresjson.connexion.Requester
|
||||
|
||||
val ktorVersion = "1.5.0"
|
||||
val kotlinVersion = "1.4.30"
|
||||
@@ -71,7 +71,7 @@ val migration by tasks.registering {
|
||||
dependsOn(tasks.named("composeUp"))
|
||||
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/main/resources/application.conf")).resolve()
|
||||
val config = ConfigFactory.parseFile(file("$buildDir/../src/main/resources/application.conf")).resolve()
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
port = config.getInt("db.port"),
|
||||
@@ -94,7 +94,7 @@ val migrationTest by tasks.registering {
|
||||
dependsOn(tasks.named("testComposeUp"))
|
||||
finalizedBy(tasks.named("testComposeDown"))
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/test/resources/application-test.conf")).resolve()
|
||||
val config = ConfigFactory.parseFile(file("$buildDir/../src/test/resources/application-test.conf")).resolve()
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
port = config.getInt("db.port"),
|
||||
@@ -119,7 +119,7 @@ val testSql by tasks.registering {
|
||||
finalizedBy(tasks.named("testComposeDown"))
|
||||
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/test/resources/application-test.conf")).resolve()
|
||||
val config = ConfigFactory.parseFile(file("$buildDir/../src/test/resources/application-test.conf")).resolve()
|
||||
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
@@ -140,7 +140,7 @@ val testSql by tasks.registering {
|
||||
|
||||
Requester.RequesterFactory(
|
||||
connection = connection,
|
||||
queriesDirectory = file("${buildDir}/../src/test/sql").toURI()
|
||||
queriesDirectory = file("$buildDir/../src/test/sql").toURI()
|
||||
).createRequester().run {
|
||||
getQueries().map {
|
||||
try {
|
||||
@@ -183,8 +183,8 @@ tasks.test {
|
||||
useJUnitPlatform()
|
||||
systemProperty("junit.jupiter.execution.parallel.enabled", true)
|
||||
dependsOn(testSql)
|
||||
dependsOn(tasks.pitest)
|
||||
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
|
||||
finalizedBy(tasks.pitest)
|
||||
}
|
||||
|
||||
apply(plugin = "docker-compose")
|
||||
|
||||
@@ -4,8 +4,8 @@ services:
|
||||
container_name: ${APP_NAME}_rabbitmq_test
|
||||
image: rabbitmq:management-alpine
|
||||
ports:
|
||||
- 5672:5672
|
||||
- 15672:15672
|
||||
- 5673:5672
|
||||
- 15673:15672
|
||||
|
||||
redis:
|
||||
container_name: ${APP_NAME}_redis_test
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package functional
|
||||
|
||||
import com.rabbitmq.client.ConnectionFactory
|
||||
import com.rabbitmq.client.ShutdownSignalException
|
||||
import fr.dcproject.application.Configuration
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
@@ -27,6 +28,7 @@ import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Tags
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
|
||||
@Tags(Tag("functional"))
|
||||
@@ -43,8 +45,14 @@ class NotificationConsumerTest {
|
||||
.apply { setUri(config.rabbitmq) }
|
||||
.run {
|
||||
newConnection().createChannel().apply {
|
||||
queuePurge("push")
|
||||
queuePurge("email")
|
||||
try {
|
||||
queuePurge("push")
|
||||
queuePurge("email")
|
||||
} catch (e: ShutdownSignalException) {
|
||||
LoggerFactory.getLogger(NotificationConsumerTest::class.qualifiedName).run {
|
||||
info("queue not exist")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,9 +75,7 @@ class NotificationConsumerTest {
|
||||
val asyncCommand = spyk(redisClient.connect().async())
|
||||
every { redisClient.connect().async() } returns asyncCommand
|
||||
|
||||
val rabbitFactory: ConnectionFactory = spyk {
|
||||
ConnectionFactory().apply { setUri(config.rabbitmq) }
|
||||
}
|
||||
val rabbitFactory: ConnectionFactory = ConnectionFactory().apply { setUri(config.rabbitmq) }
|
||||
val followArticleRepo = mockk<FollowArticleRepository> {
|
||||
every { findFollowsByTarget(any()) } returns flow {
|
||||
FollowSimple(
|
||||
@@ -88,7 +94,6 @@ class NotificationConsumerTest {
|
||||
notificationEmailSender = emailSender,
|
||||
exchangeName = "notification",
|
||||
).apply { start() }
|
||||
verify { rabbitFactory.newConnection() }
|
||||
|
||||
/* Push message */
|
||||
Publisher(
|
||||
@@ -110,6 +115,6 @@ class NotificationConsumerTest {
|
||||
verify(timeout = 1000) { emailSender.sendEmail(any()) }
|
||||
verify(timeout = 1000) { asyncCommand.zadd(any<String>(), any<Double>(), any<String>()) }
|
||||
|
||||
// consumer.close()
|
||||
consumer.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ redis {
|
||||
}
|
||||
|
||||
rabbitmq {
|
||||
connection = "amqp://localhost:5672"
|
||||
connection = "amqp://localhost:5673"
|
||||
}
|
||||
|
||||
elasticsearch {
|
||||
|
||||
Reference in New Issue
Block a user