Documents TestIdentity in the testing API docs.

This commit is contained in:
Joel Dudley 2018-03-21 15:39:16 +00:00 committed by GitHub
parent 9b981c2755
commit 4d15e17027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 0 deletions

View File

@ -304,6 +304,57 @@ Contract testing
The Corda test framework includes the ability to create a test ledger by calling the ``ledger`` function
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
^^^^^^^^^^^^

View File

@ -27,7 +27,9 @@ import static net.corda.testing.node.NodeTestUtils.transaction;
public class CommercialPaperTest {
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"));
// DOCEND 14
private static final TestIdentity bob = new TestIdentity(BOB_NAME, 80L);
private static final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
private final byte[] defaultRef = {123};

View File

@ -28,7 +28,9 @@ class CommercialPaperTest {
private companion object {
val alice = TestIdentity(ALICE_NAME, 70)
val bob = TestIdentity(BOB_NAME, 80)
// DOCSTART 14
val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
// DOCEND 14
val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
val TEST_TX_TIME: Instant = Instant.parse("2015-04-17T12:00:00.00Z")