mirror of
https://github.com/corda/corda.git
synced 2025-06-11 20:01:46 +00:00
Documents TestIdentity in the testing API docs.
This commit is contained in:
@ -304,6 +304,57 @@ Contract testing
|
|||||||
The Corda test framework includes the ability to create a test ledger by calling the ``ledger`` function
|
The Corda test framework includes the ability to create a test ledger by calling the ``ledger`` function
|
||||||
on an implementation of the ``ServiceHub`` interface.
|
on an implementation of the ``ServiceHub`` interface.
|
||||||
|
|
||||||
|
Test identities
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
You can create dummy identities to use in test transactions using the ``TestIdentity`` class:
|
||||||
|
|
||||||
|
.. container:: codeset
|
||||||
|
|
||||||
|
.. literalinclude:: ../../docs/source/example-code/src/test/kotlin/net/corda/docs/tutorial/testdsl/TutorialTestDSL.kt
|
||||||
|
:language: kotlin
|
||||||
|
:start-after: DOCSTART 14
|
||||||
|
:end-before: DOCEND 14
|
||||||
|
:dedent: 8
|
||||||
|
|
||||||
|
.. literalinclude:: ../../docs/source/example-code/src/test/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java
|
||||||
|
:language: java
|
||||||
|
:start-after: DOCSTART 14
|
||||||
|
:end-before: DOCEND 14
|
||||||
|
:dedent: 4
|
||||||
|
|
||||||
|
``TestIdentity`` exposes the following fields and methods:
|
||||||
|
|
||||||
|
.. container:: codeset
|
||||||
|
|
||||||
|
.. sourcecode:: kotlin
|
||||||
|
|
||||||
|
val identityParty: Party = bigCorp.party
|
||||||
|
val identityName: CordaX500Name = bigCorp.name
|
||||||
|
val identityPubKey: PublicKey = bigCorp.publicKey
|
||||||
|
val identityKeyPair: KeyPair = bigCorp.keyPair
|
||||||
|
val identityPartyAndCertificate: PartyAndCertificate = bigCorp.identity
|
||||||
|
|
||||||
|
.. sourcecode:: java
|
||||||
|
|
||||||
|
Party identityParty = bigCorp.getParty();
|
||||||
|
CordaX500Name identityName = bigCorp.getName();
|
||||||
|
PublicKey identityPubKey = bigCorp.getPublicKey();
|
||||||
|
KeyPair identityKeyPair = bigCorp.getKeyPair();
|
||||||
|
PartyAndCertificate identityPartyAndCertificate = bigCorp.getIdentity();
|
||||||
|
|
||||||
|
You can also create a unique ``TestIdentity`` using the ``fresh`` method:
|
||||||
|
|
||||||
|
.. container:: codeset
|
||||||
|
|
||||||
|
.. sourcecode:: kotlin
|
||||||
|
|
||||||
|
val uniqueTestIdentity: TestIdentity = TestIdentity.fresh("orgName")
|
||||||
|
|
||||||
|
.. sourcecode:: java
|
||||||
|
|
||||||
|
TestIdentity uniqueTestIdentity = TestIdentity.Companion.fresh("orgName");
|
||||||
|
|
||||||
MockServices
|
MockServices
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ import static net.corda.testing.node.NodeTestUtils.transaction;
|
|||||||
|
|
||||||
public class CommercialPaperTest {
|
public class CommercialPaperTest {
|
||||||
private static final TestIdentity alice = new TestIdentity(ALICE_NAME, 70L);
|
private static final TestIdentity alice = new TestIdentity(ALICE_NAME, 70L);
|
||||||
|
// DOCSTART 14
|
||||||
private static final TestIdentity bigCorp = new TestIdentity(new CordaX500Name("BigCorp", "New York", "GB"));
|
private static final TestIdentity bigCorp = new TestIdentity(new CordaX500Name("BigCorp", "New York", "GB"));
|
||||||
|
// DOCEND 14
|
||||||
private static final TestIdentity bob = new TestIdentity(BOB_NAME, 80L);
|
private static final TestIdentity bob = new TestIdentity(BOB_NAME, 80L);
|
||||||
private static final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
|
private static final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
|
||||||
private final byte[] defaultRef = {123};
|
private final byte[] defaultRef = {123};
|
||||||
|
@ -28,7 +28,9 @@ class CommercialPaperTest {
|
|||||||
private companion object {
|
private companion object {
|
||||||
val alice = TestIdentity(ALICE_NAME, 70)
|
val alice = TestIdentity(ALICE_NAME, 70)
|
||||||
val bob = TestIdentity(BOB_NAME, 80)
|
val bob = TestIdentity(BOB_NAME, 80)
|
||||||
|
// DOCSTART 14
|
||||||
val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
|
val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
|
||||||
|
// DOCEND 14
|
||||||
val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
|
val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
|
||||||
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
||||||
val TEST_TX_TIME: Instant = Instant.parse("2015-04-17T12:00:00.00Z")
|
val TEST_TX_TIME: Instant = Instant.parse("2015-04-17T12:00:00.00Z")
|
||||||
|
Reference in New Issue
Block a user