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