From 6e570b4d65b8655d140a127c42366845cce402cc Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Wed, 12 Jul 2017 14:09:49 +0100 Subject: [PATCH] Moved dummy stuff from core into test-utils --- .../schemas/testing/DummyDealStateSchemaV1.kt | 25 -------------- .../testing/DummyLinearStateSchemaV2.kt | 24 -------------- .../services/vault/VaultQueryJavaTests.java | 2 +- .../database/HibernateConfigurationTest.kt | 4 +-- .../node/services/vault/VaultQueryTests.kt | 8 ++--- .../node/services/vault/VaultWithCashTest.kt | 2 +- test-utils/build.gradle | 1 + .../testing}/contracts/DummyDealContract.kt | 5 +-- .../testing/contracts/DummyLinearContract.kt | 4 +-- .../corda/testing/contracts/VaultFiller.kt | 1 - .../testing/schemas/DummyDealStateSchemaV1.kt | 33 +++++++++++++++++++ .../schemas}/DummyLinearStateSchemaV1.kt | 2 +- .../schemas/DummyLinearStateSchemaV2.kt | 31 +++++++++++++++++ 13 files changed, 78 insertions(+), 64 deletions(-) delete mode 100644 core/src/main/kotlin/net/corda/core/schemas/testing/DummyDealStateSchemaV1.kt delete mode 100644 core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV2.kt rename {finance/src/main/kotlin/net/corda => test-utils/src/main/kotlin/net/corda/testing}/contracts/DummyDealContract.kt (93%) create mode 100644 test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt rename {core/src/main/kotlin/net/corda/core/schemas/testing => test-utils/src/main/kotlin/net/corda/testing/schemas}/DummyLinearStateSchemaV1.kt (97%) create mode 100644 test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV2.kt diff --git a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyDealStateSchemaV1.kt b/core/src/main/kotlin/net/corda/core/schemas/testing/DummyDealStateSchemaV1.kt deleted file mode 100644 index 4b7a2a5b68..0000000000 --- a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyDealStateSchemaV1.kt +++ /dev/null @@ -1,25 +0,0 @@ -package net.corda.core.schemas.testing - -/** - * An object used to fully qualify the [DummyDealStateSchema] family name (i.e. independent of version). - */ -object DummyDealStateSchema - -/** - * First version of a cash contract ORM schema that maps all fields of the [DummyDealState] contract state as it stood - * at the time of writing. - */ -object DummyDealStateSchemaV1 : net.corda.core.schemas.MappedSchema(schemaFamily = net.corda.core.schemas.testing.DummyDealStateSchema.javaClass, version = 1, mappedTypes = listOf(net.corda.core.schemas.testing.DummyDealStateSchemaV1.PersistentDummyDealState::class.java)) { - @javax.persistence.Entity - @javax.persistence.Table(name = "dummy_deal_states") - class PersistentDummyDealState( - - @javax.persistence.Column(name = "deal_reference") - var dealReference: String, - - /** parent attributes */ - @javax.persistence.Transient - val uid: net.corda.core.contracts.UniqueIdentifier - - ) : net.corda.node.services.vault.schemas.jpa.CommonSchemaV1.LinearState(uid = uid) -} diff --git a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV2.kt b/core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV2.kt deleted file mode 100644 index ec2f36d86c..0000000000 --- a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV2.kt +++ /dev/null @@ -1,24 +0,0 @@ -package net.corda.core.schemas.testing - -/** - * Second version of a cash contract ORM schema that extends the common - * [VaultLinearState] abstract schema - */ -object DummyLinearStateSchemaV2 : net.corda.core.schemas.MappedSchema(schemaFamily = DummyLinearStateSchema.javaClass, version = 2, - mappedTypes = listOf(net.corda.core.schemas.testing.DummyLinearStateSchemaV2.PersistentDummyLinearState::class.java)) { - @javax.persistence.Entity - @javax.persistence.Table(name = "dummy_linear_states_v2") - class PersistentDummyLinearState( - @javax.persistence.Column(name = "linear_string") var linearString: String, - - @javax.persistence.Column(name = "linear_number") var linearNumber: Long, - - @javax.persistence.Column(name = "linear_timestamp") var linearTimestamp: java.time.Instant, - - @javax.persistence.Column(name = "linear_boolean") var linearBoolean: Boolean, - - /** parent attributes */ - @Transient - val uid: net.corda.core.contracts.UniqueIdentifier - ) : net.corda.node.services.vault.schemas.jpa.CommonSchemaV1.LinearState(uid = uid) -} 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 512a0ab5d3..f5b44a3487 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 @@ -12,7 +12,6 @@ import net.corda.core.node.services.*; import net.corda.core.node.services.vault.*; import net.corda.core.node.services.vault.QueryCriteria.*; import net.corda.core.schemas.*; -import net.corda.core.schemas.testing.*; import net.corda.core.transactions.*; import net.corda.core.utilities.*; import net.corda.node.services.database.*; @@ -21,6 +20,7 @@ import net.corda.schemas.*; import net.corda.testing.*; import net.corda.testing.contracts.*; import net.corda.testing.node.*; +import net.corda.testing.schemas.DummyLinearStateSchemaV1; import org.jetbrains.annotations.*; import org.jetbrains.exposed.sql.*; import org.junit.*; diff --git a/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt index 9081d6e72f..48e56ddc55 100644 --- a/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt @@ -12,8 +12,8 @@ import net.corda.core.crypto.toBase58String import net.corda.core.node.services.Vault import net.corda.core.node.services.VaultService import net.corda.core.schemas.PersistentStateRef -import net.corda.core.schemas.testing.DummyLinearStateSchemaV1 -import net.corda.core.schemas.testing.DummyLinearStateSchemaV2 +import net.corda.testing.schemas.DummyLinearStateSchemaV1 +import net.corda.testing.schemas.DummyLinearStateSchemaV2 import net.corda.core.serialization.deserialize import net.corda.core.serialization.storageKryo import net.corda.core.transactions.SignedTransaction diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 42b43e1ce3..b669b07f6d 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -6,7 +6,6 @@ import net.corda.contracts.DealState import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER import net.corda.core.contracts.* -import net.corda.testing.contracts.DummyLinearContract import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.toBase58String import net.corda.core.days @@ -14,10 +13,9 @@ import net.corda.core.identity.Party import net.corda.core.node.services.* import net.corda.core.node.services.vault.* import net.corda.core.node.services.vault.QueryCriteria.* -import net.corda.core.schemas.testing.DummyLinearStateSchemaV1 import net.corda.core.seconds -import net.corda.core.utilities.OpaqueBytes import net.corda.core.transactions.SignedTransaction +import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.toHexString import net.corda.node.services.database.HibernateConfiguration import net.corda.node.services.schema.NodeSchemaService @@ -32,6 +30,7 @@ import net.corda.testing.* import net.corda.testing.contracts.* import net.corda.testing.node.MockServices import net.corda.testing.node.makeTestDataSourceProperties +import net.corda.testing.schemas.DummyLinearStateSchemaV1 import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy @@ -48,7 +47,6 @@ import java.time.LocalDate import java.time.ZoneOffset import java.time.temporal.ChronoUnit import java.util.* -import kotlin.test.assertFails class VaultQueryTests { @@ -974,7 +972,7 @@ class VaultQueryTests { assertThat(states).hasSize(20) assertThat(metadata.first().contractStateClassName).isEqualTo("net.corda.testing.contracts.DummyLinearContract\$State") assertThat(metadata.first().status).isEqualTo(Vault.StateStatus.UNCONSUMED) // 0 = UNCONSUMED - assertThat(metadata.last().contractStateClassName).isEqualTo("net.corda.contracts.DummyDealContract\$State") + assertThat(metadata.last().contractStateClassName).isEqualTo("net.corda.contracts.asset.Cash\$State") assertThat(metadata.last().status).isEqualTo(Vault.StateStatus.CONSUMED) // 1 = CONSUMED } } diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 02686c72b7..4ca05bb8e9 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -1,6 +1,6 @@ package net.corda.node.services.vault -import net.corda.contracts.DummyDealContract +import net.corda.testing.contracts.DummyDealContract import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER import net.corda.testing.contracts.fillWithSomeTestCash diff --git a/test-utils/build.gradle b/test-utils/build.gradle index c0567edec9..f6801db7ef 100644 --- a/test-utils/build.gradle +++ b/test-utils/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'kotlin' +apply plugin: 'kotlin-jpa' apply plugin: 'net.corda.plugins.quasar-utils' apply plugin: 'net.corda.plugins.publish-utils' apply plugin: 'com.jfrog.artifactory' diff --git a/finance/src/main/kotlin/net/corda/contracts/DummyDealContract.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt similarity index 93% rename from finance/src/main/kotlin/net/corda/contracts/DummyDealContract.kt rename to test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt index 39041fbef5..57d155f38d 100644 --- a/finance/src/main/kotlin/net/corda/contracts/DummyDealContract.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt @@ -1,5 +1,6 @@ -package net.corda.contracts +package net.corda.testing.contracts +import net.corda.contracts.DealState import net.corda.core.contracts.Contract import net.corda.core.contracts.TransactionForContract import net.corda.core.contracts.UniqueIdentifier @@ -10,7 +11,7 @@ import net.corda.core.identity.Party import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState import net.corda.core.schemas.QueryableState -import net.corda.core.schemas.testing.DummyDealStateSchemaV1 +import net.corda.testing.schemas.DummyDealStateSchemaV1 import net.corda.core.transactions.TransactionBuilder import java.security.PublicKey diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt index 46519730cf..4f0d31d676 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt @@ -10,8 +10,8 @@ import net.corda.core.identity.AbstractParty import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState import net.corda.core.schemas.QueryableState -import net.corda.core.schemas.testing.DummyLinearStateSchemaV1 -import net.corda.core.schemas.testing.DummyLinearStateSchemaV2 +import net.corda.testing.schemas.DummyLinearStateSchemaV1 +import net.corda.testing.schemas.DummyLinearStateSchemaV2 import java.time.LocalDateTime import java.time.ZoneOffset.UTC diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt index d7ae9ff523..0994505b0b 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt @@ -4,7 +4,6 @@ package net.corda.testing.contracts import net.corda.contracts.Commodity import net.corda.contracts.DealState -import net.corda.contracts.DummyDealContract import net.corda.contracts.asset.* import net.corda.core.contracts.* import net.corda.core.identity.AbstractParty diff --git a/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt new file mode 100644 index 0000000000..b28e8cfe44 --- /dev/null +++ b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt @@ -0,0 +1,33 @@ +package net.corda.testing.schemas + +import net.corda.core.contracts.UniqueIdentifier +import net.corda.core.schemas.MappedSchema +import net.corda.node.services.vault.schemas.jpa.CommonSchemaV1 +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.Table +import javax.persistence.Transient + +/** + * An object used to fully qualify the [DummyDealStateSchema] family name (i.e. independent of version). + */ +object DummyDealStateSchema + +/** + * First version of a cash contract ORM schema that maps all fields of the [DummyDealState] contract state as it stood + * at the time of writing. + */ +object DummyDealStateSchemaV1 : MappedSchema(schemaFamily = DummyDealStateSchema.javaClass, version = 1, mappedTypes = listOf(PersistentDummyDealState::class.java)) { + @Entity + @Table(name = "dummy_deal_states") + class PersistentDummyDealState( + + @Column(name = "deal_reference") + var dealReference: String, + + /** parent attributes */ + @Transient + val uid: UniqueIdentifier + + ) : CommonSchemaV1.LinearState(uid = uid) +} diff --git a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV1.kt b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV1.kt similarity index 97% rename from core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV1.kt rename to test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV1.kt index 3a0b8e3a66..b8e490b04f 100644 --- a/core/src/main/kotlin/net/corda/core/schemas/testing/DummyLinearStateSchemaV1.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV1.kt @@ -1,4 +1,4 @@ -package net.corda.core.schemas.testing +package net.corda.testing.schemas import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState diff --git a/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV2.kt b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV2.kt new file mode 100644 index 0000000000..91f3e49cbf --- /dev/null +++ b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyLinearStateSchemaV2.kt @@ -0,0 +1,31 @@ +package net.corda.testing.schemas + +import net.corda.core.contracts.UniqueIdentifier +import net.corda.core.schemas.MappedSchema +import net.corda.node.services.vault.schemas.jpa.CommonSchemaV1 +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.Table + +/** + * Second version of a cash contract ORM schema that extends the common + * [VaultLinearState] abstract schema + */ +object DummyLinearStateSchemaV2 : MappedSchema(schemaFamily = DummyLinearStateSchema.javaClass, version = 2, + mappedTypes = listOf(PersistentDummyLinearState::class.java)) { + @Entity + @Table(name = "dummy_linear_states_v2") + class PersistentDummyLinearState( + @Column(name = "linear_string") var linearString: String, + + @Column(name = "linear_number") var linearNumber: Long, + + @Column(name = "linear_timestamp") var linearTimestamp: java.time.Instant, + + @Column(name = "linear_boolean") var linearBoolean: Boolean, + + /** parent attributes */ + @Transient + val uid: UniqueIdentifier + ) : CommonSchemaV1.LinearState(uid = uid) +}