From e334ab456f7bad22361815b744fb9b89ca70c3b5 Mon Sep 17 00:00:00 2001 From: David Venable Date: Wed, 25 Aug 2021 10:03:30 -0500 Subject: [PATCH] Use JUnit Jupiter for all projects and added Mockito to all projects for testing. Made some code style updates such as using camelCase and preferring standard strings over GStrings when interpolation is not necessary. The integrationTest implementation and runtime configurations now inherit from test. Signed-off-by: David Venable --- build-resources.gradle | 6 ++++-- build.gradle | 18 ++++++++++-------- .../build.gradle | 2 +- data-prepper-core/build.gradle | 1 - data-prepper-core/integrationTest.gradle | 10 +++++++--- .../blocking-buffer/build.gradle | 1 - data-prepper-plugins/common/build.gradle | 1 - data-prepper-plugins/opensearch/build.gradle | 13 ++++++++++--- .../otel-trace-group-prepper/build.gradle | 4 +--- .../otel-trace-raw-prepper/build.gradle | 4 ++-- .../otel-trace-source/build.gradle | 13 ++----------- .../peer-forwarder/build.gradle | 13 ++----------- .../service-map-stateful/build.gradle | 4 ++-- research/zipkin-elastic-to-otel/build.gradle | 4 ++-- 14 files changed, 43 insertions(+), 51 deletions(-) diff --git a/build-resources.gradle b/build-resources.gradle index c497730c7b..ca65104b7b 100644 --- a/build-resources.gradle +++ b/build-resources.gradle @@ -11,8 +11,10 @@ //preferably try to main the alphabetical order ext.versionMap = [ - opentelemetry_proto : '1.0.1-alpha', - opensearch_version: '1.0.0-alpha2' + junitJupiter : '5.7.2', + mockito : '3.11.2', + opentelemetryProto : '1.0.1-alpha', + opensearchVersion : '1.0.0-alpha2' ] ext.coreProjects = [project(':data-prepper-api'), project(':data-prepper-core'), project('data-prepper-plugins:common')] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 482d4c01e4..9826561380 100644 --- a/build.gradle +++ b/build.gradle @@ -49,13 +49,15 @@ subprojects { } } dependencies { - implementation "com.google.guava:guava:29.0-jre" - implementation "org.apache.logging.log4j:log4j-core:2.14.0" - implementation "org.slf4j:slf4j-api:1.7.30" - implementation "org.apache.logging.log4j:log4j-slf4j-impl:2.14.0" - testImplementation("junit:junit:4.13") { - exclude group: 'org.hamcrest' // workaround for jarHell - } + implementation 'com.google.guava:guava:29.0-jre' + implementation 'org.apache.logging.log4j:log4j-core:2.14.0' + implementation 'org.slf4j:slf4j-api:1.7.30' + implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0' + testImplementation platform("org.junit:junit-bom:${versionMap.junitJupiter}") + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.junit.vintage:junit-vintage-engine' + testImplementation "org.mockito:mockito-core:${versionMap.mockito}" + testImplementation "org.mockito:mockito-junit-jupiter:${versionMap.mockito}" } build.dependsOn test jacocoTestReport { @@ -75,7 +77,7 @@ configure(coreProjects) { } } test { - useJUnit() + useJUnitPlatform() finalizedBy jacocoTestReport // report is always generated after tests run } jacocoTestCoverageVerification { diff --git a/data-prepper-benchmarks/service-map-stateful-benchmarks/build.gradle b/data-prepper-benchmarks/service-map-stateful-benchmarks/build.gradle index ef35391197..14f201d345 100644 --- a/data-prepper-benchmarks/service-map-stateful-benchmarks/build.gradle +++ b/data-prepper-benchmarks/service-map-stateful-benchmarks/build.gradle @@ -25,5 +25,5 @@ repositories { dependencies { implementation project(':data-prepper-plugins:service-map-stateful') - jmh "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + jmh "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" } diff --git a/data-prepper-core/build.gradle b/data-prepper-core/build.gradle index 2fcb062ed8..fa7d7953da 100644 --- a/data-prepper-core/build.gradle +++ b/data-prepper-core/build.gradle @@ -35,7 +35,6 @@ dependencies { implementation "io.micrometer:micrometer-registry-cloudwatch2:1.7.2" implementation "software.amazon.awssdk:cloudwatch:2.17.15" testImplementation "org.hamcrest:hamcrest:2.2" - testImplementation "org.mockito:mockito-core:3.11.2" } jar { diff --git a/data-prepper-core/integrationTest.gradle b/data-prepper-core/integrationTest.gradle index e87de8a436..84d8a42019 100644 --- a/data-prepper-core/integrationTest.gradle +++ b/data-prepper-core/integrationTest.gradle @@ -37,21 +37,25 @@ sourceSets { } } +configurations { + integrationTestImplementation.extendsFrom testImplementation + integrationTestRuntime.extendsFrom testRuntime +} + repositories { // TODO: replace local built OpenSearch artifact with the public artifact mavenLocal() } dependencies { - integrationTestCompile("junit:junit:4.13") integrationTestCompile project(':data-prepper-plugins:opensearch') integrationTestCompile project(':data-prepper-plugins:otel-trace-group-prepper') integrationTestImplementation "org.awaitility:awaitility:4.0.3" - integrationTestImplementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + integrationTestImplementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" integrationTestImplementation 'com.google.protobuf:protobuf-java-util:3.13.0' integrationTestImplementation "com.linecorp.armeria:armeria:1.0.0" integrationTestImplementation "com.linecorp.armeria:armeria-grpc:1.0.0" - integrationTestImplementation "org.opensearch.client:opensearch-rest-high-level-client:${versionMap.opensearch_version}" + integrationTestImplementation "org.opensearch.client:opensearch-rest-high-level-client:${versionMap.opensearchVersion}" integrationTestImplementation "com.fasterxml.jackson.core:jackson-databind:2.12.1" } diff --git a/data-prepper-plugins/blocking-buffer/build.gradle b/data-prepper-plugins/blocking-buffer/build.gradle index 172eb994fc..5925897be5 100644 --- a/data-prepper-plugins/blocking-buffer/build.gradle +++ b/data-prepper-plugins/blocking-buffer/build.gradle @@ -14,7 +14,6 @@ plugins { } dependencies { implementation project(':data-prepper-api') - testImplementation "junit:junit:4.13.2" } jacocoTestCoverageVerification { diff --git a/data-prepper-plugins/common/build.gradle b/data-prepper-plugins/common/build.gradle index 428dadef9c..93d838ef1a 100644 --- a/data-prepper-plugins/common/build.gradle +++ b/data-prepper-plugins/common/build.gradle @@ -17,7 +17,6 @@ dependencies { implementation "com.fasterxml.jackson.core:jackson-databind:2.12.4" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.4" implementation "org.reflections:reflections:0.9.12" - testImplementation "junit:junit:4.13.2" testImplementation "commons-io:commons-io:2.11.0" } diff --git a/data-prepper-plugins/opensearch/build.gradle b/data-prepper-plugins/opensearch/build.gradle index 35406efa3b..36dc80efeb 100644 --- a/data-prepper-plugins/opensearch/build.gradle +++ b/data-prepper-plugins/opensearch/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearch_version}") + opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearchVersion}") opensearch_group = "org.opensearch" distribution = 'oss-zip' } @@ -62,7 +62,11 @@ dependencies { implementation 'software.amazon.awssdk:sts:2.17.15' implementation 'software.amazon.awssdk:url-connection-client:2.17.15' implementation "io.micrometer:micrometer-core:1.7.2" - testImplementation("junit:junit:4.13.2") { + // The OpenSearch build-tools plugin appears to be preventing Gradle's platform + // support from working correctly, so we have to specify the JUnit versions here. + testImplementation "org.junit.jupiter:junit-jupiter:${versionMap.junitJupiter}" + testImplementation "org.junit.vintage:junit-vintage-engine:${versionMap.junitJupiter}" + testImplementation('junit:junit:4.13.2') { exclude group:'org.hamcrest' // workaround for jarHell } testImplementation "org.awaitility:awaitility:4.1.0" @@ -89,11 +93,14 @@ configurations.all { force 'joda-time:joda-time:2.10.10' force 'org.yaml:snakeyaml:1.29' force 'com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.12.4' - force 'junit:junit:4.13' + force 'junit:junit:4.13.2' force "org.slf4j:slf4j-api:1.7.32" force "org.apache.logging.log4j:log4j-api:2.14.1" force "org.apache.logging.log4j:log4j-core:2.14.1" } + // The OpenSearch plugins appear to provide their own version of Mockito + // which is causing problems, so we exclude it. + exclude group: 'org.mockito' } test { diff --git a/data-prepper-plugins/otel-trace-group-prepper/build.gradle b/data-prepper-plugins/otel-trace-group-prepper/build.gradle index f0f618ea85..ddb7df3907 100644 --- a/data-prepper-plugins/otel-trace-group-prepper/build.gradle +++ b/data-prepper-plugins/otel-trace-group-prepper/build.gradle @@ -14,7 +14,7 @@ plugins { } ext { - opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearch_version}") + opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearchVersion}") } repositories { @@ -30,6 +30,4 @@ dependencies { implementation "com.fasterxml.jackson.core:jackson-databind:2.12.4" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.4" implementation "io.micrometer:micrometer-core:1.7.2" - testImplementation "org.mockito:mockito-core:3.11.2" - testImplementation "junit:junit:4.13.2" } \ No newline at end of file diff --git a/data-prepper-plugins/otel-trace-raw-prepper/build.gradle b/data-prepper-plugins/otel-trace-raw-prepper/build.gradle index 989db83950..e17b2d8cc8 100644 --- a/data-prepper-plugins/otel-trace-raw-prepper/build.gradle +++ b/data-prepper-plugins/otel-trace-raw-prepper/build.gradle @@ -18,7 +18,7 @@ dependencies { implementation project(':data-prepper-plugins:common') implementation 'commons-codec:commons-codec:1.15' testImplementation project(':data-prepper-api').sourceSets.test.output - implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" implementation 'com.google.protobuf:protobuf-java-util:3.17.3' implementation "com.linecorp.armeria:armeria:1.9.2" implementation "com.linecorp.armeria:armeria-grpc:1.9.2" @@ -26,7 +26,7 @@ dependencies { implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.4" implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre' testImplementation 'org.assertj:assertj-core:3.20.2' - testImplementation "org.mockito:mockito-inline:3.11.2" + testImplementation "org.mockito:mockito-inline:${versionMap.mockito}" testImplementation "org.hamcrest:hamcrest:2.2" testImplementation "org.awaitility:awaitility:4.1.0" } diff --git a/data-prepper-plugins/otel-trace-source/build.gradle b/data-prepper-plugins/otel-trace-source/build.gradle index 880d509daf..09728f1771 100644 --- a/data-prepper-plugins/otel-trace-source/build.gradle +++ b/data-prepper-plugins/otel-trace-source/build.gradle @@ -18,7 +18,7 @@ dependencies { implementation project(':data-prepper-plugins:blocking-buffer') implementation 'commons-codec:commons-codec:1.15' testImplementation project(':data-prepper-api').sourceSets.test.output - implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" implementation "commons-io:commons-io:2.11.0" implementation "com.amazonaws:aws-java-sdk-s3:1.12.43" implementation "com.amazonaws:aws-java-sdk-acm:1.12.43" @@ -31,20 +31,11 @@ dependencies { implementation "org.bouncycastle:bcprov-jdk15on:1.69" implementation "org.bouncycastle:bcpkix-jdk15on:1.69" testImplementation 'org.assertj:assertj-core:3.20.2' - testImplementation "org.mockito:mockito-inline:3.11.2" + testImplementation "org.mockito:mockito-inline:${versionMap.mockito}" testImplementation "org.hamcrest:hamcrest:2.2" - testImplementation(platform('org.junit:junit-bom:5.7.2')) - testImplementation('org.junit.jupiter:junit-jupiter') - // TODO: update versionMap to use a higher version of mockito for all subprojects - testImplementation("org.mockito:mockito-core:3.11.2") - testImplementation("org.mockito:mockito-junit-jupiter:3.11.2") testImplementation("commons-io:commons-io:2.10.0") } -test { - useJUnitPlatform() -} - jacocoTestCoverageVerification { dependsOn jacocoTestReport violationRules { diff --git a/data-prepper-plugins/peer-forwarder/build.gradle b/data-prepper-plugins/peer-forwarder/build.gradle index 94f13d4d48..34538434e0 100644 --- a/data-prepper-plugins/peer-forwarder/build.gradle +++ b/data-prepper-plugins/peer-forwarder/build.gradle @@ -23,7 +23,7 @@ repositories { dependencies { implementation project(':data-prepper-api') testImplementation project(':data-prepper-api').sourceSets.test.output - implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" implementation "com.linecorp.armeria:armeria:1.9.2" implementation "com.linecorp.armeria:armeria-grpc:1.9.2" implementation(platform('software.amazon.awssdk:bom:2.17.15')) @@ -33,21 +33,12 @@ dependencies { implementation "commons-io:commons-io:2.11.0" implementation "org.apache.commons:commons-lang3:3.12.0" implementation "commons-validator:commons-validator:1.7" - testImplementation(platform('org.junit:junit-bom:5.7.2')) - testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation 'org.junit.vintage:junit-vintage-engine' testImplementation "org.hamcrest:hamcrest:2.2" - testImplementation "org.mockito:mockito-inline:3.11.2" - testImplementation "org.mockito:mockito-core:3.11.2" - testImplementation 'org.mockito:mockito-junit-jupiter:3.11.2' + testImplementation "org.mockito:mockito-inline:${versionMap.mockito}" testImplementation "commons-io:commons-io:2.10.0" testImplementation 'org.awaitility:awaitility:4.1.0' } -test { - useJUnitPlatform() -} - jacocoTestCoverageVerification { dependsOn jacocoTestReport violationRules { diff --git a/data-prepper-plugins/service-map-stateful/build.gradle b/data-prepper-plugins/service-map-stateful/build.gradle index a12df7d8e7..20fae9c165 100644 --- a/data-prepper-plugins/service-map-stateful/build.gradle +++ b/data-prepper-plugins/service-map-stateful/build.gradle @@ -29,9 +29,9 @@ dependencies { testImplementation project(':data-prepper-api').sourceSets.test.output implementation "io.micrometer:micrometer-core:1.7.2" implementation "com.fasterxml.jackson.core:jackson-databind:2.12.4" - implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" testImplementation "org.hamcrest:hamcrest:2.2" - testImplementation "org.mockito:mockito-inline:3.11.2" + testImplementation "org.mockito:mockito-inline:${versionMap.mockito}" } jacocoTestCoverageVerification { diff --git a/research/zipkin-elastic-to-otel/build.gradle b/research/zipkin-elastic-to-otel/build.gradle index 0488ec2e0b..a202c43b75 100644 --- a/research/zipkin-elastic-to-otel/build.gradle +++ b/research/zipkin-elastic-to-otel/build.gradle @@ -15,7 +15,7 @@ plugins { } ext { - opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearch_version}") + opensearch_version = System.getProperty("opensearch.version", "${versionMap.opensearchVersion}") } group 'com.amazon' @@ -49,5 +49,5 @@ dependencies { implementation "com.linecorp.armeria:armeria-grpc:1.0.0" implementation "org.opensearch.client:opensearch-rest-high-level-client:${opensearch_version}" implementation "com.fasterxml.jackson.core:jackson-databind:2.12.1" - implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetry_proto}" + implementation "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" }