From 01577e32ac2d27a36e47e32b4c84279f30d2928f Mon Sep 17 00:00:00 2001 From: Lukas Brand Date: Thu, 7 Dec 2023 10:10:42 +0100 Subject: [PATCH 1/2] Change test build system to suites --- build.gradle.kts | 171 ++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 91 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 637cc454..186cb0d0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -231,17 +231,89 @@ tasks.register("updateOpenApiSpecs") { /* ******************** test ******************** */ -tasks.test { - useJUnitPlatform() +@Suppress("UnstableApiUsage") // +testing { + suites { + val test by getting(JvmTestSuite::class) { + useJUnitJupiter(libs.versions.junit.jupiter) + + dependencies { + implementation(libs.junit.systemExit) + implementation(libs.mockito) + implementation(libs.okhttp.mockWebserver) + } + } + + 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()) + } + } + + 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"] = javaLauncher.get().executablePath.asFile.absolutePath + " -jar " + + tasks.shadowJar.map { it.outputs.files.singleFile }.get() + } + } + 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) + } + } + + tasks.named("check") { + dependsOn(integrationTest, systemTest) + } + } } 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") } @@ -249,89 +321,6 @@ dependencies { } } -/* ******************** 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) -} - -tasks.check { dependsOn(integrationTest) } - -/* ******************** system Tests ******************** */ - -sourceSets.create("systemTest") - -val systemTestImplementation: Configuration by configurations.getting { - extendsFrom(configurations.testImplementation.get()) -} -val systemTestRuntimeOnly: Configuration by configurations.getting { - extendsFrom(configurations.testRuntimeOnly.get()) -} - -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 - } -} - -tasks.check { dependsOn(systemTest, systemTestNative) } - /* ******************** compliance ******************** */ license { From 31bacaf33c12e2673220b833a4e56a5b8170a517 Mon Sep 17 00:00:00 2001 From: Lukas Brand Date: Fri, 8 Dec 2023 10:40:04 +0100 Subject: [PATCH 2/2] Fix format issues. --- build.gradle.kts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 186cb0d0..50021728 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { @@ -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" ) } @@ -234,9 +234,11 @@ tasks.register("updateOpenApiSpecs") { @Suppress("UnstableApiUsage") // testing { suites { - val test by getting(JvmTestSuite::class) { + withType { useJUnitJupiter(libs.versions.junit.jupiter) + } + val test by getting(JvmTestSuite::class) { dependencies { implementation(libs.junit.systemExit) implementation(libs.mockito) @@ -272,22 +274,22 @@ testing { testTask.configure { systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class" } - } - named("systemTest") { testTask.configure { dependsOn(tasks.shadowJar) - systemProperties["cliExec"] = javaLauncher.get().executablePath.asFile.absolutePath + " -jar " + - tasks.shadowJar.map { it.outputs.files.singleFile }.get() + 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 + systemProperties["cliExec"] = tasks.nativeCompile.map { it.outputs.files.singleFile }.get() + .resolve(project.name).absolutePath } } } @@ -398,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," + @@ -445,6 +448,7 @@ val nativeImageOptions by graalvmNative.binaries.named("main") { "org.tinylog.writers," + "org.tinylog.writers.raw" ) + //@formatter:on } graalvmNative { @@ -480,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))