From c73048a3e035719bd64cb0057cbebdcaf05e6b8d Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Mon, 7 Dec 2020 17:50:57 +0300 Subject: [PATCH] Integration tests for diktat-maven-plugin (#607) ### What's done: * Added integration tests via maven-itf for diktat-maven-plugin --- .github/workflows/build_and_test.yml | 4 +- diktat-maven-plugin/pom.xml | 94 ++++++++++++++++++- .../maven/DiktatMavenPluginIntegrationTest.kt | 32 +++++++ diktat-rules/pom.xml | 2 + 4 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest.kt diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 9ac717ed6f..9dafb60c08 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -26,8 +26,8 @@ jobs: ${{ runner.os }}-maven-build- - name: Maven Package run: mvn -B clean package -DskipTests - - name: Maven Verify - run: mvn -B verify + - name: Maven Install + run: mvn -B install - name: Code coverage report uses: codecov/codecov-action@v1 with: diff --git a/diktat-maven-plugin/pom.xml b/diktat-maven-plugin/pom.xml index 8086a04d03..b531f83920 100644 --- a/diktat-maven-plugin/pom.xml +++ b/diktat-maven-plugin/pom.xml @@ -15,6 +15,7 @@ 3.6.3 UTF-8 + 0.9.0 @@ -48,9 +49,15 @@ ${ktlint.version} - junit - junit - 4.13.1 + org.junit.vintage + junit-vintage-engine + ${junit.version} + test + + + com.soebes.itf.jupiter.extension + itf-jupiter-extension + ${maven.itf.version} test @@ -66,6 +73,11 @@ ${maven.api.version} test + + org.assertj + assertj-core + test + @@ -78,7 +90,7 @@ compile - compile + process-sources compile @@ -91,6 +103,7 @@ + src/test/kotlin @@ -101,7 +114,80 @@ 1.4 + + org.apache.maven.plugins + maven-surefire-plugin + + + *IntegrationTest* + + + + + com.soebes.itf.jupiter.extension + itf-maven-plugin + ${maven.itf.version} + + + installing + pre-integration-test + + install + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${maven.version} + ${maven.home} + + + **/*IntegrationTest* + + ${project.build.testSourceDirectory} + ${project.build.testOutputDirectory} + + + + + integration-test + verify + + + + + + + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + post-integration-test + + report + + + + + + + ../examples/maven + + false + ${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/maven + + diff --git a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest.kt b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest.kt new file mode 100644 index 0000000000..4e2baa9e1f --- /dev/null +++ b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest.kt @@ -0,0 +1,32 @@ +package org.cqfn.diktat.plugin.maven + +import com.soebes.itf.jupiter.extension.MavenGoal +import com.soebes.itf.jupiter.extension.MavenJupiterExtension +import com.soebes.itf.jupiter.extension.MavenTest +import com.soebes.itf.jupiter.maven.MavenExecutionResult +import org.junit.jupiter.api.Assertions +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.readText + +/** + * Integration tests for diktat-maven-plugin. + * Run against the project from diktat-examples. + * Note: for maven itf test name should equal example project's directory name, which we have in pom.xml. + */ +@OptIn(ExperimentalPathApi::class) +@MavenJupiterExtension +class DiktatMavenPluginIntegrationTest { + @MavenTest + @MavenGoal("diktat:check@diktat") + fun maven(result: MavenExecutionResult) { + Assertions.assertEquals(1, result.returnCode) + Assertions.assertFalse(result.isError) + Assertions.assertFalse(result.isSuccesful) + Assertions.assertTrue(result.isFailure) + + val mavenLog = result.mavenLog.stdout.readText() + Assertions.assertTrue( + mavenLog.contains("[HEADER_MISSING_OR_WRONG_COPYRIGHT]") + ) + } +} diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index 6503fb69f3..575060b87a 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -110,6 +110,8 @@ + src/main/kotlin + src/test/kotlin ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin