@@ -70,7 +70,12 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
7070 mockBackend. givenTestsSkipping(testsSkipping)
7171 mockBackend. givenSkippableTest(" Maven Smoke Tests Project maven-surefire-plugin default-test" , " datadog.smoke.TestSucceed" , " test_to_skip_with_itr" , [" src/main/java/datadog/smoke/Calculator.java" : bits(9 )])
7272
73- def exitCode = whenRunningMavenBuild(jacocoCoverage, commandLineParams)
73+ mockBackend. givenImpactedTestsDetection(true )
74+
75+ def agentArgs = jacocoCoverage ? [
76+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_JACOCO_PLUGIN_VERSION)} =${ JACOCO_PLUGIN_VERSION} " as String
77+ ] : []
78+ def exitCode = whenRunningMavenBuild(agentArgs, commandLineParams)
7479
7580 if (expectSuccess) {
7681 assert exitCode == 0
@@ -103,6 +108,26 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
103108 " test_successful_maven_run_multiple_forks" | LATEST_MAVEN_VERSION | 5 | 1 | true | true | false | true | [] | 17
104109 }
105110
111+ def " test impacted tests detection" () {
112+ givenWrapperPropertiesFile(mavenVersion)
113+ givenMavenProjectFiles(projectName)
114+ givenMavenDependenciesAreLoaded(projectName, mavenVersion)
115+
116+ mockBackend. givenImpactedTestsDetection(true )
117+ mockBackend. givenChangedFile(" src/test/java/datadog/smoke/TestSucceed.java" )
118+
119+ def exitCode = whenRunningMavenBuild([
120+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_CLIENT_ENABLED)} =false" as String
121+ ], [])
122+ assert exitCode == 0
123+
124+ verifyEventsAndCoverages(projectName, " maven" , mavenVersion, mockBackend. waitForEvents(5 ), mockBackend. waitForCoverages(1 ))
125+
126+ where :
127+ projectName | mavenVersion
128+ " test_successful_maven_run_impacted_tests" | " 3.9.9"
129+ }
130+
106131 private void givenWrapperPropertiesFile (String mavenVersion ) {
107132 def distributionUrl = " https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${ mavenVersion} /apache-maven-${ mavenVersion} -bin.zip"
108133
@@ -166,7 +191,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
166191 private static final Collection<String > LOADED_DEPENDENCIES = new HashSet<> ()
167192
168193 private void retryUntilSuccessfulOrNoAttemptsLeft (List<String > mvnCommand ) {
169- def processBuilder = createProcessBuilder(mvnCommand, false , false )
194+ def processBuilder = createProcessBuilder(mvnCommand, false , [] )
170195 for (int attempt = 0 ; attempt < DEPENDENCIES_DOWNLOAD_RETRIES ; attempt++ ) {
171196 def exitCode = runProcess(processBuilder. start())
172197 if (exitCode == 0 ) {
@@ -176,8 +201,8 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
176201 throw new AssertionError ((Object ) " Tried $DEPENDENCIES_DOWNLOAD_RETRIES times to execute $mvnCommand and failed" )
177202 }
178203
179- private int whenRunningMavenBuild (boolean injectJacoco , List<String > additionalCommandLineParams ) {
180- def processBuilder = createProcessBuilder([" -B" , " test" ] + additionalCommandLineParams, true , injectJacoco )
204+ private int whenRunningMavenBuild (List< String > additionalAgentArgs , List<String > additionalCommandLineParams ) {
205+ def processBuilder = createProcessBuilder([" -B" , " test" ] + additionalCommandLineParams, true , additionalAgentArgs )
181206
182207 processBuilder. environment(). put(" DD_API_KEY" , " 01234567890abcdef123456789ABCDEF" )
183208
@@ -198,13 +223,13 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
198223 return p. exitValue()
199224 }
200225
201- ProcessBuilder createProcessBuilder (List<String > mvnCommand , boolean runWithAgent , boolean injectJacoco ) {
226+ ProcessBuilder createProcessBuilder (List<String > mvnCommand , boolean runWithAgent , List< String > additionalAgentArgs ) {
202227 String mavenRunnerShadowJar = System . getProperty(" datadog.smoketest.maven.jar.path" )
203228 assert new File (mavenRunnerShadowJar). isFile()
204229
205230 List<String > command = new ArrayList<> ()
206231 command. add(javaPath())
207- command. addAll(jvmArguments(runWithAgent, injectJacoco ))
232+ command. addAll(jvmArguments(runWithAgent, additionalAgentArgs ))
208233 command. addAll((String []) [" -jar" , mavenRunnerShadowJar])
209234 command. addAll(programArguments())
210235 command. addAll(mvnCommand)
@@ -222,7 +247,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
222247 return System . getProperty(" java.home" ) + separator + " bin" + separator + " java"
223248 }
224249
225- List<String > jvmArguments (boolean runWithAgent , boolean injectJacoco ) {
250+ List<String > jvmArguments (boolean runWithAgent , List< String > additionalAgentArgs ) {
226251 def arguments = [
227252 " -D${ MavenWrapperMain.MVNW_VERBOSE} =true" . toString(),
228253 " -Duser.dir=${ projectHome.toAbsolutePath()} " . toString(),
@@ -249,9 +274,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
249274 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)} =${ mockBackend.intakeUrl} ," +
250275 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_FLAKY_RETRY_ONLY_KNOWN_FLAKES)} =true,"
251276
252- if (injectJacoco) {
253- agentArgument + = " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_JACOCO_PLUGIN_VERSION)} =${ JACOCO_PLUGIN_VERSION} ,"
254- }
277+ agentArgument + = additionalAgentArgs. join(" ," )
255278
256279 arguments + = agentArgument. toString()
257280 }
0 commit comments