Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change test build system to suites #373

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 88 additions & 95 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ plugins {
val prevVersion = "4.22.0"
version = "4.23.0"
group = "com.hivemq"
description = "MQTT CLI is a tool that provides a feature rich command line interface for connecting, " +
"publishing, subscribing, unsubscribing and disconnecting " +
description = "MQTT CLI is a tool that provides a feature rich command line interface for connecting, " + //
"publishing, subscribing, unsubscribing and disconnecting " + //
"various MQTT clients simultaneously and supports MQTT 5.0 and MQTT 3.1.1 "

application {
Expand Down Expand Up @@ -123,7 +123,7 @@ dependencies {
constraints {
implementation(libs.apache.commonsText) {
because(
"Force a commons-text version that does not contain CVE-2022-42889, " +
"Force a commons-text version that does not contain CVE-2022-42889, " + //
"because opencsv brings the vulnerable version 1.9 as transitive dependency"
)
}
Expand Down Expand Up @@ -231,107 +231,98 @@ tasks.register<Sync>("updateOpenApiSpecs") {

/* ******************** test ******************** */

tasks.test {
useJUnitPlatform()
}

dependencies {
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platformLauncher)
testImplementation(libs.mockito)
testImplementation(libs.okhttp.mockWebserver)
testImplementation(libs.junit.systemExit)

modules {
module("org.bouncycastle:bcpkix-jdk15on") { replacedBy("org.bouncycastle:bcpkix-jdk18on") }
module("org.bouncycastle:bcprov-jdk15on") { replacedBy("org.bouncycastle:bcprov-jdk18on") }
module("org.bouncycastle:bcutil-jdk15on") { replacedBy("org.bouncycastle:bcutil-jdk18on") }
}
}

/* ******************** integration Tests ******************** */

sourceSets.create("integrationTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}

val integrationTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val integrationTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}

dependencies {
integrationTestImplementation(libs.hivemq.testcontainer.junit5)
integrationTestImplementation(libs.testcontainers)
integrationTestImplementation(libs.awaitility)
}

val integrationTest by tasks.registering(Test::class) {
group = "verification"
description = "Runs integration tests."
testClassesDirs = sourceSets[name].output.classesDirs
classpath = sourceSets[name].runtimeClasspath
useJUnitPlatform()
shouldRunAfter(tasks.test)
}
@Suppress("UnstableApiUsage") //
testing {
suites {
withType<JvmTestSuite> {
useJUnitJupiter(libs.versions.junit.jupiter)
}

tasks.check { dependsOn(integrationTest) }
val test by getting(JvmTestSuite::class) {
dependencies {
implementation(libs.junit.systemExit)
implementation(libs.mockito)
implementation(libs.okhttp.mockWebserver)
}
}

/* ******************** system Tests ******************** */
val integrationTest by registering(JvmTestSuite::class) {
testType = TestSuiteType.INTEGRATION_TEST

dependencies {
implementation(libs.awaitility)
implementation(libs.hivemq.testcontainer.junit5)
implementation(libs.junit.systemExit)
implementation(libs.mockito)
implementation(libs.testcontainers)

implementation(libs.dagger)
implementation(libs.gson)
implementation(libs.hivemq.mqttClient)
implementation(libs.okhttp)
implementation(libs.openCsv)
implementation(libs.picocli)
implementation(libs.tinylog.api)
implementation(project())
}
}

sourceSets.create("systemTest")
val systemTest by registering(JvmTestSuite::class) {
testType = TestSuiteType.FUNCTIONAL_TEST
targets {
all {
testTask.configure {
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
}
}
named("systemTest") {
testTask.configure {
dependsOn(tasks.shadowJar)
systemProperties["cliExec"] = listOf(
javaLauncher.get().executablePath.asFile.absolutePath,
"-jar",
tasks.shadowJar.map { it.outputs.files.singleFile }.get()
).joinToString(" ")
}
}
register("systemTestNative") {
testTask.configure {
dependsOn(tasks.nativeCompile)
systemProperties["cliExec"] = tasks.nativeCompile.map { it.outputs.files.singleFile }.get()
.resolve(project.name).absolutePath
}
}
}

dependencies {
implementation(libs.awaitility)
implementation(libs.hivemq.communityEditionEmbedded)
implementation(libs.hivemq.testcontainer.junit5)
implementation(libs.junit.pioneer)
implementation(libs.junit.platformLauncher)
implementation(libs.testcontainers)

implementation(libs.apache.commonsIO)
implementation(libs.gson)
implementation(libs.guava)
implementation(libs.hivemq.mqttClient)
}
}

val systemTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val systemTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
tasks.named("check") {
dependsOn(integrationTest, systemTest)
}
}
}

dependencies {
systemTestImplementation(libs.hivemq.testcontainer.junit5)
systemTestImplementation(libs.testcontainers)
systemTestImplementation(libs.awaitility)
systemTestImplementation(libs.hivemq.communityEditionEmbedded)
systemTestImplementation(libs.junit.pioneer)
}

val systemTest by tasks.registering(Test::class) {
group = "verification"
description = "Runs system tests."
testClassesDirs = sourceSets["systemTest"].output.classesDirs
classpath = sourceSets["systemTest"].runtimeClasspath
useJUnitPlatform()
shouldRunAfter(tasks.test)
dependsOn(tasks.shadowJar)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] = javaLauncher.get().executablePath.asFile.absolutePath + " -jar " +
tasks.shadowJar.map { it.outputs.files.singleFile }.get()
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
}

val systemTestNative by tasks.registering(Test::class) {
group = "verification"
description = "Runs native system tests."
testClassesDirs = sourceSets["systemTest"].output.classesDirs
classpath = sourceSets["systemTest"].runtimeClasspath
useJUnitPlatform()
shouldRunAfter(tasks.test)
dependsOn(tasks.nativeCompile)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] =
tasks.nativeCompile.map { it.outputs.files.singleFile }.get().resolve(project.name).absolutePath
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
testLogging {
showStandardStreams = true
modules {
module("org.bouncycastle:bcpkix-jdk15on") { replacedBy("org.bouncycastle:bcpkix-jdk18on") }
module("org.bouncycastle:bcprov-jdk15on") { replacedBy("org.bouncycastle:bcprov-jdk18on") }
module("org.bouncycastle:bcutil-jdk15on") { replacedBy("org.bouncycastle:bcutil-jdk18on") }
}
}

tasks.check { dependsOn(systemTest, systemTestNative) }

/* ******************** compliance ******************** */

license {
Expand Down Expand Up @@ -409,6 +400,7 @@ val nativeImageOptions by graalvmNative.binaries.named("main") {
buildArgs.add("--no-fallback")
buildArgs.add("--enable-https")
buildArgs.add("--features=com.hivemq.cli.graal.BouncyCastleFeature")
//@formatter:off
buildArgs.add(
"--initialize-at-build-time=" +
"org.bouncycastle," +
Expand Down Expand Up @@ -456,6 +448,7 @@ val nativeImageOptions by graalvmNative.binaries.named("main") {
"org.tinylog.writers," +
"org.tinylog.writers.raw"
)
//@formatter:on
}

graalvmNative {
Expand Down Expand Up @@ -491,7 +484,7 @@ val buildBrewFormula by tasks.registering(Sync::class) {
from("packages/homebrew/mqtt-cli.rb")
into(layout.buildDirectory.dir("packages/homebrew/formula"))
filter {
it.replace("@@description@@", project.description!!)
it.replace("@@description@@", project.description!!) //
.replace("@@version@@", project.version.toString())
.replace("@@filename@@", buildBrewZip.get().archiveFileName.get())
.replace("@@shasum@@", sha256Hash(buildBrewZip.get().archiveFile.get().asFile))
Expand Down
Loading