From c29673a4a47fe8ff82f7b616a3fe71b3a16950c6 Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Wed, 5 Jul 2017 21:03:06 +0100 Subject: [PATCH] Tidy up --- .../corda/core/serialization/amqp/Schema.kt | 39 ++++--- .../serialization/carpenter/MetaCarpenter.kt | 35 +++++- .../carpenter/ClassCarpenterTestUtils.kt | 14 +-- ...berCompositeSchemaToClassCarpenterTests.kt | 95 ++++++--------- .../InheritanceSchemaToClassCarpenterTests.kt | 58 ++++----- ...berCompositeSchemaToClassCarpenterTests.kt | 110 +++--------------- 6 files changed, 143 insertions(+), 208 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt b/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt index f0f0f80647..f145b86bb8 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt @@ -123,7 +123,7 @@ data class Schema(val types: List) : DescribedType { } } -data class Descriptor(var name: String?, val code: UnsignedLong? = null) : DescribedType { +data class Descriptor(val name: String?, val code: UnsignedLong? = null) : DescribedType { companion object : DescribedTypeConstructor { val DESCRIPTOR = UnsignedLong(3L or DESCRIPTOR_TOP_32BITS) @@ -161,7 +161,7 @@ data class Descriptor(var name: String?, val code: UnsignedLong? = null) : Descr } } -data class Field(var name: String, val type: String, val requires: List, val default: String?, val label: String?, val mandatory: Boolean, val multiple: Boolean) : DescribedType { +data class Field(val name: String, val type: String, val requires: List, val default: String?, val label: String?, val mandatory: Boolean, val multiple: Boolean) : DescribedType { companion object : DescribedTypeConstructor { val DESCRIPTOR = UnsignedLong(4L or DESCRIPTOR_TOP_32BITS) @@ -221,16 +221,9 @@ data class Field(var name: String, val type: String, val requires: List, fun validateType( classLoaders: List = listOf (ClassLoader.getSystemClassLoader()) ) = when (type) { - "int" -> Int::class.javaPrimitiveType!! - "string" -> String::class.java - "short" -> Short::class.javaPrimitiveType!! - "long" -> Long::class.javaPrimitiveType!! - "char" -> Char::class.javaPrimitiveType!! - "boolean" -> Boolean::class.javaPrimitiveType!! - "double" -> Double::class.javaPrimitiveType!! - "float" -> Float::class.javaPrimitiveType!! - "*" -> if (classLoaders.exists(requires[0])) requires[0] else null - else -> if (classLoaders.exists (type)) type else null + "int", "string", "short", "long", "char", "boolean", "double", "float" -> true + "*" -> classLoaders.exists(requires[0]) + else -> classLoaders.exists (type) } fun typeAsString() = if (type =="*") requires[0] else type @@ -256,7 +249,7 @@ sealed class TypeNotation : DescribedType { abstract val descriptor: Descriptor } -data class CompositeType(override var name: String, override val label: String?, override val provides: List, override val descriptor: Descriptor, val fields: List) : TypeNotation() { +data class CompositeType(override val name: String, override val label: String?, override val provides: List, override val descriptor: Descriptor, val fields: List) : TypeNotation() { companion object : DescribedTypeConstructor { val DESCRIPTOR = UnsignedLong(5L or DESCRIPTOR_TOP_32BITS) @@ -300,16 +293,30 @@ data class CompositeType(override var name: String, override val label: String?, return sb.toString() } - /** if we can load the class then we MUST know about all of it's sub elements, - otherwise we couldn't know about this */ + /** + * if we can load the class then we MUST know about all of it's composite elements + */ private fun validateKnown ( classLoaders: List = listOf (ClassLoader.getSystemClassLoader())) { fields.forEach { - if (it.validateType(classLoaders) == null) throw UncarpentableException (name, it.name, it.type) + if (!it.validateType(classLoaders)) throw UncarpentableException (name, it.name, it.type) } } + /** + * based upon this AMQP schema either + * a) add the corespending carpenter schema to the [carpenterSchemas] param + * b) add the class to the dependency tree in [carpenterSchemas] if it cannot be instantiated + * at this time + * + * @param classLoaders list of classLoaders, defaulting toe the system class loader, that might + * be used to load objects + * @param carpenterSchemas structure that holds the dependency tree and list of classes that + * need constructing + * @param force by default a schema is not added to [carpenterSchemas] if it already exists + * on the class path. For testing purposes schema generation can be forced + */ fun carpenterSchema( classLoaders: List = listOf (ClassLoader.getSystemClassLoader()), carpenterSchemas : CarpenterSchemas, diff --git a/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt b/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt index 3f0414c1ad..012df7173e 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt @@ -5,10 +5,30 @@ import net.corda.core.serialization.amqp.TypeNotation /**********************************************************************************************************************/ +/** + * Generated from an AMQP schema this class represents the classes unknown to the deserialiser and that thusly + * require carpenting up in bytecode form. This is a multi step process as carpenting one object may be depedent + * upon the creation of others, this information is tracked in the dependency tree represented by + * [dependencies] and [dependsOn]. Creatable classes are stored in [carpenterSchemas]. + * + * The state of this class after initial generation is expected to mutate as classes are built by the carpenter + * enablaing the resolution of dependencies and thus new carpenter schemas added whilst those already + * carpented schemas are removed. + * + * @property carpenterSchemas The list of carpentable classes + * @property dependencies Maps a class to a list of classes that depend on it being built first + * @property dependsOn Maps a class to a list of classes it depends on being built before it + * + * Once a class is constructed we can quickly check for resolution by first looking at all of its dependents in the + * [dependencies] map. This will give us a list of classes that depended on that class being carpented. We can then + * in turn look up all of those classes in the [dependsOn] list, remove their dependency on the newly created class, + * and if that list is reduced to zero know we can now generate a [Schema] for them and carpent them up + */ data class CarpenterSchemas ( val carpenterSchemas : MutableList, val dependencies : MutableMap>>, - val dependsOn : MutableMap>) { + val dependsOn : MutableMap>) +{ companion object CarpenterSchemaConstructor { fun newInstance(): CarpenterSchemas { return CarpenterSchemas( @@ -19,8 +39,6 @@ data class CarpenterSchemas ( } fun addDepPair(type: TypeNotation, dependant: String, dependee: String) { - fun String.name() = this.split ('.').last().split('$').last() - println ("add dep ${dependant.name()} on ${dependee.name()}") dependsOn.computeIfAbsent(dependee, { mutableListOf() }).add(dependant) dependencies.computeIfAbsent(dependant, { Pair(type, mutableListOf()) }).second.add(dependee) } @@ -31,8 +49,16 @@ data class CarpenterSchemas ( /**********************************************************************************************************************/ +/** + * Take a dependency tree of [CarpenterSchemas] and reduce it to zero by carpenting those classes that + * require it. As classes are carpented check for depdency resolution, if now free generate a [Schema] for + * that class and add it to the list of classes ([CarpenterSchemas.carpenterSchemas]) that require + * carpenting + * + * @property cc a reference to the actual class carpenter we're using to constuct classes + * @property objects a list of carpented classes loaded into the carpenters class loader + */ abstract class MetaCarpenterBase (val schemas : CarpenterSchemas) { - private val cc = ClassCarpenter() val objects = mutableMapOf>() @@ -76,7 +102,6 @@ class MetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { class TestMetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { override fun build() { - println ("TestMetaCarpenter::build") if (schemas.carpenterSchemas.isEmpty()) return step (schemas.carpenterSchemas.removeAt(0)) } diff --git a/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt index 5ec3dbc61d..90d8dc52fc 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt @@ -9,32 +9,32 @@ import net.corda.core.serialization.amqp.SerializationOutput /**********************************************************************************************************************/ -fun curruptName(name: String) = "${name}__carpenter" +fun corruptName(name: String) = "${name}__carpenter" /**********************************************************************************************************************/ /* given a list of class names work through the amqp envelope schema and alter any that match in the fashion defined above */ -fun Schema.curruptName(names: List): Schema { +fun Schema.corruptName(names: List): Schema { val newTypes: MutableList = mutableListOf() for (type in types) { - val newName = if (type.name in names) curruptName(type.name) else type.name + val newName = if (type.name in names) corruptName(type.name) else type.name val newProvides = type.provides.map { it -> - if (it in names) curruptName(it) else it + if (it in names) corruptName(it) else it } val newFields = mutableListOf() (type as CompositeType).fields.forEach { - val type = if (it.type in names) curruptName(it.type) else it.type + val fieldType = if (it.type in names) corruptName(it.type) else it.type val requires = if (it.requires.isNotEmpty() && (it.requires[0] in names)) - listOf(curruptName(it.requires[0])) else it.requires + listOf(corruptName(it.requires[0])) else it.requires - newFields.add(it.copy(type = type, requires = requires)) + newFields.add(it.copy(type = fieldType, requires = requires)) } newTypes.add(type.copy(name = newName, provides = newProvides, fields = newFields)) diff --git a/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt index cc196cd5f3..58b5c84225 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt @@ -96,7 +96,7 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - val amqpSchema = obj.envelope.schema.curruptName(listOf (classTestName ("A"))) + val amqpSchema = obj.envelope.schema.corruptName(listOf (classTestName ("A"))) assert(obj.obj is B) @@ -120,7 +120,7 @@ class CompositeMembers : AmqpCarpenterBase() { assert(obj.obj is B) - val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("B"))) + val amqpSchema = obj.envelope.schema.corruptName(listOf(classTestName("B"))) val carpenterSchema = amqpSchema.carpenterSchema() @@ -130,7 +130,7 @@ class CompositeMembers : AmqpCarpenterBase() { metaCarpenter.build() - assert(curruptName(classTestName("B")) in metaCarpenter.objects) + assert(corruptName(classTestName("B")) in metaCarpenter.objects) } @Test @@ -150,18 +150,18 @@ class CompositeMembers : AmqpCarpenterBase() { assert(obj.obj is B) - val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) + val amqpSchema = obj.envelope.schema.corruptName(listOf(classTestName("A"), classTestName("B"))) val carpenterSchema = amqpSchema.carpenterSchema() /* just verify we're in the expected initial state, A is carpentable, B is not because it depends on A and the dependency chains are in place */ assertEquals(1, carpenterSchema.size) - assertEquals(curruptName(classTestName("A")), carpenterSchema.carpenterSchemas.first().name) + assertEquals(corruptName(classTestName("A")), carpenterSchema.carpenterSchemas.first().name) assertEquals(1, carpenterSchema.dependencies.size) - assert(curruptName(classTestName("B")) in carpenterSchema.dependencies) + assert(corruptName(classTestName("B")) in carpenterSchema.dependencies) assertEquals(1, carpenterSchema.dependsOn.size) - assert(curruptName(classTestName("A")) in carpenterSchema.dependsOn) + assert(corruptName(classTestName("A")) in carpenterSchema.dependsOn) /* test meta carpenter lets us single step over the creation */ val metaCarpenter = TestMetaCarpenter(carpenterSchema) @@ -174,18 +174,18 @@ class CompositeMembers : AmqpCarpenterBase() { /* one build iteration should have carpetned up A and worked out that B is now buildable given it's depedencies have been satisfied */ - assertTrue(curruptName(classTestName("A")) in metaCarpenter.objects) - assertFalse(curruptName(classTestName("B")) in metaCarpenter.objects) + assertTrue(corruptName(classTestName("A")) in metaCarpenter.objects) + assertFalse(corruptName(classTestName("B")) in metaCarpenter.objects) assertEquals(1, carpenterSchema.carpenterSchemas.size) - assertEquals(curruptName(classTestName("B")), carpenterSchema.carpenterSchemas.first().name) + assertEquals(corruptName(classTestName("B")), carpenterSchema.carpenterSchemas.first().name) assertTrue(carpenterSchema.dependencies.isEmpty()) assertTrue(carpenterSchema.dependsOn.isEmpty()) /* second manual iteration, will carpent B */ metaCarpenter.build() - assert(curruptName(classTestName("A")) in metaCarpenter.objects) - assert(curruptName(classTestName("B")) in metaCarpenter.objects) + assert(corruptName(classTestName("A")) in metaCarpenter.objects) + assert(corruptName(classTestName("B")) in metaCarpenter.objects) assertTrue(carpenterSchema.carpenterSchemas.isEmpty()) } @@ -211,7 +211,7 @@ class CompositeMembers : AmqpCarpenterBase() { assert(obj.obj is C) - val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) + val amqpSchema = obj.envelope.schema.corruptName(listOf(classTestName("A"), classTestName("B"))) amqpSchema.carpenterSchema() } @@ -237,13 +237,13 @@ class CompositeMembers : AmqpCarpenterBase() { assert(obj.obj is C) - val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) + val amqpSchema = obj.envelope.schema.corruptName(listOf(classTestName("A"), classTestName("B"))) amqpSchema.carpenterSchema() } - @Test - fun parentsIsUnknownWithUnkownInheritedMember() { + @Test(expected = UncarpentableException::class) + fun parentsIsUnknownWithUnknownInheritedMember() { val testA = 10 val testB = 20 val testC = 30 @@ -263,66 +263,41 @@ class CompositeMembers : AmqpCarpenterBase() { assert(obj.obj is C) - val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) + val carpenterSchema = obj.envelope.schema.corruptName(listOf(classTestName("A"), classTestName("B"))) + + TestMetaCarpenter(carpenterSchema.carpenterSchema()) } + /* - * In this case B holds an element of Interface I_ which is an A but we don't know of A - * but we do know about I_ - */ + * TODO serializer doesn't support inheritnace at the moment, when it does this should work @Test - fun nestedIsInterfaceToUnknown() { + fun `inheritance`() { val testA = 10 val testB = 20 @CordaSerializable - data class A(override val a: Int) : I_ + open class A(open val a: Int) @CordaSerializable - data class B(val a: A, var b: Int) + class B(override val a: Int, val b: Int) : A (a) - val b = B(A(testA), testB) - - val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - - assert(obj.obj is B) - } - - @Test - fun nestedIsUnknownInterface() { - val testA = 10 - val testB = 20 - - @CordaSerializable - data class A(override val a: Int) : I_ - - @CordaSerializable - data class B(val a: A, var b: Int) - - val b = B(A(testA), testB) - - val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - - assert(obj.obj is B) - } - - @Test - fun ParentsIsInterfaceToUnkown() { - val testA = 10 - val testB = 20 - - @CordaSerializable - data class A(override val a: Int) : I_ - - @CordaSerializable - data class B(val a: A, var b: Int) - - val b = B(A(testA), testB) + val b = B(testA, testB) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) assert(obj.obj is B) + + val carpenterSchema = obj.envelope.schema.corruptName(listOf(classTestName("A"), classTestName("B"))) + + val metaCarpenter = TestMetaCarpenter(carpenterSchema.carpenterSchema()) + + assertEquals(1, metaCarpenter.schemas.carpenterSchemas.size) + assertEquals(corruptName(classTestName("B")), metaCarpenter.schemas.carpenterSchemas.first().name) + assertEquals(1, metaCarpenter.schemas.dependencies.size) + assertTrue(corruptName(classTestName("A")) in metaCarpenter.schemas.dependencies) } + */ } diff --git a/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt index 7516b4228e..638074a8e6 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt @@ -67,16 +67,16 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { it's extremely unlikely we'd need to carpent any classes */ assertEquals(0, l1.size) - val curruptSchema = serSchema.curruptName(listOf(classTestName("A"))) + val corruptSchema = serSchema.corruptName(listOf(classTestName("A"))) - val l2 = curruptSchema.carpenterSchema() + val l2 = corruptSchema.carpenterSchema() assertEquals(1, l2.size) - val aSchema = l2.carpenterSchemas.find { it.name == curruptName(classTestName("A")) } + val aSchema = l2.carpenterSchemas.find { it.name == corruptName(classTestName("A")) } assertNotEquals(null, aSchema) - assertEquals(curruptName(classTestName("A")), aSchema!!.name) + assertEquals(corruptName(classTestName("A")), aSchema!!.name) assertEquals(1, aSchema.interfaces.size) assertEquals(net.corda.core.serialization.carpenter.J::class.java, aSchema.interfaces[0]) @@ -116,10 +116,10 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { it's extremely unlikely we'd need to carpent any classes */ assertEquals(0, l1.size) - val curruptSchema = serSchema.curruptName(listOf(classTestName("A"))) - val aName = curruptName(classTestName("A")) + val corruptSchema = serSchema.corruptName(listOf(classTestName("A"))) + val aName = corruptName(classTestName("A")) - val l2 = curruptSchema.carpenterSchema() + val l2 = corruptSchema.carpenterSchema() assertEquals(1, l2.size) @@ -167,9 +167,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { /* pretend we don't know the class we've been sent, i.e. it's unknown to the class loader, and thus needs some carpentry */ - val curruptSchema = serSchema.curruptName(listOf(classTestName("A"))) - val l2 = curruptSchema.carpenterSchema() - val aName = curruptName(classTestName("A")) + val corruptSchema = serSchema.corruptName(listOf(classTestName("A"))) + val l2 = corruptSchema.carpenterSchema() + val aName = corruptName(classTestName("A")) assertEquals(1, l2.size) @@ -217,9 +217,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { it's extremely unlikely we'd need to carpent any classes */ assertEquals(0, l1.size) - val curruptSchema = serSchema.curruptName(listOf(classTestName("A"))) - val l2 = curruptSchema.carpenterSchema() - val aName = curruptName(classTestName("A")) + val corruptSchema = serSchema.corruptName(listOf(classTestName("A"))) + val l2 = corruptSchema.carpenterSchema() + val aName = corruptName(classTestName("A")) assertEquals(1, l2.size) @@ -271,10 +271,10 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { */ assertEquals(4, serSchema.types.size) - val curruptSchema = serSchema.curruptName(listOf(classTestName("A"), classTestName("B"))) - val cSchema = curruptSchema.carpenterSchema() - val aName = curruptName(classTestName("A")) - val bName = curruptName(classTestName("B")) + val corruptSchema = serSchema.corruptName(listOf(classTestName("A"), classTestName("B"))) + val cSchema = corruptSchema.carpenterSchema() + val aName = corruptName(classTestName("A")) + val bName = corruptName(classTestName("B")) assertEquals(2, cSchema.size) @@ -333,7 +333,7 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(4, serSchema.types.size) /* ignore the return as we expect this to throw */ - serSchema.curruptName(listOf( + serSchema.corruptName(listOf( classTestName("A"), "${this.javaClass.`package`.name}.I")).carpenterSchema() } @@ -358,10 +358,10 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { */ assertEquals(2, serSchema.types.size) - val amqpSchema = serSchema.curruptName(listOf(classTestName("A"), "${this.javaClass.`package`.name}.I")) + val amqpSchema = serSchema.corruptName(listOf(classTestName("A"), "${this.javaClass.`package`.name}.I")) - val aName = curruptName(classTestName("A")) - val iName = curruptName("${this.javaClass.`package`.name}.I") + val aName = corruptName(classTestName("A")) + val iName = corruptName("${this.javaClass.`package`.name}.I") val carpenterSchema = amqpSchema.carpenterSchema() @@ -405,14 +405,14 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - val amqpSchema = obj.envelope.schema.curruptName(listOf( + val amqpSchema = obj.envelope.schema.corruptName(listOf( classTestName("A"), "${this.javaClass.`package`.name}.I", "${this.javaClass.`package`.name}.II")) - val aName = curruptName(classTestName("A")) - val iName = curruptName("${this.javaClass.`package`.name}.I") - val iiName = curruptName("${this.javaClass.`package`.name}.II") + val aName = corruptName(classTestName("A")) + val iName = corruptName("${this.javaClass.`package`.name}.I") + val iiName = corruptName("${this.javaClass.`package`.name}.II") val carpenterSchema = amqpSchema.carpenterSchema() @@ -460,14 +460,14 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - val amqpSchema = obj.envelope.schema.curruptName(listOf( + val amqpSchema = obj.envelope.schema.corruptName(listOf( classTestName("A"), "${this.javaClass.`package`.name}.I", "${this.javaClass.`package`.name}.III")) - val aName = curruptName(classTestName("A")) - val iName = curruptName("${this.javaClass.`package`.name}.I") - val iiiName = curruptName("${this.javaClass.`package`.name}.III") + val aName = corruptName(classTestName("A")) + val iName = corruptName("${this.javaClass.`package`.name}.I") + val iiiName = corruptName("${this.javaClass.`package`.name}.III") val carpenterSchema = amqpSchema.carpenterSchema() diff --git a/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt index 304d7185c4..302ca58a4a 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt @@ -38,11 +38,11 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) + val aBuilder = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } @Test @@ -69,52 +69,13 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) + val aBuilder = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } - /* - @Test - fun singleChar () { - val test = 'c' - - @CordaSerializable - data class A(val a : Char) - val a = A(test) - - val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - - assert (obj.obj is A) - val amqpObj = obj.obj as A - - assertEquals (test, amqpObj.a) - assertEquals (1, obj.envelope.schema.types.size) - assertEquals (1, obj.envelope.schema.types.size) - assert (obj.envelope.schema.types[0] is CompositeType) - - val amqpSchema = obj.envelope.schema.types[0] as CompositeType - - assertEquals (1, amqpSchema.fields.size) - assertEquals ("a", amqpSchema.fields[0].name) - assertEquals ("char", amqpSchema.fields[0].type) - - val carpenterSchema = CarpenterSchema.newInstance() - amqpSchema.carpenterSchema(carpenterSchema = carpenterSchema, force = true) - - assert (classTestName ("A") in carpenterSchema.carpenterSchemas) - - val aSchema = carpenterSchema.carpenterSchemas[classTestName ("A")]!! - val pinochio = ClassCarpenter().build(aSchema) - - val p = pinochio.constructors[0].newInstance (test) - - assertEquals (pinochio.getMethod("getA").invoke (p), amqpObj.a) - } - */ - @Test fun singleLong() { val test = 10L @@ -143,10 +104,10 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val aBuilder = ClassCarpenter().build(aSchema) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } @Test @@ -177,47 +138,14 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val aBuilder = ClassCarpenter().build(aSchema) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } - /* @Test - fun singleBool() { - val test = true - - @CordaSerializable - data class A(val a : Boolean) - - var a = A (test) - - val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise (a)) - - assert (obj.obj is A) - val amqpObj = obj.obj as A - - assertEquals (test, amqpObj.a) - assertEquals (1, obj.envelope.schema.types.size) - assert (obj.envelope.schema.types[0] is CompositeType) - - var amqpSchema = obj.envelope.schema.types[0] as CompositeType - - assertEquals (1, amqpSchema.fields.size) - assertEquals ("a", amqpSchema.fields[0].name) - assertEquals ("boolean", amqpSchema.fields[0].type) - - var pinochio = ClassCarpenter().build(ClassCarpenter.Schema(amqpSchema.name, amqpSchema.carpenterSchema())) - - val p = pinochio.constructors[0].newInstance (test) - - assertEquals (pinochio.getMethod("getA").invoke (p), amqpObj.a) - } - */ - - @Test - fun singleDouble() { +fun singleDouble() { val test = 10.0 @CordaSerializable @@ -244,10 +172,10 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val aBuilder = ClassCarpenter().build(aSchema) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } @Test @@ -278,9 +206,9 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { amqpSchema.carpenterSchema(carpenterSchemas = carpenterSchema, force = true) val aSchema = carpenterSchema.carpenterSchemas.find { it.name == classTestName("A") }!! - val pinochio = ClassCarpenter().build(aSchema) - val p = pinochio.constructors[0].newInstance(test) + val aBuilder = ClassCarpenter().build(aSchema) + val p = aBuilder.constructors[0].newInstance(test) - assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) + assertEquals(aBuilder.getMethod("getA").invoke(p), amqpObj.a) } }