Skip to content

Commit

Permalink
junit 5 (hyperledger#6256)
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: jflo <justin+github@florentine.us>
  • Loading branch information
macfarla authored and jflo committed Dec 18, 2023
1 parent 7545177 commit 0ae323e
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 121 deletions.
1 change: 0 additions & 1 deletion acceptance-tests/test-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
implementation 'com.google.auto.service:auto-service'
implementation 'info.picocli:picocli'

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class BesuPluginContextImplTest {

@BeforeClass
@BeforeAll
public static void createFakePluginDir() throws IOException {
if (System.getProperty("besu.plugins.dir") == null) {
final Path pluginDir = Files.createTempDirectory("besuTest");
Expand All @@ -44,7 +44,7 @@ public static void createFakePluginDir() throws IOException {
}
}

@After
@AfterEach
public void clearTestPluginState() {
System.clearProperty("testPicoCLIPlugin.testOption");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -40,10 +40,12 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

abstract class AbstractJsonRpcTest {
private static final MediaType MEDIA_TYPE_JSON =
protected static final MediaType MEDIA_TYPE_JSON =
MediaType.parse("application/json; charset=utf-8");

static class JsonRpcTestsContext {
Expand All @@ -69,16 +71,14 @@ public void tearDown() {
}

private final JsonRpcTestsContext testsContext;
private final URI testCaseFileURI;

public AbstractJsonRpcTest(
final String ignored, final JsonRpcTestsContext testsContext, final URI testCaseFileURI) {
this.testCaseFileURI = testCaseFileURI;
public AbstractJsonRpcTest(final JsonRpcTestsContext testsContext) {
this.testsContext = testsContext;
}

@Test
public void test() throws IOException {
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("testCases")
public void test(final URI testCaseFileURI) throws IOException {
final JsonRpcTestCase testCase =
testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class);

Expand Down Expand Up @@ -118,22 +118,20 @@ protected void evaluateResponse(
final JsonRpcTestCase testCase,
final URL url) {}

private String getRpcUrl(final String rpcMethod) {
protected String getRpcUrl(final String rpcMethod) {
if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) {
return testsContext.besuNode.engineRpcUrl().get();
}

return testsContext.besuNode.jsonRpcBaseUrl().get();
}

public static Iterable<Object[]> testCases(final String testCasesPath) throws URISyntaxException {
public static Stream<Arguments> testCasesFromPath(final String testCasesPath)
throws URISyntaxException {

final File[] testCasesList =
new File(AbstractJsonRpcTest.class.getResource(testCasesPath).toURI()).listFiles();

return Arrays.stream(testCasesList)
.sorted()
.map(file -> new Object[] {file.getName(), file.toURI()})
.collect(Collectors.toList());
return Arrays.stream(testCasesList).sorted().map(File::toURI).map(Arguments::of);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,33 @@
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.stream.Stream;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

@RunWith(Parameterized.class)
public class DebugReplayBlockAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/debug/replayBlock/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/debug/replayBlock/test-cases/";

private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext;

public DebugReplayBlockAcceptanceTest(final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
public DebugReplayBlockAcceptanceTest() {
super(testsContext);
}

@BeforeClass
@BeforeAll
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
public static Stream<Arguments> testCases() throws URISyntaxException {
return testCasesFromPath(TEST_CASE_PATH);
}

@AfterClass
@AfterAll
public static void tearDown() {
testsContext.cluster.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,33 @@
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.stream.Stream;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

@RunWith(Parameterized.class)
public class DebugSetHeadAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/debug/setHead/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/debug/setHead/test-cases/";

private static JsonRpcTestsContext testsContext;

public DebugSetHeadAcceptanceTest(final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
public DebugSetHeadAcceptanceTest() {
super(testsContext);
}

@BeforeClass
@BeforeAll
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
public static Stream<Arguments> testCases() throws URISyntaxException {
return testCasesFromPath(TEST_CASE_PATH);
}

@AfterClass
@AfterAll
public static void tearDown() {
testsContext.cluster.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase {

Expand All @@ -38,7 +38,7 @@ public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase {

List<SimpleEntry<Integer, Long>> testCase = new ArrayList<>();

@Before
@BeforeEach
public void setUp() throws Exception {
node =
besu.createMinerNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,34 @@
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.stream.Stream;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

@RunWith(Parameterized.class)
public class EthGetBlockByNumberAndHashShanghaiAcceptanceTest extends AbstractJsonRpcTest {
private static final String TEST_RESOURCES_DIR = "/jsonrpc/eth/getBlockBy/";
private static final String GENESIS_FILE = TEST_RESOURCES_DIR + "genesis.json";
private static final String TEST_CASE_PATH = TEST_RESOURCES_DIR + "test-cases/";

private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext;

public EthGetBlockByNumberAndHashShanghaiAcceptanceTest(
final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
public EthGetBlockByNumberAndHashShanghaiAcceptanceTest() {
super(testsContext);
}

@BeforeClass
@BeforeAll
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
public static Stream<Arguments> testCases() throws URISyntaxException {
return testCasesFromPath(TEST_CASE_PATH);
}

@AfterClass
@AfterAll
public static void tearDown() {
testsContext.cluster.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,35 @@
import org.hyperledger.besu.tests.acceptance.dsl.rpc.JsonRpcTestCase;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import okhttp3.Call;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

@RunWith(Parameterized.class)
public class ExecutionEngineCancunBlockBuildingAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/engine/cancun/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/engine/cancun/test-cases/block-production";

private static JsonRpcTestsContext testsContext;

public ExecutionEngineCancunBlockBuildingAcceptanceTest(
final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
public ExecutionEngineCancunBlockBuildingAcceptanceTest() {
super(testsContext);
}

@BeforeClass
@BeforeAll
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
public static Stream<Arguments> testCases() throws URISyntaxException {
return testCasesFromPath(TEST_CASE_PATH);
}

@Override
Expand Down Expand Up @@ -90,7 +86,7 @@ protected void evaluateResponse(
}
}

@AfterClass
@AfterAll
public static void tearDown() {
testsContext.cluster.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,33 @@
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.stream.Stream;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

@RunWith(Parameterized.class)
public class ExecutionEngineEip6110AcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/engine/eip6110/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/engine/eip6110/test-cases/";

private static JsonRpcTestsContext testsContext;

public ExecutionEngineEip6110AcceptanceTest(final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
public ExecutionEngineEip6110AcceptanceTest() {
super(testsContext);
}

@BeforeClass
@BeforeAll
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
public static Stream<Arguments> testCases() throws URISyntaxException {
return testCasesFromPath(TEST_CASE_PATH);
}

@AfterClass
@AfterAll
public static void tearDown() {
testsContext.cluster.close();
}
Expand Down
Loading

0 comments on commit 0ae323e

Please sign in to comment.