From 21e1118ea04f5da324b8b3434c39ea606af2910c Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Thu, 14 Dec 2017 16:30:18 +0000 Subject: [PATCH] Make test constants Java-visible fields. (#2258) --- .../client/rpc/CordaRPCJavaClientTest.java | 4 ++-- .../net/corda/core/flows/FlowsInJavaTest.java | 4 ++-- .../tutorial/testdsl/CommercialPaperTest.java | 22 +++++++++---------- .../contracts/asset/CashTestsJava.java | 4 ++-- .../services/vault/VaultQueryJavaTests.java | 12 +++++----- .../kotlin/net/corda/testing/TestConstants.kt | 11 +++++++++- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java index c4492eca06..a3796af894 100644 --- a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java +++ b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java @@ -28,7 +28,7 @@ import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.contracts.GetBalances.getCashBalance; import static net.corda.node.services.Permissions.invokeRpc; import static net.corda.node.services.Permissions.startFlow; -import static net.corda.testing.TestConstants.getALICE_NAME; +import static net.corda.testing.TestConstants.ALICE_NAME; public class CordaRPCJavaClientTest extends NodeBasedTest { public CordaRPCJavaClientTest() { @@ -56,7 +56,7 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { @Before public void setUp() throws ExecutionException, InterruptedException { - node = startNode(getALICE_NAME(), 1, singletonList(rpcUser)); + node = startNode(ALICE_NAME, 1, singletonList(rpcUser)); client = new CordaRPCClient(requireNonNull(node.getInternals().getConfiguration().getRpcAddress())); } diff --git a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java index 250877bde4..2a536b7f0d 100644 --- a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java +++ b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java @@ -26,8 +26,8 @@ public class FlowsInJavaTest { @Before public void setUp() throws Exception { - aliceNode = mockNet.createPartyNode(TestConstants.getALICE_NAME()); - bobNode = mockNet.createPartyNode(TestConstants.getBOB_NAME()); + aliceNode = mockNet.createPartyNode(TestConstants.ALICE_NAME); + bobNode = mockNet.createPartyNode(TestConstants.BOB_NAME); bob = singleIdentity(bobNode.getInfo()); } diff --git a/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java b/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java index 573bef81b3..0a361a7b95 100644 --- a/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java +++ b/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java @@ -28,11 +28,11 @@ import static net.corda.testing.TestConstants.*; import static org.mockito.Mockito.doReturn; public class CommercialPaperTest { - private static final TestIdentity ALICE = new TestIdentity(getALICE_NAME(), 70L); + private static final TestIdentity ALICE = new TestIdentity(ALICE_NAME, 70L); private static final PublicKey BIG_CORP_PUBKEY = generateKeyPair().getPublic(); - private static final TestIdentity BOB = new TestIdentity(getBOB_NAME(), 80L); + private static final TestIdentity BOB = new TestIdentity(BOB_NAME, 80L); private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); - private static final Party DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L).getParty(); + private static final Party DUMMY_NOTARY = new TestIdentity(DUMMY_NOTARY_NAME, 20L).getParty(); @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); private final byte[] defaultRef = {123}; @@ -52,7 +52,7 @@ public class CommercialPaperTest { MEGA_CORP.ref(defaultRef), MEGA_CORP.getParty(), issuedBy(DOLLARS(1000), MEGA_CORP.ref(defaultRef)), - getTEST_TX_TIME().plus(7, ChronoUnit.DAYS) + TEST_TX_TIME.plus(7, ChronoUnit.DAYS) ); } // DOCEND 1 @@ -131,11 +131,11 @@ public class CommercialPaperTest { tx.attachments(JCP_PROGRAM_ID); tx.tweak(tw -> { tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue()); - tw.timeWindow(getTEST_TX_TIME()); + tw.timeWindow(TEST_TX_TIME); return tw.failsWith("output states are issued by a command signer"); }); tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue()); - tx.timeWindow(getTEST_TX_TIME()); + tx.timeWindow(TEST_TX_TIME); return tx.verifies(); }); return Unit.INSTANCE; @@ -151,11 +151,11 @@ public class CommercialPaperTest { tx.attachments(JCP_PROGRAM_ID); tx.tweak(tw -> { tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue()); - tw.timeWindow(getTEST_TX_TIME()); + tw.timeWindow(TEST_TX_TIME); return tw.failsWith("output states are issued by a command signer"); }); tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue()); - tx.timeWindow(getTEST_TX_TIME()); + tx.timeWindow(TEST_TX_TIME); return tx.verifies(); }); } @@ -178,7 +178,7 @@ public class CommercialPaperTest { tx.output(JCP_PROGRAM_ID, "paper", getPaper()); tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); - tx.timeWindow(getTEST_TX_TIME()); + tx.timeWindow(TEST_TX_TIME); return tx.verifies(); }); @@ -214,7 +214,7 @@ public class CommercialPaperTest { tx.output(Cash.PROGRAM_ID, "paper", getPaper()); tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); - tx.timeWindow(getTEST_TX_TIME()); + tx.timeWindow(TEST_TX_TIME); return tx.verifies(); }); @@ -260,7 +260,7 @@ public class CommercialPaperTest { tx.output(Cash.PROGRAM_ID, "paper", getPaper()); tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); - tx.timeWindow(getTEST_TX_TIME()); + tx.timeWindow(TEST_TX_TIME); return tx.verifies(); }); diff --git a/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java b/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java index b9daac0541..7bde2efedd 100644 --- a/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java +++ b/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java @@ -16,14 +16,14 @@ import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.Currencies.issuedBy; import static net.corda.testing.node.NodeTestUtils.transaction; import static net.corda.testing.CoreTestUtils.rigorousMock; -import static net.corda.testing.TestConstants.getDUMMY_NOTARY_NAME; +import static net.corda.testing.TestConstants.DUMMY_NOTARY_NAME; import static org.mockito.Mockito.doReturn; /** * This is an incomplete Java replica of CashTests.kt to show how to use the Java test DSL */ public class CashTestsJava { - private static final Party DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L).getParty(); + private static final Party DUMMY_NOTARY = new TestIdentity(DUMMY_NOTARY_NAME, 20L).getParty(); private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); private static final TestIdentity MINI_CORP = new TestIdentity(new CordaX500Name("MiniCorp", "London", "GB")); private final PartyAndReference defaultIssuer = MEGA_CORP.ref((byte) 1); diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index f6fa7aa18a..45ae11c758 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -46,19 +46,19 @@ import static net.corda.core.node.services.vault.QueryCriteriaUtils.DEFAULT_PAGE import static net.corda.core.node.services.vault.QueryCriteriaUtils.MAX_PAGE_SIZE; import static net.corda.core.utilities.ByteArrays.toHexString; import static net.corda.testing.CoreTestUtils.rigorousMock; -import static net.corda.testing.TestConstants.getBOC_NAME; -import static net.corda.testing.TestConstants.getCHARLIE_NAME; -import static net.corda.testing.TestConstants.getDUMMY_NOTARY_NAME; +import static net.corda.testing.TestConstants.BOC_NAME; +import static net.corda.testing.TestConstants.CHARLIE_NAME; +import static net.corda.testing.TestConstants.DUMMY_NOTARY_NAME; import static net.corda.testing.node.MockServices.makeTestDatabaseAndMockServices; import static net.corda.testing.node.MockServicesKt.makeTestIdentityService; import static org.assertj.core.api.Assertions.assertThat; public class VaultQueryJavaTests { - private static final TestIdentity BOC = new TestIdentity(getBOC_NAME()); - private static final Party CHARLIE = new TestIdentity(getCHARLIE_NAME(), 90L).getParty(); + private static final TestIdentity BOC = new TestIdentity(BOC_NAME); + private static final Party CHARLIE = new TestIdentity(CHARLIE_NAME, 90L).getParty(); private static final TestIdentity DUMMY_CASH_ISSUER_INFO = new TestIdentity(new CordaX500Name("Snake Oil Issuer", "London", "GB"), 10L); private static final PartyAndReference DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_INFO.ref((byte) 1); - private static final TestIdentity DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L); + private static final TestIdentity DUMMY_NOTARY = new TestIdentity(DUMMY_NOTARY_NAME, 20L); private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt index fc4ee20cd4..f601f988d2 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt @@ -13,14 +13,23 @@ import java.security.PublicKey import java.time.Instant // A dummy time at which we will be pretending test transactions are created. -val TEST_TX_TIME: Instant get() = Instant.parse("2015-04-17T12:00:00.00Z") +@JvmField +val TEST_TX_TIME = Instant.parse("2015-04-17T12:00:00.00Z") +@JvmField val DUMMY_NOTARY_NAME = CordaX500Name("Notary Service", "Zurich", "CH") +@JvmField val DUMMY_BANK_A_NAME = CordaX500Name("Bank A", "London", "GB") +@JvmField val DUMMY_BANK_B_NAME = CordaX500Name("Bank B", "New York", "US") +@JvmField val DUMMY_BANK_C_NAME = CordaX500Name("Bank C", "Tokyo", "JP") +@JvmField val BOC_NAME = CordaX500Name("BankOfCorda", "London", "GB") +@JvmField val ALICE_NAME = CordaX500Name("Alice Corp", "Madrid", "ES") +@JvmField val BOB_NAME = CordaX500Name("Bob Plc", "Rome", "IT") +@JvmField val CHARLIE_NAME = CordaX500Name("Charlie Ltd", "Athens", "GR") val DEV_CA: CertificateAndKeyPair by lazy { // TODO: Should be identity scheme