diff --git a/serialization-tests/build.gradle b/serialization-tests/build.gradle new file mode 100644 index 0000000000..0e2e82a1b8 --- /dev/null +++ b/serialization-tests/build.gradle @@ -0,0 +1,24 @@ +apply plugin: 'kotlin' + +// Any serialization tests that require further Corda dependencies (other than `core`) should be added to this module. +description 'Corda serialization tests' + +dependencies { + testCompile project(":serialization") + testCompile project(path: ':serialization', configuration: 'testArtifacts') + testCompile project(':node-driver') + + testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}" + testImplementation "junit:junit:$junit_version" + + testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}" + + testCompile "org.assertj:assertj-core:$assertj_version" + testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" +} + +configurations { + testArtifacts.extendsFrom testRuntimeClasspath +} diff --git a/serialization-tests/src/test/README.md b/serialization-tests/src/test/README.md new file mode 100644 index 0000000000..063c5eb864 --- /dev/null +++ b/serialization-tests/src/test/README.md @@ -0,0 +1,3 @@ +# Adding tests to the Serialization module + +Any serialization tests that require further Corda dependencies (other than `core`) should be added to this module. \ No newline at end of file diff --git a/serialization/src/test/java/net/corda/serialization/internal/ForbiddenLambdaSerializationTests.java b/serialization-tests/src/test/java/net/corda/serialization/internal/ForbiddenLambdaSerializationTests.java similarity index 100% rename from serialization/src/test/java/net/corda/serialization/internal/ForbiddenLambdaSerializationTests.java rename to serialization-tests/src/test/java/net/corda/serialization/internal/ForbiddenLambdaSerializationTests.java diff --git a/serialization/src/test/java/net/corda/serialization/internal/LambdaCheckpointSerializationTest.java b/serialization-tests/src/test/java/net/corda/serialization/internal/LambdaCheckpointSerializationTest.java similarity index 100% rename from serialization/src/test/java/net/corda/serialization/internal/LambdaCheckpointSerializationTest.java rename to serialization-tests/src/test/java/net/corda/serialization/internal/LambdaCheckpointSerializationTest.java diff --git a/serialization/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java b/serialization-tests/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java similarity index 92% rename from serialization/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java rename to serialization-tests/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java index 105b017d08..e0b9b305d6 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java +++ b/serialization-tests/src/test/java/net/corda/serialization/internal/carpenter/JavaCalculatedValuesToClassCarpenterTest.java @@ -5,8 +5,10 @@ import net.corda.core.serialization.SerializationContext; import net.corda.core.serialization.SerializationFactory; import net.corda.core.serialization.SerializedBytes; import net.corda.serialization.internal.AllWhitelist; -import net.corda.serialization.internal.amqp.*; -import net.corda.serialization.internal.amqp.Schema; +import net.corda.serialization.internal.amqp.DeserializationInput; +import net.corda.serialization.internal.amqp.Envelope; +import net.corda.serialization.internal.amqp.ObjectAndEnvelope; +import net.corda.serialization.internal.amqp.SerializerFactory; import net.corda.serialization.internal.amqp.testutils.TestSerializationContext; import net.corda.serialization.internal.model.RemoteTypeInformation; import net.corda.serialization.internal.model.TypeIdentifier; @@ -15,10 +17,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static java.util.Collections.singletonList; import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactoryNoEvolution; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; public class JavaCalculatedValuesToClassCarpenterTest extends AmqpCarpenterBase { public JavaCalculatedValuesToClassCarpenterTest() { diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/ContractAttachmentSerializerTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/ContractAttachmentSerializerTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/ContractAttachmentSerializerTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/ContractAttachmentSerializerTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt similarity index 99% rename from serialization/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt index 4fa5a456e2..e4cefe0495 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt +++ b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt @@ -13,7 +13,6 @@ import net.corda.core.contracts.TransactionVerificationException import net.corda.core.crypto.SecureHash import net.corda.core.internal.DEPLOYED_CORDAPP_UPLOADER import net.corda.core.node.services.AttachmentStorage -import net.corda.core.serialization.ClassWhitelist import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.internal.AttachmentsClassLoader import net.corda.core.serialization.internal.CheckpointSerializationContext @@ -110,10 +109,6 @@ class DefaultSerializableSerializer : Serializer() { } } -object EmptyWhitelist : ClassWhitelist { - override fun hasListed(type: Class<*>): Boolean = false -} - class CordaClassResolverTests { private companion object { val emptyListClass = listOf().javaClass diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/ListsSerializationTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/ListsSerializationTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/ListsSerializationTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/ListsSerializationTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/MapsSerializationTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/MapsSerializationTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/MapsSerializationTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/MapsSerializationTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/PrivateKeySerializationTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/PrivateKeySerializationTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/PrivateKeySerializationTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/PrivateKeySerializationTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/SerializationTokenTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/SerializationTokenTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/SerializationTokenTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/SerializationTokenTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt similarity index 95% rename from serialization/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt index de1378fac4..daa9cbe1ce 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt +++ b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/SetsSerializationTest.kt @@ -6,15 +6,15 @@ import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize import net.corda.node.serialization.kryo.kryoMagic import net.corda.node.services.statemachine.DataSessionMessage -import net.corda.serialization.internal.amqp.propertyDescriptors import net.corda.testing.core.SerializationEnvironmentRule import net.corda.testing.internal.kryoSpecific -import org.junit.Assert.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import java.io.ByteArrayOutputStream import java.util.* -import org.assertj.core.api.Assertions.assertThat class SetsSerializationTest { private companion object { @@ -85,7 +85,8 @@ class SetsSerializationTest { */ @Test fun `type variance on setter getter pair does not fail validation`() { - assertThat(VarOfP::class.java.propertyDescriptors()).containsKey("p") + assertThat(VarOfP::class.java.accessPropertyDescriptors()).containsKey("p") } } + diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt similarity index 90% rename from serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt index 1a737bddce..3e27e166a6 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt +++ b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPRemoteTypeModelTests.kt @@ -1,15 +1,13 @@ package net.corda.serialization.internal.amqp -import net.corda.core.flows.FlowException -import net.corda.serialization.internal.amqp.custom.ThrowableSerializer import net.corda.serialization.internal.amqp.testutils.serializeAndReturnSchema import net.corda.serialization.internal.amqp.testutils.testDefaultFactory -import net.corda.serialization.internal.model.* +import net.corda.serialization.internal.accessAsClass +import net.corda.serialization.internal.model.RemoteTypeInformation import net.corda.testing.core.SerializationEnvironmentRule import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test -import java.lang.IllegalArgumentException import java.util.* class AMQPRemoteTypeModelTests { @@ -76,7 +74,7 @@ class AMQPRemoteTypeModelTests { val schema = output.serializeAndReturnSchema(obj) schema.schema.types.forEach { println(it) } val values = typeModel.interpret(SerializationSchemas(schema.schema, schema.transformsSchema)).values - return values.find { it.typeIdentifier.getLocalType().asClass().isAssignableFrom(obj::class.java) } ?: + return values.find { it.typeIdentifier.getLocalType().accessAsClass().isAssignableFrom(obj::class.java) } ?: throw IllegalArgumentException( "Can't find ${obj::class.java.name} in ${values.map { it.typeIdentifier.name}}") } diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AbstractAMQPSerializationSchemeTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AbstractAMQPSerializationSchemeTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AbstractAMQPSerializationSchemeTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AbstractAMQPSerializationSchemeTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistryTests.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistryTests.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistryTests.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistryTests.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/DeserializeQueryableStateTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/DeserializeQueryableStateTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/amqp/DeserializeQueryableStateTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/DeserializeQueryableStateTest.kt diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt similarity index 99% rename from serialization/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt index 4927961900..dca4df5744 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt +++ b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/SerializationOutputTests.kt @@ -222,16 +222,16 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi val bytes = ser.serialize(obj, compression) val decoder = DecoderImpl().apply { - this.register(Envelope.DESCRIPTOR, Envelope.Companion) - this.register(Schema.DESCRIPTOR, Schema.Companion) - this.register(Descriptor.DESCRIPTOR, Descriptor.Companion) - this.register(Field.DESCRIPTOR, Field.Companion) - this.register(CompositeType.DESCRIPTOR, CompositeType.Companion) - this.register(Choice.DESCRIPTOR, Choice.Companion) - this.register(RestrictedType.DESCRIPTOR, RestrictedType.Companion) - this.register(ReferencedObject.DESCRIPTOR, ReferencedObject.Companion) - this.register(TransformsSchema.DESCRIPTOR, TransformsSchema.Companion) - this.register(TransformTypes.DESCRIPTOR, TransformTypes.Companion) + this.register(Envelope.DESCRIPTOR, Envelope) + this.register(Schema.DESCRIPTOR, Schema) + this.register(Descriptor.DESCRIPTOR, Descriptor) + this.register(Field.DESCRIPTOR, Field) + this.register(CompositeType.DESCRIPTOR, CompositeType) + this.register(Choice.DESCRIPTOR, Choice) + this.register(RestrictedType.DESCRIPTOR, RestrictedType) + this.register(ReferencedObject.DESCRIPTOR, ReferencedObject) + this.register(TransformsSchema.DESCRIPTOR, TransformsSchema) + this.register(TransformTypes.DESCRIPTOR, TransformTypes) } EncoderImpl(decoder) DeserializationInput.withDataBytes(bytes, encodingWhitelist) { @@ -424,7 +424,6 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi serdes(obj) } - @Test fun `test inherits generic captured`() { val obj = CapturesGenericX(InheritGenericX(1.0, "Ginger")) @@ -664,7 +663,6 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi object FooContract : Contract { override fun verify(tx: LedgerTransaction) { - } } diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.kt similarity index 100% rename from serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.kt rename to serialization-tests/src/test/kotlin/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.kt diff --git a/serialization/src/test/resources/isolated.jar b/serialization-tests/src/test/resources/isolated.jar similarity index 100% rename from serialization/src/test/resources/isolated.jar rename to serialization-tests/src/test/resources/isolated.jar diff --git a/serialization/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.implementingGenericInterface b/serialization-tests/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.implementingGenericInterface similarity index 100% rename from serialization/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.implementingGenericInterface rename to serialization-tests/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.implementingGenericInterface diff --git a/serialization/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.lenientCarpenter b/serialization-tests/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.lenientCarpenter similarity index 100% rename from serialization/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.lenientCarpenter rename to serialization-tests/src/test/resources/net/corda/serialization/internal/carpenter/SerDeserCarpentryTest.lenientCarpenter diff --git a/serialization/build.gradle b/serialization/build.gradle index 3630e06cfb..fcf70496b0 100644 --- a/serialization/build.gradle +++ b/serialization/build.gradle @@ -37,7 +37,9 @@ dependencies { testCompile "org.assertj:assertj-core:$assertj_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" - testCompile project(':node-driver') + testCompile "org.mockito:mockito-core:$mockito_version" + testCompile 'org.hamcrest:hamcrest-library:2.1' + testCompile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" } configurations { diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializationHelper.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializationHelper.kt index eff270e249..bb5ead2f45 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializationHelper.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializationHelper.kt @@ -118,7 +118,7 @@ internal fun suitableForObjectReference(type: Type): Boolean { /** * Common properties that are to be used in the [SerializationContext.properties] to alter serialization behavior/content */ -internal enum class CommonPropertyNames { +enum class CommonPropertyNames { IncludeInternalInfo, } diff --git a/serialization/src/test/README.md b/serialization/src/test/README.md new file mode 100644 index 0000000000..a98dff4c03 --- /dev/null +++ b/serialization/src/test/README.md @@ -0,0 +1,11 @@ +# Adding tests to the Serialization module + +Any tests that do not require further Corda dependencies (other than `core`) should be added to this module, anything that requires additional +Corda dependencies needs to go into `serialization-tests`. + +The Corda Serialization module should be self-contained and compilable to Java 8 (for the DJVM) bytecode when using a Java 11 compiler. +Prior to this change, it was impossible to use a Java 11 compiler to compile this module to Java 8 bytecode due to its dependencies on other +modules compiled to Java 11 (`node-driver` and transitive dependencies including: `test-utils`, `node`, `test-common`, `common-logging`, `node-api`, +`client-mock`. `tools-cliutils`). +Therefore, any tests that require further Corda dependencies need to be defined in the module `serialization-tests`, which has the full set +of dependencies including `node-driver`. \ No newline at end of file diff --git a/serialization/src/test/java/net/corda/serialization/internal/amqp/ErrorMessageTests.java b/serialization/src/test/java/net/corda/serialization/internal/amqp/ErrorMessageTests.java index df9cb5b046..fc113bce0c 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/amqp/ErrorMessageTests.java +++ b/serialization/src/test/java/net/corda/serialization/internal/amqp/ErrorMessageTests.java @@ -1,15 +1,13 @@ package net.corda.serialization.internal.amqp; -import net.corda.serialization.internal.AllWhitelist; import net.corda.serialization.internal.amqp.testutils.TestSerializationContext; -import org.assertj.core.api.Assertions; import org.junit.Ignore; import org.junit.Test; import java.io.NotSerializableException; import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatThrownBy; @Ignore("Current behaviour allows for the serialization of objects with private members, this will be disallowed at some point in the future") public class ErrorMessageTests { diff --git a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaEvolutionTests.java b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaEvolutionTests.java index 8360cc8af9..409015a7a3 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaEvolutionTests.java +++ b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaEvolutionTests.java @@ -1,6 +1,5 @@ package net.corda.serialization.internal.amqp; -import kotlin.Suppress; import net.corda.core.serialization.SerializedBytes; import net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt; import net.corda.serialization.internal.amqp.testutils.TestSerializationContext; @@ -8,7 +7,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import java.io.*; +import java.io.IOException; +import java.io.NotSerializableException; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaGenericsTest.java b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaGenericsTest.java index ecf7ba358e..2480c7966f 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaGenericsTest.java +++ b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaGenericsTest.java @@ -14,7 +14,7 @@ import java.math.BigInteger; import java.util.*; import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory; -import static org.jgroups.util.Util.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings("unchecked") public class JavaGenericsTest { diff --git a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaPrivatePropertyTests.java b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaPrivatePropertyTests.java index a811807dcb..7cc7dc7e57 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaPrivatePropertyTests.java +++ b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaPrivatePropertyTests.java @@ -5,12 +5,10 @@ import net.corda.serialization.internal.amqp.testutils.TestSerializationContext; import org.junit.Test; import java.io.NotSerializableException; -import java.lang.reflect.Field; -import java.util.Map; -import static net.corda.core.internal.InternalUtils.uncheckedCast; import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class JavaPrivatePropertyTests { static class C { diff --git a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaSerialiseEnumTests.java b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaSerialiseEnumTests.java index e09d1f4da2..3e11ba4e7d 100644 --- a/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaSerialiseEnumTests.java +++ b/serialization/src/test/java/net/corda/serialization/internal/amqp/JavaSerialiseEnumTests.java @@ -1,6 +1,5 @@ package net.corda.serialization.internal.amqp; -import net.corda.core.serialization.SerializedBytes; import net.corda.serialization.internal.amqp.testutils.TestSerializationContext; import org.junit.Test; diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/InternalAccessTestHelpers.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/InternalAccessTestHelpers.kt new file mode 100644 index 0000000000..d2d51b257c --- /dev/null +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/InternalAccessTestHelpers.kt @@ -0,0 +1,19 @@ +package net.corda.serialization.internal + +import net.corda.core.serialization.ClassWhitelist +import net.corda.serialization.internal.amqp.* +import java.lang.reflect.Type + +/** + * A set of functions in serialization:test that allows testing of serialization internal classes in the serialization-tests project. + */ + +const val MAX_TYPE_PARAM_DEPTH = AMQPTypeIdentifierParser.MAX_TYPE_PARAM_DEPTH + +fun Class.accessPropertyDescriptors(validateProperties: Boolean = true): Map = propertyDescriptors(validateProperties) +fun Type.accessAsClass(): Class<*> = asClass() +fun ifThrowsAppend(strToAppendFn: () -> String, block: () -> T): T = net.corda.serialization.internal.amqp.ifThrowsAppend(strToAppendFn, block) + +object EmptyWhitelist : ClassWhitelist { + override fun hasListed(type: Class<*>): Boolean = false +} \ No newline at end of file diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPExceptionsTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPExceptionsTests.kt index b1caa03ecf..e39c558a33 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPExceptionsTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPExceptionsTests.kt @@ -4,6 +4,7 @@ import org.assertj.core.api.Assertions import org.junit.Test import java.io.NotSerializableException import kotlin.test.assertEquals +import net.corda.serialization.internal.ifThrowsAppend class AMQPExceptionsTests { diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPTypeIdentifierParserTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPTypeIdentifierParserTests.kt index f46ab4bde2..52f4005131 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPTypeIdentifierParserTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/AMQPTypeIdentifierParserTests.kt @@ -10,6 +10,7 @@ import java.time.LocalDateTime import java.util.* import kotlin.test.assertEquals import kotlin.test.assertFailsWith +import net.corda.serialization.internal.MAX_TYPE_PARAM_DEPTH class AMQPTypeIdentifierParserTests { @@ -157,7 +158,7 @@ class AMQPTypeIdentifierParserTests { @Test(expected = NotSerializableException::class) fun `test excessive nesting`() { var nested = "java.lang.Integer" - for (i in 1..AMQPTypeIdentifierParser.MAX_TYPE_PARAM_DEPTH) { + for (i in 1..MAX_TYPE_PARAM_DEPTH) { nested = "java.util.List<$nested>" } verify(nested) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolvabilityTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolvabilityTests.kt index 7ca14ea231..b7b0c7acfd 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolvabilityTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolvabilityTests.kt @@ -3,21 +3,19 @@ package net.corda.serialization.internal.amqp import net.corda.core.serialization.* import net.corda.serialization.internal.NotSerializableDetailedException import net.corda.serialization.internal.amqp.testutils.* -import net.corda.testing.common.internal.ProjectStructure.projectRootDir +import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Test import java.io.NotSerializableException import java.net.URI -import java.util.* -import java.util.concurrent.ConcurrentHashMap import kotlin.test.assertEquals import kotlin.test.assertTrue class EnumEvolvabilityTests { @Suppress("UNUSED") val localPath: URI = projectRootDir.toUri().resolve( - "serialization/src/test/resources/net/corda/serialization/internal/amqp") + "serialization-tests/src/test/resources/net/corda/serialization/internal/amqp") companion object { const val VERBOSE = false diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolveTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolveTests.kt index aadcd75d5e..b9009925b1 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolveTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EnumEvolveTests.kt @@ -1,15 +1,16 @@ package net.corda.serialization.internal.amqp import net.corda.core.internal.toPath -import net.corda.core.serialization.* +import net.corda.core.serialization.CordaSerializationTransformEnumDefault +import net.corda.core.serialization.CordaSerializationTransformEnumDefaults +import net.corda.core.serialization.SerializedBytes +import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir import net.corda.serialization.internal.amqp.testutils.deserialize import net.corda.serialization.internal.amqp.testutils.serialize import net.corda.serialization.internal.amqp.testutils.testDefaultFactory import net.corda.serialization.internal.amqp.testutils.testName -import net.corda.testing.common.internal.ProjectStructure.projectRootDir import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy -import org.junit.Ignore import org.junit.Test import java.io.File import java.io.NotSerializableException @@ -23,7 +24,7 @@ import kotlin.test.assertNotNull class EnumEvolveTests { @Suppress("UNUSED") var localPath: URI = projectRootDir.toUri().resolve( - "serialization/src/test/resources/net/corda/serialization/internal/amqp") + "serialization-tests/src/test/resources/net/corda/serialization/internal/amqp") // Version of the class as it was serialised // diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EvolvabilityTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EvolvabilityTests.kt index 6ebe8eb8fd..80e9b366a6 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EvolvabilityTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/EvolvabilityTests.kt @@ -1,8 +1,11 @@ package net.corda.serialization.internal.amqp +import net.corda.core.crypto.Crypto import net.corda.core.crypto.Crypto.generateKeyPair import net.corda.core.crypto.SignedData import net.corda.core.crypto.sign +import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party import net.corda.core.node.NetworkParameters import net.corda.core.node.NotaryInfo import net.corda.core.serialization.ConstructorForDeserialization @@ -10,9 +13,6 @@ import net.corda.core.serialization.DeprecatedConstructorForDeserialization import net.corda.core.serialization.SerializableCalculatedProperty import net.corda.core.serialization.SerializedBytes import net.corda.serialization.internal.amqp.testutils.* -import net.corda.testing.common.internal.ProjectStructure.projectRootDir -import net.corda.testing.core.DUMMY_NOTARY_NAME -import net.corda.testing.core.TestIdentity import org.junit.Ignore import org.junit.Test import java.io.File @@ -21,6 +21,8 @@ import java.net.URI import java.time.Instant import kotlin.test.assertEquals import net.corda.serialization.internal.amqp.custom.InstantSerializer +import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir +import java.math.BigInteger // To regenerate any of the binary test files do the following // @@ -34,7 +36,12 @@ class EvolvabilityTests { // When regenerating the test files this needs to be set to the file system location of the resource files @Suppress("UNUSED") var localPath: URI = projectRootDir.toUri().resolve( - "serialization/src/test/resources/net/corda/serialization/internal/amqp") + "serialization-test/src/test/resources/net/corda/serialization/internal/amqp") + + companion object { + private val DUMMY_NOTARY_NAME = CordaX500Name("Notary Service", "Zurich", "CH") + private val DUMMY_NOTARY_PARTY = Party(DUMMY_NOTARY_NAME, Crypto.deriveKeyPairFromEntropy(Crypto.DEFAULT_SIGNATURE_SCHEME, BigInteger.valueOf(20)).public) + } @Test fun simpleOrderSwapSameType() { @@ -619,7 +626,7 @@ class EvolvabilityTests { assertEquals(1000, networkParams.maxTransactionSize) assertEquals(3, networkParams.minimumPlatformVersion) assertEquals(1, networkParams.notaries.size) - assertEquals(TestIdentity(DUMMY_NOTARY_NAME, 20).party, networkParams.notaries.firstOrNull()?.identity) + assertEquals(DUMMY_NOTARY_PARTY, networkParams.notaries.firstOrNull()?.identity) } // @@ -631,9 +638,8 @@ class EvolvabilityTests { fun `regenerate broken network parameters`() { // note: 6a6b6f256 is the sha that generates the file val resource = "networkParams.." - val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party val networkParameters = NetworkParameters( - 3, listOf(NotaryInfo(DUMMY_NOTARY, false)), 1000, 1000, Instant.EPOCH, 1, emptyMap()) + 3, listOf(NotaryInfo(DUMMY_NOTARY_PARTY, false)), 1000, 1000, Instant.EPOCH, 1, emptyMap()) val sf = testDefaultFactory() sf.register(net.corda.serialization.internal.amqp.custom.InstantSerializer(sf)) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/GenericsTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/GenericsTests.kt index c85fc2a343..0e5abb3fa5 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/GenericsTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/GenericsTests.kt @@ -4,15 +4,17 @@ import net.corda.core.contracts.Attachment import net.corda.core.contracts.AttachmentConstraint import net.corda.core.contracts.ContractState import net.corda.core.contracts.TransactionState +import net.corda.core.crypto.Crypto import net.corda.core.identity.AbstractParty import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party import net.corda.core.serialization.SerializedBytes import net.corda.serialization.internal.amqp.testutils.* import net.corda.serialization.internal.AllWhitelist +import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir import net.corda.serialization.internal.carpenter.ClassCarpenterImpl -import net.corda.testing.common.internal.ProjectStructure.projectRootDir -import net.corda.testing.core.TestIdentity import org.junit.Test +import java.math.BigInteger import java.net.URI import java.util.* import kotlin.test.assertEquals @@ -31,9 +33,10 @@ class GenericsTests { @Suppress("UNUSED") var localPath: URI = projectRootDir.toUri().resolve( - "serialization/src/test/resources/net/corda/serialization/internal/amqp") + "serialization-tests/src/test/resources/net/corda/serialization/internal/amqp") - val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + private val MINI_CORP_NAME = CordaX500Name("Notary Service", "Zurich", "CH") + private val MINI_CORP_PARTY = Party(MINI_CORP_NAME, Crypto.deriveKeyPairFromEntropy(Crypto.DEFAULT_SIGNATURE_SCHEME, BigInteger.valueOf(20)).public) } private fun printSeparator() = if (VERBOSE) println("\n\n-------------------------------------------\n\n") else Unit @@ -313,8 +316,8 @@ class GenericsTests { @Test fun fingerprintingDiffers() { val state = TransactionState( - TestContractState(listOf(miniCorp.party)), - "wibble", miniCorp.party, + TestContractState(listOf(MINI_CORP_PARTY)), + "wibble",MINI_CORP_PARTY, encumbrance = null, constraint = TestAttachmentConstraint()) @@ -326,8 +329,8 @@ class GenericsTests { @Test fun fingerprintingDiffersList() { val state = TransactionState( - TestContractState(listOf(miniCorp.party)), - "wibble", miniCorp.party, + TestContractState(listOf(MINI_CORP_PARTY)), + "wibble", MINI_CORP_PARTY, encumbrance = null, constraint = TestAttachmentConstraint()) @@ -349,8 +352,8 @@ class GenericsTests { data class TransactionStateWrapper (val o: List>) val state = TransactionState ( - TestContractState(listOf(miniCorp.party)), - "wibble", miniCorp.party, + TestContractState(listOf(MINI_CORP_PARTY)), + "wibble", MINI_CORP_PARTY, encumbrance = null, constraint = TestAttachmentConstraint()) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/testutils/AMQPTestUtils.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/testutils/AMQPTestUtils.kt index 77dc08ab79..e0c465ad0a 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/testutils/AMQPTestUtils.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/testutils/AMQPTestUtils.kt @@ -1,8 +1,6 @@ package net.corda.serialization.internal.amqp.testutils -import net.corda.core.internal.copyTo -import net.corda.core.internal.div -import net.corda.core.internal.packageName +import net.corda.core.internal.* import net.corda.core.serialization.SerializationContext import net.corda.core.serialization.SerializationEncoding import net.corda.core.serialization.SerializedBytes @@ -11,11 +9,11 @@ import net.corda.serialization.internal.AllWhitelist import net.corda.serialization.internal.EmptyWhitelist import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.carpenter.ClassCarpenterImpl -import net.corda.testing.common.internal.ProjectStructure import org.apache.qpid.proton.codec.Data import org.junit.Test import java.io.File.separatorChar import java.io.NotSerializableException +import java.nio.file.Path import java.nio.file.StandardCopyOption.REPLACE_EXISTING /** @@ -99,6 +97,16 @@ fun testName(): String { fun Any.testResourceName(): String = "${javaClass.simpleName}.${testName()}" +internal object ProjectStructure { + val projectRootDir: Path = run { + var dir = javaClass.getResource("/").toPath() + while (!(dir / ".git").isDirectory()) { + dir = dir.parent + } + dir + } +} + fun Any.writeTestResource(bytes: OpaqueBytes) { val dir = ProjectStructure.projectRootDir / "serialization" / "src" / "test" / "resources" / javaClass.packageName.replace('.', separatorChar) bytes.open().copyTo(dir / testResourceName(), REPLACE_EXISTING) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenterTestUtils.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenterTestUtils.kt index 189d176d3c..334bd18b22 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenterTestUtils.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenterTestUtils.kt @@ -4,10 +4,10 @@ import com.google.common.reflect.TypeToken import net.corda.core.serialization.ClassWhitelist import net.corda.core.serialization.SerializationContext import net.corda.core.serialization.SerializedBytes +import net.corda.serialization.internal.accessAsClass import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.amqp.testutils.deserializeAndReturnEnvelope import net.corda.serialization.internal.amqp.testutils.serialize -import net.corda.serialization.internal.amqp.testutils.testName import net.corda.serialization.internal.model.* import org.junit.Assert.assertTrue @@ -85,7 +85,7 @@ open class AmqpCarpenterBase(whitelist: ClassWhitelist) { } protected fun RemoteTypeInformation.load(context : SerializationContext): Class<*> = - typeLoader.load(listOf(this), context)[typeIdentifier]!!.asClass() + typeLoader.load(listOf(this), context)[typeIdentifier]!!.accessAsClass() protected fun assertCanLoadAll(context: SerializationContext, vararg types: RemoteTypeInformation) { assertTrue(typeLoader.load(types.asList(), context).keys.containsAll(types.map { it.typeIdentifier })) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/model/ClassCarpentingTypeLoaderTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/model/ClassCarpentingTypeLoaderTests.kt index 683241c117..4a2ca6c208 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/model/ClassCarpentingTypeLoaderTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/model/ClassCarpentingTypeLoaderTests.kt @@ -3,7 +3,7 @@ package net.corda.serialization.internal.model import com.fasterxml.jackson.databind.ObjectMapper import com.google.common.reflect.TypeToken import net.corda.serialization.internal.AllWhitelist -import net.corda.serialization.internal.amqp.asClass +import net.corda.serialization.internal.accessAsClass import net.corda.serialization.internal.amqp.testutils.testSerializationContext import net.corda.serialization.internal.carpenter.ClassCarpenterImpl import org.junit.Test @@ -75,7 +75,7 @@ class ClassCarpentingTypeLoaderTests { } private fun Type.make(vararg params: Any): Any { - val cls = this.asClass() + val cls = this.accessAsClass() val paramTypes = params.map { it::class.javaPrimitiveType ?: it::class.javaObjectType }.toTypedArray() val constructor = cls.constructors.find { it.parameterTypes.zip(paramTypes).all { (expected, actual) -> expected.isAssignableFrom(actual) diff --git a/settings.gradle b/settings.gradle index 2aed29bca5..0c46bc359f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -77,6 +77,7 @@ include 'samples:cordapp-configuration:workflows' include 'samples:network-verifier:contracts' include 'samples:network-verifier:workflows' include 'serialization' +include 'serialization-tests' // Common libraries - start include 'common-validation'