mirror of
https://github.com/corda/corda.git
synced 2025-01-20 03:36:29 +00:00
Final changes integrating tests into the new API
Fix some rebase issues Ensure tests are using the correct versions of the factories
This commit is contained in:
parent
825908cf15
commit
49c23a58d1
@ -4,7 +4,6 @@ import com.google.common.primitives.Primitives
|
||||
import com.google.common.reflect.TypeResolver
|
||||
import net.corda.core.serialization.ClassWhitelist
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.nodeapi.internal.serialization.AllWhitelist
|
||||
import net.corda.nodeapi.internal.serialization.carpenter.CarpenterSchemas
|
||||
import net.corda.nodeapi.internal.serialization.carpenter.ClassCarpenter
|
||||
import net.corda.nodeapi.internal.serialization.carpenter.MetaCarpenter
|
||||
@ -182,13 +181,13 @@ class SerializerFactory(val whitelist: ClassWhitelist, cl : ClassLoader) {
|
||||
* Iterate over an AMQP schema, for each type ascertain weather it's on ClassPath of [classloader] amd
|
||||
* if not use the [ClassCarpenter] to generate a class to use in it's place
|
||||
*/
|
||||
private fun processSchema(schema: Schema, sentinal: Boolean = false) {
|
||||
private fun processSchema(schema: Schema, sentinel: Boolean = false) {
|
||||
val carpenterSchemas = CarpenterSchemas.newInstance()
|
||||
for (typeNotation in schema.types) {
|
||||
try {
|
||||
}
|
||||
catch (e: ClassNotFoundException) {
|
||||
if (sentinal || (typeNotation !is CompositeType)) throw e
|
||||
processSchemaEntry(typeNotation)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
if (sentinel || (typeNotation !is CompositeType)) throw e
|
||||
typeNotation.carpenterSchema(classloader, carpenterSchemas = carpenterSchemas)
|
||||
}
|
||||
}
|
||||
@ -209,13 +208,13 @@ class SerializerFactory(val whitelist: ClassWhitelist, cl : ClassLoader) {
|
||||
|
||||
private fun processRestrictedType(typeNotation: RestrictedType) {
|
||||
// TODO: class loader logic, and compare the schema.
|
||||
val type = typeForName(typeNotation.name)
|
||||
val type = typeForName(typeNotation.name, classloader)
|
||||
get(null, type)
|
||||
}
|
||||
|
||||
private fun processCompositeType(typeNotation: CompositeType,
|
||||
private fun processCompositeType(typeNotation: CompositeType) {
|
||||
// TODO: class loader logic, and compare the schema.
|
||||
val type = typeForName(typeNotation.name, cl)
|
||||
val type = typeForName(typeNotation.name, classloader)
|
||||
get(type.asClass() ?: throw NotSerializableException("Unable to build composite type for $type"), type)
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ class DeserializeNeedingCarpentrySimpleTypesTest : AmqpCarpenterBase() {
|
||||
private const val VERBOSE = false
|
||||
}
|
||||
|
||||
val sf = SerializerFactory()
|
||||
val sf2 = SerializerFactory()
|
||||
val sf = testDefaultFactory()
|
||||
val sf2 = testDefaultFactory()
|
||||
|
||||
@Test
|
||||
fun singleInt() {
|
||||
|
@ -25,8 +25,8 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() {
|
||||
private const val VERBOSE = false
|
||||
}
|
||||
|
||||
val sf1 = SerializerFactory()
|
||||
val sf2 = SerializerFactory()
|
||||
val sf1 = testDefaultFactory()
|
||||
val sf2 = testDefaultFactory()
|
||||
|
||||
@Test
|
||||
fun verySimpleType() {
|
||||
@ -165,7 +165,7 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() {
|
||||
@Test
|
||||
fun nestedTypes() {
|
||||
val cc = ClassCarpenter()
|
||||
val nestedClass = cc.build (ClassSchema(testName(),
|
||||
val nestedClass = cc.build (ClassSchema("nestedType",
|
||||
mapOf("name" to NonNullableField(String::class.java))))
|
||||
|
||||
val outerClass = cc.build (ClassSchema("outerType",
|
||||
@ -174,6 +174,23 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() {
|
||||
val classInstance = outerClass.constructors.first().newInstance(nestedClass.constructors.first().newInstance("name"))
|
||||
val serialisedBytes = TestSerializationOutput(VERBOSE, sf1).serialize(classInstance)
|
||||
val deserializedObj = DeserializationInput(sf2).deserialize(serialisedBytes)
|
||||
|
||||
val inner = deserializedObj::class.java.getMethod("getInner").invoke(deserializedObj)
|
||||
assertEquals("name", inner::class.java.getMethod("getName").invoke(inner))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun repeatedNestedTypes() {
|
||||
val cc = ClassCarpenter()
|
||||
val nestedClass = cc.build (ClassSchema("nestedType",
|
||||
mapOf("name" to NonNullableField(String::class.java))))
|
||||
|
||||
data class outer(val a: Any, val b: Any)
|
||||
|
||||
val classInstance = outer (
|
||||
nestedClass.constructors.first().newInstance("foo"),
|
||||
nestedClass.constructors.first().newInstance("bar"))
|
||||
|
||||
val serialisedBytes = TestSerializationOutput(VERBOSE, sf1).serialize(classInstance)
|
||||
val deserializedObj = DeserializationInput(sf2).deserialize(serialisedBytes)
|
||||
|
||||
|
@ -23,23 +23,23 @@ class DeserializeSimpleTypesTests {
|
||||
fun testChar() {
|
||||
data class C(val c: Char)
|
||||
|
||||
var deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('c')))
|
||||
var deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('c')))
|
||||
assertEquals('c', deserializedC.c)
|
||||
|
||||
// CYRILLIC CAPITAL LETTER YU (U+042E)
|
||||
deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('Ю')))
|
||||
deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('Ю')))
|
||||
assertEquals('Ю', deserializedC.c)
|
||||
|
||||
// ARABIC LETTER FEH WITH DOT BELOW (U+06A3)
|
||||
deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('ڣ')))
|
||||
deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('ڣ')))
|
||||
assertEquals('ڣ', deserializedC.c)
|
||||
|
||||
// ARABIC LETTER DAD WITH DOT BELOW (U+06FB)
|
||||
deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('ۻ')))
|
||||
deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('ۻ')))
|
||||
assertEquals('ۻ', deserializedC.c)
|
||||
|
||||
// BENGALI LETTER AA (U+0986)
|
||||
deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('আ')))
|
||||
deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('আ')))
|
||||
assertEquals('আ', deserializedC.c)
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ class DeserializeSimpleTypesTests {
|
||||
data class C(val c: Character)
|
||||
|
||||
val c = C(Character('c'))
|
||||
val serialisedC = SerializationOutput(sf).serialize(c)
|
||||
val deserializedC = DeserializationInput(sf).deserialize(serialisedC)
|
||||
val serialisedC = SerializationOutput(sf1).serialize(c)
|
||||
val deserializedC = DeserializationInput(sf1).deserialize(serialisedC)
|
||||
|
||||
assertEquals(c.c, deserializedC.c)
|
||||
}
|
||||
@ -60,8 +60,8 @@ class DeserializeSimpleTypesTests {
|
||||
data class C(val c: Char?)
|
||||
|
||||
val c = C(null)
|
||||
val serialisedC = SerializationOutput(sf).serialize(c)
|
||||
val deserializedC = DeserializationInput(sf).deserialize(serialisedC)
|
||||
val serialisedC = SerializationOutput(sf1).serialize(c)
|
||||
val deserializedC = DeserializationInput(sf1).deserialize(serialisedC)
|
||||
|
||||
assertEquals(c.c, deserializedC.c)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user