From b4027d6e3960ffc43ffa89514d87b99150fac4ac Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 1 Apr 2022 08:34:48 -0600 Subject: [PATCH] Use JUnit 5 for unit test execution (#3620) Change the unit test execution to use the Junit5 JUnitPlatform. This allows for a mix of junit 4 and junit 5 tests and for a gradual migration to junit 5 instead of a big bang. One class depended on junit 4 exceptions and was updated. Two tests depending on native libraries fail gracefully on mac (and only mac). Signed-off-by: Danno Ferrin --- CHANGELOG.md | 6 +- acceptance-tests/test-plugins/build.gradle | 5 +- acceptance-tests/tests/build.gradle | 12 +- besu/build.gradle | 7 +- build.gradle | 1 + config/build.gradle | 3 + consensus/clique/build.gradle | 3 + consensus/common/build.gradle | 5 +- consensus/ibft/build.gradle | 5 +- consensus/ibftlegacy/build.gradle | 3 + consensus/merge/build.gradle | 3 + consensus/qbft/build.gradle | 12 +- container-tests/tests/build.gradle | 3 + crypto/build.gradle | 3 + datatypes/build.gradle | 3 + enclave/build.gradle | 3 + errorprone-checks/build.gradle | 3 + ethereum/api/build.gradle | 9 +- ethereum/blockcreation/build.gradle | 5 +- ethereum/core/build.gradle | 3 + ethereum/eth/build.gradle | 5 +- .../TransactionPoolPropagationTest.java | 27 ++-- ethereum/ethstats/build.gradle | 3 + ethereum/evmtool/build.gradle | 3 + ethereum/mock-p2p/build.gradle | 5 +- ethereum/p2p/build.gradle | 5 +- .../netty/TLSContextFactoryTest.java | 149 ++++++++++-------- ethereum/permissioning/build.gradle | 4 + ethereum/retesteth/build.gradle | 3 + ethereum/rlp/build.gradle | 3 + ethereum/stratum/build.gradle | 5 +- ethereum/trie/build.gradle | 3 + evm/build.gradle | 3 + gradle.properties | 2 +- gradle/versions.gradle | 3 + metrics/core/build.gradle | 3 + nat/build.gradle | 3 + pki/build.gradle | 3 + .../HardwareKeyStoreFileWrapperTest.java | 9 +- plugins/rocksdb/build.gradle | 3 + services/kvstore/build.gradle | 3 + services/pipeline/build.gradle | 3 + services/tasks/build.gradle | 3 + util/build.gradle | 5 +- 44 files changed, 250 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 840161d87d..041ea6e062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog -## 22.1.4 +## 22.4.0-RC1 +### Breaking Changes + +### Additions and Improvements +- Unit tests are now executed with JUnit5 [#3620](https://github.com/hyperledger/besu/pull/3620) ## 22.1.3 diff --git a/acceptance-tests/test-plugins/build.gradle b/acceptance-tests/test-plugins/build.gradle index 09d19912d3..8df9a191b4 100644 --- a/acceptance-tests/test-plugins/build.gradle +++ b/acceptance-tests/test-plugins/build.gradle @@ -11,8 +11,11 @@ dependencies { implementation 'com.google.auto.service:auto-service' implementation 'info.picocli:picocli' - testImplementation 'org.assertj:assertj-core' testImplementation 'junit:junit' + testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } task testPluginsJar(type: Jar) { diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index 5476f287cf..cac08cad81 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -53,17 +53,17 @@ dependencies { testImplementation 'io.grpc:grpc-core' testImplementation 'io.grpc:grpc-netty' testImplementation 'io.grpc:grpc-stub' + testImplementation 'io.jaegertracing:jaeger-client' + testImplementation 'io.jaegertracing:jaeger-proto' testImplementation 'io.netty:netty-all' + testImplementation 'io.opentelemetry.proto:opentelemetry-proto' testImplementation 'io.opentelemetry:opentelemetry-api' + testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp' testImplementation 'io.opentelemetry:opentelemetry-sdk' testImplementation 'io.opentelemetry:opentelemetry-sdk-trace' - testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp' - testImplementation 'io.opentelemetry.proto:opentelemetry-proto' testImplementation 'io.opentracing.contrib:opentracing-okhttp3' testImplementation 'io.opentracing:opentracing-api' testImplementation 'io.opentracing:opentracing-util' - testImplementation 'io.jaegertracing:jaeger-client' - testImplementation 'io.jaegertracing:jaeger-proto' testImplementation 'io.vertx:vertx-core' testImplementation 'junit:junit' testImplementation 'org.apache.commons:commons-compress' @@ -71,10 +71,12 @@ dependencies { testImplementation 'org.apache.tuweni:tuweni-crypto' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.testcontainers:testcontainers' testImplementation 'org.web3j:abi' testImplementation 'org.web3j:besu' - testImplementation 'org.testcontainers:testcontainers' + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } test.enabled = false diff --git a/besu/build.gradle b/besu/build.gradle index 878e883e25..378177d289 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -84,16 +84,19 @@ dependencies { testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts') testImplementation project(':testutil') - testImplementation 'tech.pegasys.discovery:discovery' testImplementation 'com.google.auto.service:auto-service' testImplementation 'com.squareup.okhttp3:okhttp' + testImplementation 'commons-io:commons-io' testImplementation 'junit:junit' testImplementation 'org.apache.commons:commons-text' testImplementation 'org.apache.tuweni:tuweni-bytes' testImplementation 'org.apache.tuweni:tuweni-units' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'commons-io:commons-io' testImplementation 'org.testcontainers:testcontainers' + testImplementation 'tech.pegasys.discovery:discovery' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/build.gradle b/build.gradle index e709b96c7d..6633b2427a 100644 --- a/build.gradle +++ b/build.gradle @@ -258,6 +258,7 @@ allprojects { systemProperty name, System.getProperty(name) } } + useJUnitPlatform {} } javadoc { diff --git a/config/build.gradle b/config/build.gradle index a0d2a7d2f3..8e7f197d13 100644 --- a/config/build.gradle +++ b/config/build.gradle @@ -43,7 +43,10 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } configurations { testArtifacts } diff --git a/consensus/clique/build.gradle b/consensus/clique/build.gradle index cc5c927693..a3059f9b1f 100644 --- a/consensus/clique/build.gradle +++ b/consensus/clique/build.gradle @@ -58,5 +58,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/consensus/common/build.gradle b/consensus/common/build.gradle index 0e7b4e279b..e19842fef8 100644 --- a/consensus/common/build.gradle +++ b/consensus/common/build.gradle @@ -55,8 +55,11 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' - testImplementation 'org.mockito:mockito-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' testSupportImplementation project( path: ':crypto', configuration: 'testSupportArtifacts') testSupportImplementation project( path: ':ethereum:core', configuration: 'testSupportArtifacts') diff --git a/consensus/ibft/build.gradle b/consensus/ibft/build.gradle index 1c706c5745..a3b6918e69 100644 --- a/consensus/ibft/build.gradle +++ b/consensus/ibft/build.gradle @@ -69,7 +69,10 @@ dependencies { integrationTestImplementation 'org.mockito:mockito-core' testImplementation 'junit:junit' - testImplementation 'org.awaitility:awaitility' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/consensus/ibftlegacy/build.gradle b/consensus/ibftlegacy/build.gradle index 4dd3093892..9265881661 100644 --- a/consensus/ibftlegacy/build.gradle +++ b/consensus/ibftlegacy/build.gradle @@ -44,5 +44,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/consensus/merge/build.gradle b/consensus/merge/build.gradle index 87fda2832e..5bc8e8adac 100644 --- a/consensus/merge/build.gradle +++ b/consensus/merge/build.gradle @@ -54,6 +54,9 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation project(':ethereum:core') + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/consensus/qbft/build.gradle b/consensus/qbft/build.gradle index 59c61f5516..22a93b1b41 100644 --- a/consensus/qbft/build.gradle +++ b/consensus/qbft/build.gradle @@ -80,10 +80,6 @@ dependencies { integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts') integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') - testImplementation 'junit:junit' - testImplementation 'org.awaitility:awaitility' - testImplementation 'org.assertj:assertj-core' - testImplementation 'org.mockito:mockito-core' testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts') testImplementation project(path: ':config', configuration: 'testSupportArtifacts') testImplementation project(path: ':consensus:common', configuration: 'testArtifacts') @@ -95,6 +91,14 @@ dependencies { testImplementation project(':metrics:core') testImplementation project(':testutil') + testImplementation 'junit:junit' + testImplementation 'org.assertj:assertj-core' + testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + integrationTestImplementation project(':crypto') integrationTestImplementation project(path: ':crypto', configuration: 'testSupportArtifacts') integrationTestImplementation project(path: ':consensus:common', configuration: 'testSupportArtifacts') diff --git a/container-tests/tests/build.gradle b/container-tests/tests/build.gradle index 5b4a9dccc4..7998aa2c0c 100644 --- a/container-tests/tests/build.gradle +++ b/container-tests/tests/build.gradle @@ -20,9 +20,12 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.testcontainers:testcontainers' testImplementation 'org.web3j:core' testImplementation 'org.web3j:quorum' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } test.enabled = false diff --git a/crypto/build.gradle b/crypto/build.gradle index 9ad4cb9b23..33644b13b2 100644 --- a/crypto/build.gradle +++ b/crypto/build.gradle @@ -43,7 +43,10 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } artifacts { diff --git a/datatypes/build.gradle b/datatypes/build.gradle index 74fa2a227e..337ef5cdab 100644 --- a/datatypes/build.gradle +++ b/datatypes/build.gradle @@ -40,6 +40,9 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } configurations { testArtifacts } diff --git a/enclave/build.gradle b/enclave/build.gradle index 608b91df1a..88fbb54a4f 100644 --- a/enclave/build.gradle +++ b/enclave/build.gradle @@ -16,6 +16,9 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' // integration test dependencies. integrationTestImplementation project(':testutil') diff --git a/errorprone-checks/build.gradle b/errorprone-checks/build.gradle index f5325cbb94..fa1203c2af 100644 --- a/errorprone-checks/build.gradle +++ b/errorprone-checks/build.gradle @@ -37,6 +37,9 @@ dependencies { testImplementation 'com.google.errorprone:error_prone_test_helpers' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' epJavac 'com.google.errorprone:error_prone_check_api' } diff --git a/ethereum/api/build.gradle b/ethereum/api/build.gradle index c710267738..24de67a263 100644 --- a/ethereum/api/build.gradle +++ b/ethereum/api/build.gradle @@ -88,14 +88,17 @@ dependencies { testResourceGeneration project(':besu') testImplementation 'com.squareup.okhttp3:okhttp' - + testImplementation 'io.vertx:vertx-auth-jwt' testImplementation 'io.vertx:vertx-unit' + testImplementation 'io.vertx:vertx-web-client' testImplementation 'junit:junit' testImplementation 'org.apache.logging.log4j:log4j-core' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'io.vertx:vertx-web-client' - testImplementation 'io.vertx:vertx-auth-jwt' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + testSupportImplementation 'org.bouncycastle:bcpkix-jdk15on' integrationTestImplementation project(':config') diff --git a/ethereum/blockcreation/build.gradle b/ethereum/blockcreation/build.gradle index 9ac851695b..b195b286bb 100644 --- a/ethereum/blockcreation/build.gradle +++ b/ethereum/blockcreation/build.gradle @@ -34,9 +34,12 @@ dependencies { testImplementation project(':metrics:core') testImplementation project(':testutil') + testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'com.fasterxml.jackson.core:jackson-databind' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index ef6c58441e..f5e25336cb 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -80,8 +80,11 @@ dependencies { testImplementation 'org.apache.tuweni:tuweni-io' testImplementation 'org.apache.tuweni:tuweni-units' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts') integrationTestImplementation project(':testutil') diff --git a/ethereum/eth/build.gradle b/ethereum/eth/build.gradle index 82b835cd66..271118155c 100644 --- a/ethereum/eth/build.gradle +++ b/ethereum/eth/build.gradle @@ -71,11 +71,14 @@ dependencies { testImplementation project(path: ':metrics:core', configuration: 'testSupportArtifacts') testImplementation project(':testutil') + testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'com.fasterxml.jackson.core:jackson-databind' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' testSupportImplementation 'junit:junit' testSupportImplementation 'org.mockito:mockito-core' diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolPropagationTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolPropagationTest.java index e00092d708..65961d9813 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolPropagationTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolPropagationTest.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.eth.transactions; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; @@ -27,24 +29,23 @@ import java.util.concurrent.TimeUnit; import io.vertx.core.Vertx; import org.apache.tuweni.bytes.Bytes32; import org.awaitility.Awaitility; -import org.junit.After; -import org.junit.Before; -import org.junit.ComparisonFailure; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TransactionPoolPropagationTest { +class TransactionPoolPropagationTest { final DiscoveryConfiguration noDiscovery = DiscoveryConfiguration.create().setActive(false); private Vertx vertx; - @Before - public void setUp() { + @BeforeEach + void setUp() { vertx = Vertx.vertx(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { vertx.close(); } @@ -67,8 +68,8 @@ public class TransactionPoolPropagationTest { * 2nd order test to verify the framework correctly fails if a disconnect occurs It could have a * more detailed exception check - more than just the class. */ - @Test(expected = ComparisonFailure.class) - public void disconnectShouldThrow() throws Exception { + @Test + void disconnectShouldThrow() throws Exception { try (final TestNodeList txNodes = new TestNodeList()) { // Create & Start Nodes @@ -80,7 +81,7 @@ public class TransactionPoolPropagationTest { node1.network.getPeers().iterator().next().disconnect(DisconnectReason.BREACH_OF_PROTOCOL); - wrapup(txNodes); + assertThatThrownBy(() -> wrapup(txNodes)).isInstanceOf(AssertionError.class); } } @@ -89,7 +90,7 @@ public class TransactionPoolPropagationTest { * node. Verify that all nodes get the correct number of pending transactions. */ @Test - public void shouldPropagateLocalAndRemoteTransactions() throws Exception { + void shouldPropagateLocalAndRemoteTransactions() throws Exception { try (final TestNodeList nodes = new TestNodeList()) { // Create & Start Nodes final TestNode node1 = nodes.create(vertx, null, null, noDiscovery); diff --git a/ethereum/ethstats/build.gradle b/ethereum/ethstats/build.gradle index 90c67063cd..c361c16c86 100644 --- a/ethereum/ethstats/build.gradle +++ b/ethereum/ethstats/build.gradle @@ -59,5 +59,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/evmtool/build.gradle b/ethereum/evmtool/build.gradle index ab67f1fc25..68c2b15e94 100644 --- a/ethereum/evmtool/build.gradle +++ b/ethereum/evmtool/build.gradle @@ -62,7 +62,10 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } mainClassName = 'org.hyperledger.besu.evmtool.EvmTool' diff --git a/ethereum/mock-p2p/build.gradle b/ethereum/mock-p2p/build.gradle index b1e605b68f..b73c0a051f 100644 --- a/ethereum/mock-p2p/build.gradle +++ b/ethereum/mock-p2p/build.gradle @@ -37,6 +37,9 @@ dependencies { implementation 'io.vertx:vertx-core' implementation 'org.apache.tuweni:tuweni-bytes' - testImplementation "junit:junit" + testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 132f98ffd0..c74192dbe0 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -66,6 +66,7 @@ dependencies { testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts') testImplementation project(':testutil') + testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation('io.pkts:pkts-core') { exclude group: 'io.pkts', module: 'pkts-sdp' exclude group: 'io.pkts', module: 'pkts-sip' @@ -75,6 +76,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'com.fasterxml.jackson.core:jackson-databind' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/TLSContextFactoryTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/TLSContextFactoryTest.java index eacdbe6337..7170d97ea1 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/TLSContextFactoryTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/TLSContextFactoryTest.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.pki.keystore.HardwareKeyStoreWrapper; import org.hyperledger.besu.pki.keystore.KeyStoreWrapper; import org.hyperledger.besu.pki.keystore.SoftwareKeyStoreWrapper; -import java.io.IOException; import java.net.InetSocketAddress; import java.nio.file.Path; import java.util.Arrays; @@ -45,16 +44,16 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslHandler; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.Assume; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@RunWith(Parameterized.class) -public class TLSContextFactoryTest { +class TLSContextFactoryTest { private static final String JKS = "JKS"; private static final String validKeystorePassword = "test123"; @@ -86,19 +85,36 @@ public class TLSContextFactoryTest { private Server server; private Client client; - @Parameterized.Parameter public String keyStoreWrapperDescription; - - @Parameterized.Parameter(1) - public boolean testSuccess; - - @Parameterized.Parameter(2) - public KeyStoreWrapper serverKeyStoreWrapper; - - @Parameterized.Parameter(3) - public KeyStoreWrapper clientKeyStoreWrapper; + static Collection hardwareKeysData() { + return Arrays.asList( + new Object[][] { + { + "PKCS11 serverPartner1Client1 -> JKS clientPartner2Client1 SuccessfulConnection", + true, + getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), + getSoftwareKeyStoreWrapper( + partner2client1JKSKeystore, partner2client1JKSTruststore, partner2client1CRL) + }, + { + "PKCS11 serverPartner1Client1 -> JKS clientInvalidPartner1Client1 FailedConnection", + false, + getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), + getSoftwareKeyStoreWrapper( + invalidPartner1client1JKSKeystore, + invalidPartner1client1JKSTruststore, + invalidPartner1client1CRL) + }, + { + "PKCS11 serverPartner1Client1 -> JKS clientPartner1Client2rvk FailedConnection", + false, + getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), + getSoftwareKeyStoreWrapper( + partner1client2rvkJKSKeystore, partner1client2rvkJKSTruststore, null) + }, + }); + } - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() { + static Collection softwareKeysData() { return Arrays.asList( new Object[][] { { @@ -117,13 +133,6 @@ public class TLSContextFactoryTest { getSoftwareKeyStoreWrapper( partner1client1JKSKeystore, partner1client1JKSTruststore, partner1client1CRL) }, - { - "PKCS11 serverPartner1Client1 -> JKS clientPartner2Client1 SuccessfulConnection", - true, - getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), - getSoftwareKeyStoreWrapper( - partner2client1JKSKeystore, partner2client1JKSTruststore, partner2client1CRL) - }, { "JKS serverPartner1Client1 -> JKS clientInvalidPartner1Client1 FailedConnection", false, @@ -144,15 +153,6 @@ public class TLSContextFactoryTest { getSoftwareKeyStoreWrapper( partner1client1JKSKeystore, partner1client1JKSTruststore, partner1client1CRL) }, - { - "PKCS11 serverPartner1Client1 -> JKS clientInvalidPartner1Client1 FailedConnection", - false, - getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), - getSoftwareKeyStoreWrapper( - invalidPartner1client1JKSKeystore, - invalidPartner1client1JKSTruststore, - invalidPartner1client1CRL) - }, { "JKS serverPartner1Client2rvk -> JKS clientPartner2Client1 FailedConnection", false, @@ -169,13 +169,6 @@ public class TLSContextFactoryTest { getSoftwareKeyStoreWrapper( partner1client2rvkJKSKeystore, partner1client2rvkJKSTruststore, null) }, - { - "PKCS11 serverPartner1Client1 -> JKS clientPartner1Client2rvk FailedConnection", - false, - getHardwareKeyStoreWrapper(partner1client1PKCS11Config, partner1client1CRL), - getSoftwareKeyStoreWrapper( - partner1client2rvkJKSKeystore, partner1client2rvkJKSTruststore, null) - }, { "JKS serverPartner2Client2rvk -> JKS clientPartner1Client1 FailedConnection", false, @@ -195,11 +188,11 @@ public class TLSContextFactoryTest { }); } - @Before - public void init() throws IOException, InterruptedException {} + @BeforeEach + void init() {} - @After - public void tearDown() { + @AfterEach + void tearDown() { if (client != null) { client.stop(); } @@ -217,7 +210,13 @@ public class TLSContextFactoryTest { try { return new HardwareKeyStoreWrapper( validKeystorePassword, toPath(config), toPath(crlLocation)); - } catch (Exception e) { + } catch (final Exception e) { + if (OS.MAC.isCurrentOs()) { + // nss3 is difficult to setup on mac correctly, don't let it break unit tests for dev + // machines. + Assume.assumeNoException("Failed to initialize hardware keystore", e); + } + // Not a mac, probably a production build. Full failure. throw new PkiException("Failed to initialize hardware keystore", e); } } @@ -233,13 +232,38 @@ public class TLSContextFactoryTest { toPath(trustStore), null, toPath(crl)); - } catch (Exception e) { + } catch (final Exception e) { throw new PkiException("Failed to initialize software keystore", e); } } - @Test - public void testConnection() throws Exception { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("softwareKeysData") + void testConnectionSoftwareKeys( + final String ignoredTestDescription, + final boolean testSuccess, + final KeyStoreWrapper serverKeyStoreWrapper, + final KeyStoreWrapper clientKeyStoreWrapper) + throws Exception { + testConnection(testSuccess, serverKeyStoreWrapper, clientKeyStoreWrapper); + } + + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("hardwareKeysData") + void testConnectionHardwareKeys( + final String ignoredTestDescription, + final boolean testSuccess, + final KeyStoreWrapper serverKeyStoreWrapper, + final KeyStoreWrapper clientKeyStoreWrapper) + throws Exception { + testConnection(testSuccess, serverKeyStoreWrapper, clientKeyStoreWrapper); + } + + private void testConnection( + final boolean testSuccess, + final KeyStoreWrapper serverKeyStoreWrapper, + final KeyStoreWrapper clientKeyStoreWrapper) + throws Exception { final CountDownLatch serverLatch = new CountDownLatch(MAX_NUMBER_MESSAGES); final CountDownLatch clientLatch = new CountDownLatch(MAX_NUMBER_MESSAGES); server = startServer(serverKeyStoreWrapper, serverLatch); @@ -255,7 +279,7 @@ public class TLSContextFactoryTest { client.getChannelFuture().channel().writeAndFlush(Unpooled.copyInt(0)).sync(); serverLatch.await(2, TimeUnit.SECONDS); assertThat(client.getChannelFuture().channel().isActive()).isFalse(); - } catch (Exception e) { + } catch (final Exception e) { // NOOP } } @@ -282,7 +306,7 @@ public class TLSContextFactoryTest { private final String id; private final CountDownLatch latch; - public MessageHandler(final String id, final CountDownLatch latch) { + MessageHandler(final String id, final CountDownLatch latch) { this.id = id; this.latch = latch; } @@ -312,7 +336,7 @@ public class TLSContextFactoryTest { private ChannelFuture channelFuture; private final EventLoopGroup group = new NioEventLoopGroup(); - public ChannelFuture getChannelFuture() { + ChannelFuture getChannelFuture() { return channelFuture; } @@ -335,7 +359,7 @@ public class TLSContextFactoryTest { new ChannelInitializer() { @Override protected void initChannel(final SocketChannel socketChannel) throws Exception { - SslContext sslContext = + final SslContext sslContext = TLSContextFactory.getInstance(keystorePassword, keyStoreWrapper) .createNettyClientSslContext(); @@ -346,11 +370,10 @@ public class TLSContextFactoryTest { } }); - final ChannelFuture cf = b.connect("127.0.0.1", this.port).sync(); - this.channelFuture = cf; + this.channelFuture = b.connect("127.0.0.1", this.port).sync(); } - public void stop() { + void stop() { group.shutdownGracefully(); } } @@ -362,7 +385,6 @@ public class TLSContextFactoryTest { private final CountDownLatch latch; private Channel channel; - private ChannelFuture channelFuture; private final EventLoopGroup parentGroup = new NioEventLoopGroup(); private final EventLoopGroup childGroup = new NioEventLoopGroup(); @@ -376,10 +398,6 @@ public class TLSContextFactoryTest { this.latch = latch; } - public ChannelFuture getChannelFuture() { - return channelFuture; - } - void start() throws Exception { final ServerBootstrap sb = new ServerBootstrap(); sb.group(parentGroup, childGroup) @@ -388,7 +406,7 @@ public class TLSContextFactoryTest { new ChannelInitializer() { @Override public void initChannel(final SocketChannel socketChannel) throws Exception { - SslContext sslContext = + final SslContext sslContext = TLSContextFactory.getInstance(keystorePassword, keyStoreWrapper) .createNettyServerSslContext(); final SslHandler sslHandler = sslContext.newHandler(channel.alloc()); @@ -400,11 +418,10 @@ public class TLSContextFactoryTest { final ChannelFuture cf = sb.bind(0).sync(); this.channel = cf.channel(); - this.channelFuture = cf; this.port = ((InetSocketAddress) channel.localAddress()).getPort(); } - public void stop() { + void stop() { childGroup.shutdownGracefully(); parentGroup.shutdownGracefully(); } diff --git a/ethereum/permissioning/build.gradle b/ethereum/permissioning/build.gradle index 2c8497a17f..e70ffa33e8 100644 --- a/ethereum/permissioning/build.gradle +++ b/ethereum/permissioning/build.gradle @@ -49,8 +49,12 @@ dependencies { testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') testImplementation project(':evm') testImplementation project(':testutil') + testImplementation 'io.vertx:vertx-core' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/retesteth/build.gradle b/ethereum/retesteth/build.gradle index fa5907ec3c..08d0693290 100644 --- a/ethereum/retesteth/build.gradle +++ b/ethereum/retesteth/build.gradle @@ -52,5 +52,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/rlp/build.gradle b/ethereum/rlp/build.gradle index 33a276916c..00bb8460ef 100644 --- a/ethereum/rlp/build.gradle +++ b/ethereum/rlp/build.gradle @@ -45,6 +45,9 @@ dependencies { testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } test { diff --git a/ethereum/stratum/build.gradle b/ethereum/stratum/build.gradle index 6a7927293d..22335b9f24 100644 --- a/ethereum/stratum/build.gradle +++ b/ethereum/stratum/build.gradle @@ -44,11 +44,14 @@ dependencies { implementation 'org.apache.tuweni:tuweni-bytes' implementation 'org.apache.tuweni:tuweni-units' + testImplementation project(path: ':metrics:core', configuration: 'testSupportArtifacts') testImplementation project(':testutil') testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation project(path: ':metrics:core', configuration: 'testSupportArtifacts') + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/ethereum/trie/build.gradle b/ethereum/trie/build.gradle index b44b9f9e44..0e87bafaf9 100644 --- a/ethereum/trie/build.gradle +++ b/ethereum/trie/build.gradle @@ -47,7 +47,10 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.apache.tuweni:tuweni-units' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } test { exclude 'org/hyperledger/besu/ethereum/trie/TrieRefTest.class' } diff --git a/evm/build.gradle b/evm/build.gradle index eb9e27baa1..bfada32030 100644 --- a/evm/build.gradle +++ b/evm/build.gradle @@ -46,7 +46,10 @@ dependencies { testImplementation 'info.picocli:picocli' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } publishing { diff --git a/gradle.properties b/gradle.properties index 8c1c9b93dd..1c10758e62 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=22.1.4-SNAPSHOT +version=22.4.0-RC1 # Workaround for Java 16 and spotless bug 834 https://github.com/diffplug/spotless/issues/834 org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ diff --git a/gradle/versions.gradle b/gradle/versions.gradle index d57dfe11f0..389192d044 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -154,6 +154,9 @@ dependencyManagement { dependency 'org.jupnp:org.jupnp.support:2.6.0' dependency 'org.jupnp:org.jupnp:2.6.0' + dependency 'org.junit.jupiter:junit-jupiter:5.8.2' + dependency 'org.junit.vintage:junit-vintage-engine:5.8.2' + dependency 'org.mockito:mockito-core:4.4.0' dependency 'org.openjdk.jmh:jmh-core:1.34' diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index de1aa06237..4349d3abbf 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -66,8 +66,11 @@ dependencies { testImplementation 'com.squareup.okhttp3:okhttp' testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + testSupportImplementation 'org.mockito:mockito-core' } diff --git a/nat/build.gradle b/nat/build.gradle index ff55f17098..311183b001 100644 --- a/nat/build.gradle +++ b/nat/build.gradle @@ -43,5 +43,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/pki/build.gradle b/pki/build.gradle index 7315ec225d..6ab43a1815 100644 --- a/pki/build.gradle +++ b/pki/build.gradle @@ -36,7 +36,10 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } configurations { testArtifacts } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java index 6ffd57f1cc..3e444b125c 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java @@ -27,6 +27,7 @@ import java.util.stream.Stream; import org.junit.Assume; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.condition.OS; import org.junit.runners.Parameterized; public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest { @@ -60,7 +61,13 @@ public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest .map(provider -> new HardwareKeyStoreWrapper(validKeystorePassword, provider, crlPath)) .orElseGet(() -> new HardwareKeyStoreWrapper(validKeystorePassword, path, crlPath)); } catch (final Exception e) { - throw new PkiException("Failed to initialize NSS keystore", e); + if (OS.MAC.isCurrentOs()) { + // nss3 is difficult to setup on mac correctly, don't let it break unit tests for dev + // machines. + Assume.assumeNoException("Failed to initialize hardware keystore", e); + } + // Not a mac, probably a production build. Full failure. + throw new PkiException("Failed to initialize hardware keystore", e); } } diff --git a/plugins/rocksdb/build.gradle b/plugins/rocksdb/build.gradle index 4463813ede..70c28080ec 100644 --- a/plugins/rocksdb/build.gradle +++ b/plugins/rocksdb/build.gradle @@ -51,5 +51,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/services/kvstore/build.gradle b/services/kvstore/build.gradle index 6001470f06..294d5cc6df 100644 --- a/services/kvstore/build.gradle +++ b/services/kvstore/build.gradle @@ -44,5 +44,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/services/pipeline/build.gradle b/services/pipeline/build.gradle index 517061c1b7..0df845f76d 100644 --- a/services/pipeline/build.gradle +++ b/services/pipeline/build.gradle @@ -40,5 +40,8 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/services/tasks/build.gradle b/services/tasks/build.gradle index fa7ab66cf6..f398248c73 100644 --- a/services/tasks/build.gradle +++ b/services/tasks/build.gradle @@ -42,4 +42,7 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/util/build.gradle b/util/build.gradle index 94d5f9ec37..483a778fb5 100644 --- a/util/build.gradle +++ b/util/build.gradle @@ -40,8 +40,11 @@ dependencies { implementation 'org.apache.tuweni:tuweni-units' implementation 'org.xerial.snappy:snappy-java' - testImplementation 'junit:junit' testImplementation 'io.vertx:vertx-unit' + testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' }