mirror of
https://github.com/corda/corda.git
synced 2025-05-03 17:23:03 +00:00
Code tidy up, auto reformat, IntelliJ suggestions
This commit is contained in:
parent
32ea59d085
commit
afdf5fb717
@ -27,9 +27,9 @@ import java.util.*
|
|||||||
* transformation rules we create a mapping between those values and the values that exist on the
|
* transformation rules we create a mapping between those values and the values that exist on the
|
||||||
* current class
|
* current class
|
||||||
*
|
*
|
||||||
* @property clazz The enum as it exists now, not as it did when it was serialized (either in the past
|
* @property type The enum as it exists now, not as it did when it was serialized (either in the past
|
||||||
* or future).
|
* or future).
|
||||||
* @property factory the [SerializerFactory] that is building this serialization object.
|
* @param factory the [SerializerFactory] that is building this serialization object.
|
||||||
* @property conversions A mapping between all potential enum constants that could've been assigned to
|
* @property conversions A mapping between all potential enum constants that could've been assigned to
|
||||||
* an instance of the enum as it existed at time of serialisation and those that exist now
|
* an instance of the enum as it existed at time of serialisation and those that exist now
|
||||||
* @property ordinals Convenience mapping of constant to ordinality
|
* @property ordinals Convenience mapping of constant to ordinality
|
||||||
@ -57,7 +57,7 @@ class EnumEvolutionSerializer(
|
|||||||
* received AMQP header
|
* received AMQP header
|
||||||
* @param new The Serializer object we built based on the current state of the enum class on our classpath
|
* @param new The Serializer object we built based on the current state of the enum class on our classpath
|
||||||
* @param factory the [SerializerFactory] that is building this serialization object.
|
* @param factory the [SerializerFactory] that is building this serialization object.
|
||||||
* @param transformsFromBlob the transforms attached to the class in the AMQP header, i.e. the transforms
|
* @param schemas the transforms attached to the class in the AMQP header, i.e. the transforms
|
||||||
* known at serialization time
|
* known at serialization time
|
||||||
*/
|
*/
|
||||||
fun make(old: RestrictedType,
|
fun make(old: RestrictedType,
|
||||||
|
@ -32,17 +32,16 @@ sealed class PropertySerializer(val name: String, val readMethod: Method?, val r
|
|||||||
return if (isInterface) listOf(SerializerFactory.nameForType(resolvedType)) else emptyList()
|
return if (isInterface) listOf(SerializerFactory.nameForType(resolvedType)) else emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDefault(): String? {
|
private fun generateDefault(): String? =
|
||||||
if (isJVMPrimitive) {
|
if (isJVMPrimitive) {
|
||||||
return when (resolvedType) {
|
when (resolvedType) {
|
||||||
java.lang.Boolean.TYPE -> "false"
|
java.lang.Boolean.TYPE -> "false"
|
||||||
java.lang.Character.TYPE -> "�"
|
java.lang.Character.TYPE -> "�"
|
||||||
else -> "0"
|
else -> "0"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateMandatory(): Boolean {
|
private fun generateMandatory(): Boolean {
|
||||||
return isJVMPrimitive || readMethod?.returnsNullable() == false
|
return isJVMPrimitive || readMethod?.returnsNullable() == false
|
||||||
|
@ -28,7 +28,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
Unknown({ UnknownTransform() }) {
|
Unknown({ UnknownTransform() }) {
|
||||||
override fun getDescriptor(): Any = DESCRIPTOR
|
override fun getDescriptor(): Any = DESCRIPTOR
|
||||||
override fun getDescribed(): Any = ordinal
|
override fun getDescribed(): Any = ordinal
|
||||||
override fun validate(l : List<Transform>, constants: Map<String, Int>) { }
|
override fun validate(list: List<Transform>, constants: Map<String, Int>) {}
|
||||||
},
|
},
|
||||||
EnumDefault({ a -> EnumDefaultSchemaTransform((a as CordaSerializationTransformEnumDefault).old, a.new) }) {
|
EnumDefault({ a -> EnumDefaultSchemaTransform((a as CordaSerializationTransformEnumDefault).old, a.new) }) {
|
||||||
override fun getDescriptor(): Any = DESCRIPTOR
|
override fun getDescriptor(): Any = DESCRIPTOR
|
||||||
@ -39,11 +39,11 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
* that should be used when we cannot use the new value) must refer to a constant that exists in the
|
* that should be used when we cannot use the new value) must refer to a constant that exists in the
|
||||||
* enum class as it exists now and it cannot refer to itself.
|
* enum class as it exists now and it cannot refer to itself.
|
||||||
*
|
*
|
||||||
* @param l The list of transforms representing new constants and the mapping from that constant to an
|
* @param list The list of transforms representing new constants and the mapping from that constant to an
|
||||||
* existing value
|
* existing value
|
||||||
* @param constants The list of enum constants on the type the transforms are being applied to
|
* @param constants The list of enum constants on the type the transforms are being applied to
|
||||||
*/
|
*/
|
||||||
override fun validate(list : List<Transform>, constants: Map<String, Int>) {
|
override fun validate(list: List<Transform>, constants: Map<String, Int>) {
|
||||||
uncheckedCast<List<Transform>, List<EnumDefaultSchemaTransform>>(list).forEach {
|
uncheckedCast<List<Transform>, List<EnumDefaultSchemaTransform>>(list).forEach {
|
||||||
if (!constants.contains(it.new)) {
|
if (!constants.contains(it.new)) {
|
||||||
throw NotSerializableException("Unknown enum constant ${it.new}")
|
throw NotSerializableException("Unknown enum constant ${it.new}")
|
||||||
@ -62,7 +62,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
if (constants[it.old]!! >= constants[it.new]!!) {
|
if (constants[it.old]!! >= constants[it.new]!!) {
|
||||||
throw NotSerializableException(
|
throw NotSerializableException(
|
||||||
"Enum extensions must default to older constants. ${it.new}[${constants[it.new]}] " +
|
"Enum extensions must default to older constants. ${it.new}[${constants[it.new]}] " +
|
||||||
"defaults to ${it.old}[${constants[it.old]}] which is greater")
|
"defaults to ${it.old}[${constants[it.old]}] which is greater")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,15 +76,16 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
* that is a constant is renamed to something that used to exist in the enum. We do this for both
|
* that is a constant is renamed to something that used to exist in the enum. We do this for both
|
||||||
* the same constant (i.e. C -> D -> C) and multiple constants (C->D, B->C)
|
* the same constant (i.e. C -> D -> C) and multiple constants (C->D, B->C)
|
||||||
*
|
*
|
||||||
* @param l The list of transforms representing the renamed constants and the mapping between their new
|
* @param list The list of transforms representing the renamed constants and the mapping between their new
|
||||||
* and old values
|
* and old values
|
||||||
* @param constants The list of enum constants on the type the transforms are being applied to
|
* @param constants The list of enum constants on the type the transforms are being applied to
|
||||||
*/
|
*/
|
||||||
override fun validate(l : List<Transform>, constants: Map<String, Int>) {
|
override fun validate(list: List<Transform>, constants: Map<String, Int>) {
|
||||||
object : Any() {
|
object : Any() {
|
||||||
val from : MutableSet<String> = mutableSetOf()
|
val from: MutableSet<String> = mutableSetOf()
|
||||||
val to : MutableSet<String> = mutableSetOf() }.apply {
|
val to: MutableSet<String> = mutableSetOf()
|
||||||
@Suppress("UNCHECKED_CAST") (l as List<RenameSchemaTransform>).forEach { rename ->
|
}.apply {
|
||||||
|
@Suppress("UNCHECKED_CAST") (list as List<RenameSchemaTransform>).forEach { rename ->
|
||||||
if (rename.to in this.to || rename.from in this.from) {
|
if (rename.to in this.to || rename.from in this.from) {
|
||||||
throw NotSerializableException("Cyclic renames are not allowed (${rename.to})")
|
throw NotSerializableException("Cyclic renames are not allowed (${rename.to})")
|
||||||
}
|
}
|
||||||
@ -104,7 +105,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
//}
|
//}
|
||||||
;
|
;
|
||||||
|
|
||||||
abstract fun validate(l: List<Transform>, constants: Map<String, Int>)
|
abstract fun validate(list: List<Transform>, constants: Map<String, Int>)
|
||||||
|
|
||||||
companion object : DescribedTypeConstructor<TransformTypes> {
|
companion object : DescribedTypeConstructor<TransformTypes> {
|
||||||
val DESCRIPTOR = AMQPDescriptorRegistry.TRANSFORM_ELEMENT_KEY.amqpDescriptor
|
val DESCRIPTOR = AMQPDescriptorRegistry.TRANSFORM_ELEMENT_KEY.amqpDescriptor
|
||||||
|
@ -92,7 +92,7 @@ class UnknownTestTransform(val a: Int, val b: Int, val c: Int) : Transform() {
|
|||||||
companion object : DescribedTypeConstructor<UnknownTestTransform> {
|
companion object : DescribedTypeConstructor<UnknownTestTransform> {
|
||||||
val typeName = "UnknownTest"
|
val typeName = "UnknownTest"
|
||||||
|
|
||||||
override fun newInstance(obj: Any?) : UnknownTestTransform {
|
override fun newInstance(obj: Any?): UnknownTestTransform {
|
||||||
val described = obj as List<*>
|
val described = obj as List<*>
|
||||||
return UnknownTestTransform(described[1] as Int, described[2] as Int, described[3] as Int)
|
return UnknownTestTransform(described[1] as Int, described[2] as Int, described[3] as Int)
|
||||||
}
|
}
|
||||||
@ -201,41 +201,41 @@ data class TransformsSchema(val types: Map<String, EnumMap<TransformTypes, Mutab
|
|||||||
* class loader and this dictates which classes we can and cannot see
|
* class loader and this dictates which classes we can and cannot see
|
||||||
*/
|
*/
|
||||||
fun get(name: String, sf: SerializerFactory) = sf.transformsCache.computeIfAbsent(name) {
|
fun get(name: String, sf: SerializerFactory) = sf.transformsCache.computeIfAbsent(name) {
|
||||||
val transforms = EnumMap<TransformTypes, MutableList<Transform>>(TransformTypes::class.java)
|
val transforms = EnumMap<TransformTypes, MutableList<Transform>>(TransformTypes::class.java)
|
||||||
try {
|
try {
|
||||||
val clazz = sf.classloader.loadClass(name)
|
val clazz = sf.classloader.loadClass(name)
|
||||||
|
|
||||||
supportedTransforms.forEach { transform ->
|
supportedTransforms.forEach { transform ->
|
||||||
clazz.getAnnotation(transform.type)?.let { list ->
|
clazz.getAnnotation(transform.type)?.let { list ->
|
||||||
transform.getAnnotations(list).forEach { annotation ->
|
transform.getAnnotations(list).forEach { annotation ->
|
||||||
val t = transform.enum.build(annotation)
|
val t = transform.enum.build(annotation)
|
||||||
|
|
||||||
// we're explicitly rejecting repeated annotations, whilst it's fine and we'd just
|
// we're explicitly rejecting repeated annotations, whilst it's fine and we'd just
|
||||||
// ignore them it feels like a good thing to alert the user to since this is
|
// ignore them it feels like a good thing to alert the user to since this is
|
||||||
// more than likely a typo in their code so best make it an actual error
|
// more than likely a typo in their code so best make it an actual error
|
||||||
if (transforms.computeIfAbsent(transform.enum) { mutableListOf() }
|
if (transforms.computeIfAbsent(transform.enum) { mutableListOf() }
|
||||||
.filter { t == it }
|
.filter { t == it }
|
||||||
.isNotEmpty()) {
|
.isNotEmpty()) {
|
||||||
throw NotSerializableException(
|
throw NotSerializableException(
|
||||||
"Repeated unique transformation annotation of type ${t.name}")
|
"Repeated unique transformation annotation of type ${t.name}")
|
||||||
}
|
|
||||||
|
|
||||||
transforms[transform.enum]!!.add(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transform.enum.validate(
|
transforms[transform.enum]!!.add(t)
|
||||||
transforms[transform.enum] ?: emptyList(),
|
|
||||||
clazz.enumConstants.mapIndexed { i, s -> Pair(s.toString(), i) }.toMap())
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (_: ClassNotFoundException) {
|
|
||||||
// if we can't load the class we'll end up caching an empty list which is fine as that
|
|
||||||
// list, on lookup, won't be included in the schema because it's empty
|
|
||||||
}
|
|
||||||
|
|
||||||
transforms
|
transform.enum.validate(
|
||||||
|
transforms[transform.enum] ?: emptyList(),
|
||||||
|
clazz.enumConstants.mapIndexed { i, s -> Pair(s.toString(), i) }.toMap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: ClassNotFoundException) {
|
||||||
|
// if we can't load the class we'll end up caching an empty list which is fine as that
|
||||||
|
// list, on lookup, won't be included in the schema because it's empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transforms
|
||||||
|
}
|
||||||
|
|
||||||
private fun getAndAdd(
|
private fun getAndAdd(
|
||||||
type: String,
|
type: String,
|
||||||
sf: SerializerFactory,
|
sf: SerializerFactory,
|
||||||
|
@ -6,7 +6,6 @@ import org.assertj.core.api.Assertions
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun noAnnotation() {
|
fun noAnnotation() {
|
||||||
data class C (val n: NotAnnotated)
|
data class C(val n: NotAnnotated)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(NotAnnotated.A))
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(NotAnnotated.A))
|
||||||
@ -63,7 +62,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun missingDefaults() {
|
fun missingDefaults() {
|
||||||
data class C (val m: MissingDefaults)
|
data class C(val m: MissingDefaults)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(MissingDefaults.A))
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(MissingDefaults.A))
|
||||||
@ -74,7 +73,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun missingRenames() {
|
fun missingRenames() {
|
||||||
data class C (val m: MissingRenames)
|
data class C(val m: MissingRenames)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(MissingRenames.A))
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(MissingRenames.A))
|
||||||
@ -86,7 +85,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun defaultAnnotationIsAddedToEnvelope() {
|
fun defaultAnnotationIsAddedToEnvelope() {
|
||||||
data class C (val annotatedEnum: AnnotatedEnumOnce)
|
data class C(val annotatedEnum: AnnotatedEnumOnce)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(AnnotatedEnumOnce.D))
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(AnnotatedEnumOnce.D))
|
||||||
@ -94,45 +93,45 @@ class EnumEvolvabilityTests {
|
|||||||
// only the enum is decorated so schema sizes should be different (2 objects, only one evolved)
|
// only the enum is decorated so schema sizes should be different (2 objects, only one evolved)
|
||||||
assertEquals(2, bAndS.schema.types.size)
|
assertEquals(2, bAndS.schema.types.size)
|
||||||
assertEquals(1, bAndS.transformsSchema.types.size)
|
assertEquals(1, bAndS.transformsSchema.types.size)
|
||||||
assertEquals (AnnotatedEnumOnce::class.java.name, bAndS.transformsSchema.types.keys.first())
|
assertEquals(AnnotatedEnumOnce::class.java.name, bAndS.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val schema = bAndS.transformsSchema.types.values.first()
|
val schema = bAndS.transformsSchema.types.values.first()
|
||||||
|
|
||||||
assertEquals(1, schema.size)
|
assertEquals(1, schema.size)
|
||||||
assertTrue (schema.keys.contains(TransformTypes.EnumDefault))
|
assertTrue(schema.keys.contains(TransformTypes.EnumDefault))
|
||||||
assertEquals (1, schema[TransformTypes.EnumDefault]!!.size)
|
assertEquals(1, schema[TransformTypes.EnumDefault]!!.size)
|
||||||
assertTrue (schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
assertTrue(schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
||||||
assertEquals ("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
assertEquals("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
||||||
assertEquals ("A", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
assertEquals("A", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun doubleDefaultAnnotationIsAddedToEnvelope() {
|
fun doubleDefaultAnnotationIsAddedToEnvelope() {
|
||||||
data class C (val annotatedEnum: AnnotatedEnumTwice)
|
data class C(val annotatedEnum: AnnotatedEnumTwice)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(AnnotatedEnumTwice.E))
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(C(AnnotatedEnumTwice.E))
|
||||||
|
|
||||||
assertEquals(2, bAndS.schema.types.size)
|
assertEquals(2, bAndS.schema.types.size)
|
||||||
assertEquals(1, bAndS.transformsSchema.types.size)
|
assertEquals(1, bAndS.transformsSchema.types.size)
|
||||||
assertEquals (AnnotatedEnumTwice::class.java.name, bAndS.transformsSchema.types.keys.first())
|
assertEquals(AnnotatedEnumTwice::class.java.name, bAndS.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val schema = bAndS.transformsSchema.types.values.first()
|
val schema = bAndS.transformsSchema.types.values.first()
|
||||||
|
|
||||||
assertEquals(1, schema.size)
|
assertEquals(1, schema.size)
|
||||||
assertTrue (schema.keys.contains(TransformTypes.EnumDefault))
|
assertTrue(schema.keys.contains(TransformTypes.EnumDefault))
|
||||||
assertEquals (2, schema[TransformTypes.EnumDefault]!!.size)
|
assertEquals(2, schema[TransformTypes.EnumDefault]!!.size)
|
||||||
assertTrue (schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
assertTrue(schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
||||||
assertEquals ("E", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
assertEquals("E", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
||||||
assertEquals ("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
assertEquals("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
||||||
assertTrue (schema[TransformTypes.EnumDefault]!![1] is EnumDefaultSchemaTransform)
|
assertTrue(schema[TransformTypes.EnumDefault]!![1] is EnumDefaultSchemaTransform)
|
||||||
assertEquals ("D", (schema[TransformTypes.EnumDefault]!![1] as EnumDefaultSchemaTransform).new)
|
assertEquals("D", (schema[TransformTypes.EnumDefault]!![1] as EnumDefaultSchemaTransform).new)
|
||||||
assertEquals ("A", (schema[TransformTypes.EnumDefault]!![1] as EnumDefaultSchemaTransform).old)
|
assertEquals("A", (schema[TransformTypes.EnumDefault]!![1] as EnumDefaultSchemaTransform).old)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun defaultAnnotationIsAddedToEnvelopeAndDeserialised() {
|
fun defaultAnnotationIsAddedToEnvelopeAndDeserialised() {
|
||||||
data class C (val annotatedEnum: AnnotatedEnumOnce)
|
data class C(val annotatedEnum: AnnotatedEnumOnce)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val sb = TestSerializationOutput(VERBOSE, sf).serialize(C(AnnotatedEnumOnce.D))
|
val sb = TestSerializationOutput(VERBOSE, sf).serialize(C(AnnotatedEnumOnce.D))
|
||||||
@ -152,11 +151,11 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
val schema = transforms[eName]
|
val schema = transforms[eName]
|
||||||
|
|
||||||
assertTrue (schema!!.keys.contains(TransformTypes.EnumDefault))
|
assertTrue(schema!!.keys.contains(TransformTypes.EnumDefault))
|
||||||
assertEquals (1, schema[TransformTypes.EnumDefault]!!.size)
|
assertEquals(1, schema[TransformTypes.EnumDefault]!!.size)
|
||||||
assertTrue (schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
assertTrue(schema[TransformTypes.EnumDefault]!![0] is EnumDefaultSchemaTransform)
|
||||||
assertEquals ("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
assertEquals("D", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).new)
|
||||||
assertEquals ("A", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
assertEquals("A", (schema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -174,9 +173,9 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
val transforms = db.envelope.transformsSchema.types
|
val transforms = db.envelope.transformsSchema.types
|
||||||
|
|
||||||
assertTrue (transforms.contains(AnnotatedEnumTwice::class.java.name))
|
assertTrue(transforms.contains(AnnotatedEnumTwice::class.java.name))
|
||||||
assertTrue (transforms[AnnotatedEnumTwice::class.java.name]!!.contains(TransformTypes.EnumDefault))
|
assertTrue(transforms[AnnotatedEnumTwice::class.java.name]!!.contains(TransformTypes.EnumDefault))
|
||||||
assertEquals (2, transforms[AnnotatedEnumTwice::class.java.name]!![TransformTypes.EnumDefault]!!.size)
|
assertEquals(2, transforms[AnnotatedEnumTwice::class.java.name]!![TransformTypes.EnumDefault]!!.size)
|
||||||
|
|
||||||
val enumDefaults = transforms[AnnotatedEnumTwice::class.java.name]!![TransformTypes.EnumDefault]!!
|
val enumDefaults = transforms[AnnotatedEnumTwice::class.java.name]!![TransformTypes.EnumDefault]!!
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun renameAnnotationIsAdded() {
|
fun renameAnnotationIsAdded() {
|
||||||
data class C (val annotatedEnum: RenameEnumOnce)
|
data class C(val annotatedEnum: RenameEnumOnce)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(2, bAndS.schema.types.size)
|
assertEquals(2, bAndS.schema.types.size)
|
||||||
assertEquals(1, bAndS.transformsSchema.types.size)
|
assertEquals(1, bAndS.transformsSchema.types.size)
|
||||||
assertEquals (RenameEnumOnce::class.java.name, bAndS.transformsSchema.types.keys.first())
|
assertEquals(RenameEnumOnce::class.java.name, bAndS.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val serialisedSchema = bAndS.transformsSchema.types[RenameEnumOnce::class.java.name]!!
|
val serialisedSchema = bAndS.transformsSchema.types[RenameEnumOnce::class.java.name]!!
|
||||||
|
|
||||||
@ -212,7 +211,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(2, cAndS.envelope.schema.types.size)
|
assertEquals(2, cAndS.envelope.schema.types.size)
|
||||||
assertEquals(1, cAndS.envelope.transformsSchema.types.size)
|
assertEquals(1, cAndS.envelope.transformsSchema.types.size)
|
||||||
assertEquals (RenameEnumOnce::class.java.name, cAndS.envelope.transformsSchema.types.keys.first())
|
assertEquals(RenameEnumOnce::class.java.name, cAndS.envelope.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val deserialisedSchema = cAndS.envelope.transformsSchema.types[RenameEnumOnce::class.java.name]!!
|
val deserialisedSchema = cAndS.envelope.transformsSchema.types[RenameEnumOnce::class.java.name]!!
|
||||||
|
|
||||||
@ -232,7 +231,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun doubleRenameAnnotationIsAdded() {
|
fun doubleRenameAnnotationIsAdded() {
|
||||||
data class C (val annotatedEnum: RenameEnumTwice)
|
data class C(val annotatedEnum: RenameEnumTwice)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
@ -241,7 +240,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(2, bAndS.schema.types.size)
|
assertEquals(2, bAndS.schema.types.size)
|
||||||
assertEquals(1, bAndS.transformsSchema.types.size)
|
assertEquals(1, bAndS.transformsSchema.types.size)
|
||||||
assertEquals (RenameEnumTwice::class.java.name, bAndS.transformsSchema.types.keys.first())
|
assertEquals(RenameEnumTwice::class.java.name, bAndS.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val serialisedSchema = bAndS.transformsSchema.types[RenameEnumTwice::class.java.name]!!
|
val serialisedSchema = bAndS.transformsSchema.types[RenameEnumTwice::class.java.name]!!
|
||||||
|
|
||||||
@ -258,7 +257,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(2, cAndS.envelope.schema.types.size)
|
assertEquals(2, cAndS.envelope.schema.types.size)
|
||||||
assertEquals(1, cAndS.envelope.transformsSchema.types.size)
|
assertEquals(1, cAndS.envelope.transformsSchema.types.size)
|
||||||
assertEquals (RenameEnumTwice::class.java.name, cAndS.envelope.transformsSchema.types.keys.first())
|
assertEquals(RenameEnumTwice::class.java.name, cAndS.envelope.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val deserialisedSchema = cAndS.envelope.transformsSchema.types[RenameEnumTwice::class.java.name]!!
|
val deserialisedSchema = cAndS.envelope.transformsSchema.types[RenameEnumTwice::class.java.name]!!
|
||||||
|
|
||||||
@ -271,15 +270,15 @@ class EnumEvolvabilityTests {
|
|||||||
assertEquals("F", (deserialisedSchema[TransformTypes.Rename]!![1] as RenameSchemaTransform).to)
|
assertEquals("F", (deserialisedSchema[TransformTypes.Rename]!![1] as RenameSchemaTransform).to)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformRename(from="A", to="X")
|
@CordaSerializationTransformRename(from = "A", to = "X")
|
||||||
@CordaSerializationTransformEnumDefault(old = "X", new="E")
|
@CordaSerializationTransformEnumDefault(old = "X", new = "E")
|
||||||
enum class RenameAndExtendEnum {
|
enum class RenameAndExtendEnum {
|
||||||
X, B, C, D, E
|
X, B, C, D, E
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun bothAnnotationTypes() {
|
fun bothAnnotationTypes() {
|
||||||
data class C (val annotatedEnum: RenameAndExtendEnum)
|
data class C(val annotatedEnum: RenameAndExtendEnum)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
@ -288,15 +287,15 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(2, bAndS.schema.types.size)
|
assertEquals(2, bAndS.schema.types.size)
|
||||||
assertEquals(1, bAndS.transformsSchema.types.size)
|
assertEquals(1, bAndS.transformsSchema.types.size)
|
||||||
assertEquals (RenameAndExtendEnum::class.java.name, bAndS.transformsSchema.types.keys.first())
|
assertEquals(RenameAndExtendEnum::class.java.name, bAndS.transformsSchema.types.keys.first())
|
||||||
|
|
||||||
val serialisedSchema = bAndS.transformsSchema.types[RenameAndExtendEnum::class.java.name]!!
|
val serialisedSchema = bAndS.transformsSchema.types[RenameAndExtendEnum::class.java.name]!!
|
||||||
|
|
||||||
// This time there should be two distinct transform types (all previous tests have had only
|
// This time there should be two distinct transform types (all previous tests have had only
|
||||||
// a single type
|
// a single type
|
||||||
assertEquals(2, serialisedSchema.size)
|
assertEquals(2, serialisedSchema.size)
|
||||||
assertTrue (serialisedSchema.containsKey(TransformTypes.Rename))
|
assertTrue(serialisedSchema.containsKey(TransformTypes.Rename))
|
||||||
assertTrue (serialisedSchema.containsKey(TransformTypes.EnumDefault))
|
assertTrue(serialisedSchema.containsKey(TransformTypes.EnumDefault))
|
||||||
|
|
||||||
assertEquals(1, serialisedSchema[TransformTypes.Rename]!!.size)
|
assertEquals(1, serialisedSchema[TransformTypes.Rename]!!.size)
|
||||||
assertEquals("A", (serialisedSchema[TransformTypes.Rename]!![0] as RenameSchemaTransform).from)
|
assertEquals("A", (serialisedSchema[TransformTypes.Rename]!![0] as RenameSchemaTransform).from)
|
||||||
@ -307,7 +306,7 @@ class EnumEvolvabilityTests {
|
|||||||
assertEquals("X", (serialisedSchema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
assertEquals("X", (serialisedSchema[TransformTypes.EnumDefault]!![0] as EnumDefaultSchemaTransform).old)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefaults (
|
@CordaSerializationTransformEnumDefaults(
|
||||||
CordaSerializationTransformEnumDefault("D", "A"),
|
CordaSerializationTransformEnumDefault("D", "A"),
|
||||||
CordaSerializationTransformEnumDefault("D", "A"))
|
CordaSerializationTransformEnumDefault("D", "A"))
|
||||||
enum class RepeatedAnnotation {
|
enum class RepeatedAnnotation {
|
||||||
@ -316,7 +315,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun repeatedAnnotation() {
|
fun repeatedAnnotation() {
|
||||||
data class C (val a: RepeatedAnnotation)
|
data class C(val a: RepeatedAnnotation)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
@ -330,40 +329,40 @@ class EnumEvolvabilityTests {
|
|||||||
A, B, C, D
|
A, B, C, D
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefaults (
|
@CordaSerializationTransformEnumDefaults(
|
||||||
CordaSerializationTransformEnumDefault("D", "A"),
|
CordaSerializationTransformEnumDefault("D", "A"),
|
||||||
CordaSerializationTransformEnumDefault("E", "A"))
|
CordaSerializationTransformEnumDefault("E", "A"))
|
||||||
enum class E2 {
|
enum class E2 {
|
||||||
A, B, C, D, E
|
A, B, C, D, E
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefaults (CordaSerializationTransformEnumDefault("D", "A"))
|
@CordaSerializationTransformEnumDefaults(CordaSerializationTransformEnumDefault("D", "A"))
|
||||||
enum class E3 {
|
enum class E3 {
|
||||||
A, B, C, D
|
A, B, C, D
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun multiEnums() {
|
fun multiEnums() {
|
||||||
data class A (val a: E1, val b: E2)
|
data class A(val a: E1, val b: E2)
|
||||||
data class B (val a: E3, val b: A, val c: E1)
|
data class B(val a: E3, val b: A, val c: E1)
|
||||||
data class C (val a: B, val b: E2, val c: E3)
|
data class C(val a: B, val b: E2, val c: E3)
|
||||||
|
|
||||||
val c = C(B(E3.A,A(E1.A,E2.B),E1.C),E2.B,E3.A)
|
val c = C(B(E3.A, A(E1.A, E2.B), E1.C), E2.B, E3.A)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
// Serialise the object
|
// Serialise the object
|
||||||
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(c)
|
val bAndS = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(c)
|
||||||
|
|
||||||
println (bAndS.transformsSchema)
|
println(bAndS.transformsSchema)
|
||||||
|
|
||||||
// we have six types and three of those, the enums, should have transforms
|
// we have six types and three of those, the enums, should have transforms
|
||||||
assertEquals(6, bAndS.schema.types.size)
|
assertEquals(6, bAndS.schema.types.size)
|
||||||
assertEquals(3, bAndS.transformsSchema.types.size)
|
assertEquals(3, bAndS.transformsSchema.types.size)
|
||||||
|
|
||||||
assertTrue (E1::class.java.name in bAndS.transformsSchema.types)
|
assertTrue(E1::class.java.name in bAndS.transformsSchema.types)
|
||||||
assertTrue (E2::class.java.name in bAndS.transformsSchema.types)
|
assertTrue(E2::class.java.name in bAndS.transformsSchema.types)
|
||||||
assertTrue (E3::class.java.name in bAndS.transformsSchema.types)
|
assertTrue(E3::class.java.name in bAndS.transformsSchema.types)
|
||||||
|
|
||||||
val e1S = bAndS.transformsSchema.types[E1::class.java.name]!!
|
val e1S = bAndS.transformsSchema.types[E1::class.java.name]!!
|
||||||
val e2S = bAndS.transformsSchema.types[E2::class.java.name]!!
|
val e2S = bAndS.transformsSchema.types[E2::class.java.name]!!
|
||||||
@ -404,7 +403,7 @@ class EnumEvolvabilityTests {
|
|||||||
assertTrue(sf.transformsCache.containsKey(C2::class.java.name))
|
assertTrue(sf.transformsCache.containsKey(C2::class.java.name))
|
||||||
assertTrue(sf.transformsCache.containsKey(AnnotatedEnumOnce::class.java.name))
|
assertTrue(sf.transformsCache.containsKey(AnnotatedEnumOnce::class.java.name))
|
||||||
|
|
||||||
assertEquals (sb1.transformsSchema.types[AnnotatedEnumOnce::class.java.name],
|
assertEquals(sb1.transformsSchema.types[AnnotatedEnumOnce::class.java.name],
|
||||||
sb2.transformsSchema.types[AnnotatedEnumOnce::class.java.name])
|
sb2.transformsSchema.types[AnnotatedEnumOnce::class.java.name])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +446,7 @@ class EnumEvolvabilityTests {
|
|||||||
//
|
//
|
||||||
// And we're not at 3. However, we ban this rename
|
// And we're not at 3. However, we ban this rename
|
||||||
//
|
//
|
||||||
@CordaSerializationTransformRenames (
|
@CordaSerializationTransformRenames(
|
||||||
CordaSerializationTransformRename("D", "C"),
|
CordaSerializationTransformRename("D", "C"),
|
||||||
CordaSerializationTransformRename("C", "D")
|
CordaSerializationTransformRename("C", "D")
|
||||||
)
|
)
|
||||||
@ -455,7 +454,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rejectCyclicRename() {
|
fun rejectCyclicRename() {
|
||||||
data class C (val e: RejectCyclicRename)
|
data class C(val e: RejectCyclicRename)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
@ -468,7 +467,7 @@ class EnumEvolvabilityTests {
|
|||||||
// unserailzble. However, in this case, it isn't a struct cycle, rather one element
|
// unserailzble. However, in this case, it isn't a struct cycle, rather one element
|
||||||
// is renamed to match what a different element used to be called
|
// is renamed to match what a different element used to be called
|
||||||
//
|
//
|
||||||
@CordaSerializationTransformRenames (
|
@CordaSerializationTransformRenames(
|
||||||
CordaSerializationTransformRename(from = "B", to = "C"),
|
CordaSerializationTransformRename(from = "B", to = "C"),
|
||||||
CordaSerializationTransformRename(from = "C", to = "D")
|
CordaSerializationTransformRename(from = "C", to = "D")
|
||||||
)
|
)
|
||||||
@ -476,7 +475,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rejectCyclicRenameAlt() {
|
fun rejectCyclicRenameAlt() {
|
||||||
data class C (val e: RejectCyclicRenameAlt)
|
data class C(val e: RejectCyclicRenameAlt)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
@ -484,7 +483,7 @@ class EnumEvolvabilityTests {
|
|||||||
}.isInstanceOf(NotSerializableException::class.java)
|
}.isInstanceOf(NotSerializableException::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformRenames (
|
@CordaSerializationTransformRenames(
|
||||||
CordaSerializationTransformRename("G", "C"),
|
CordaSerializationTransformRename("G", "C"),
|
||||||
CordaSerializationTransformRename("F", "G"),
|
CordaSerializationTransformRename("F", "G"),
|
||||||
CordaSerializationTransformRename("E", "F"),
|
CordaSerializationTransformRename("E", "F"),
|
||||||
@ -495,7 +494,7 @@ class EnumEvolvabilityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rejectCyclicRenameRedux() {
|
fun rejectCyclicRenameRedux() {
|
||||||
data class C (val e: RejectCyclicRenameRedux)
|
data class C(val e: RejectCyclicRenameRedux)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
@ -503,12 +502,12 @@ class EnumEvolvabilityTests {
|
|||||||
}.isInstanceOf(NotSerializableException::class.java)
|
}.isInstanceOf(NotSerializableException::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefault (new = "D", old = "X")
|
@CordaSerializationTransformEnumDefault(new = "D", old = "X")
|
||||||
enum class RejectBadDefault { A, B, C, D }
|
enum class RejectBadDefault { A, B, C, D }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rejectBadDefault() {
|
fun rejectBadDefault() {
|
||||||
data class C (val e: RejectBadDefault)
|
data class C(val e: RejectBadDefault)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
@ -516,12 +515,12 @@ class EnumEvolvabilityTests {
|
|||||||
}.isInstanceOf(NotSerializableException::class.java)
|
}.isInstanceOf(NotSerializableException::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefault (new = "D", old = "D")
|
@CordaSerializationTransformEnumDefault(new = "D", old = "D")
|
||||||
enum class RejectBadDefaultToSelf { A, B, C, D }
|
enum class RejectBadDefaultToSelf { A, B, C, D }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rejectBadDefaultToSelf() {
|
fun rejectBadDefaultToSelf() {
|
||||||
data class C (val e: RejectBadDefaultToSelf)
|
data class C(val e: RejectBadDefaultToSelf)
|
||||||
|
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package net.corda.nodeapi.internal.serialization.amqp
|
package net.corda.nodeapi.internal.serialization.amqp
|
||||||
|
|
||||||
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.testing.common.internal.ProjectStructure.projectRootDir
|
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||||
import org.assertj.core.api.Assertions
|
import org.assertj.core.api.Assertions
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
// NOTE: To recreate the test files used by these tests uncomment the original test classes and comment
|
// NOTE: To recreate the test files used by these tests uncomment the original test classes and comment
|
||||||
@ -30,7 +31,7 @@ class EnumEvolveTests {
|
|||||||
val resource = "${javaClass.simpleName}.${testName()}"
|
val resource = "${javaClass.simpleName}.${testName()}"
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
data class C (val e : DeserializeNewerSetToUnknown)
|
data class C(val e: DeserializeNewerSetToUnknown)
|
||||||
|
|
||||||
// Uncomment to re-generate test files
|
// Uncomment to re-generate test files
|
||||||
// File(URI("$localPath/$resource")).writeBytes(
|
// File(URI("$localPath/$resource")).writeBytes(
|
||||||
@ -40,7 +41,7 @@ class EnumEvolveTests {
|
|||||||
|
|
||||||
val obj = DeserializationInput(sf).deserialize(SerializedBytes<C>(File(path.toURI()).readBytes()))
|
val obj = DeserializationInput(sf).deserialize(SerializedBytes<C>(File(path.toURI()).readBytes()))
|
||||||
|
|
||||||
assertEquals (DeserializeNewerSetToUnknown.C, obj.e)
|
assertEquals(DeserializeNewerSetToUnknown.C, obj.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version of the class as it was serialised
|
// Version of the class as it was serialised
|
||||||
@ -78,9 +79,9 @@ class EnumEvolveTests {
|
|||||||
// of the evolution code
|
// of the evolution code
|
||||||
val obj3 = DeserializationInput(sf).deserialize(SerializedBytes<C>(File(path3.toURI()).readBytes()))
|
val obj3 = DeserializationInput(sf).deserialize(SerializedBytes<C>(File(path3.toURI()).readBytes()))
|
||||||
|
|
||||||
assertEquals (DeserializeNewerSetToUnknown2.C, obj1.e)
|
assertEquals(DeserializeNewerSetToUnknown2.C, obj1.e)
|
||||||
assertEquals (DeserializeNewerSetToUnknown2.C, obj2.e)
|
assertEquals(DeserializeNewerSetToUnknown2.C, obj2.e)
|
||||||
assertEquals (DeserializeNewerSetToUnknown2.C, obj3.e)
|
assertEquals(DeserializeNewerSetToUnknown2.C, obj3.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ class EnumEvolveTests {
|
|||||||
data class C(val e: DeserializeWithRename)
|
data class C(val e: DeserializeWithRename)
|
||||||
|
|
||||||
// Uncomment to re-generate test files, needs to be done in three stages
|
// Uncomment to re-generate test files, needs to be done in three stages
|
||||||
val so = SerializationOutput(sf)
|
// val so = SerializationOutput(sf)
|
||||||
// First change
|
// First change
|
||||||
// File(URI("$localPath/$resource.1.AA")).writeBytes(so.serialize(C(DeserializeWithRename.AA)).bytes)
|
// File(URI("$localPath/$resource.1.AA")).writeBytes(so.serialize(C(DeserializeWithRename.AA)).bytes)
|
||||||
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(DeserializeWithRename.B)).bytes)
|
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(DeserializeWithRename.B)).bytes)
|
||||||
@ -271,7 +272,7 @@ class EnumEvolveTests {
|
|||||||
data class C(val e: MultiOperations)
|
data class C(val e: MultiOperations)
|
||||||
|
|
||||||
// Uncomment to re-generate test files, needs to be done in three stages
|
// Uncomment to re-generate test files, needs to be done in three stages
|
||||||
val so = SerializationOutput(sf)
|
// val so = SerializationOutput(sf)
|
||||||
// First change
|
// First change
|
||||||
// File(URI("$localPath/$resource.1.A")).writeBytes(so.serialize(C(MultiOperations.A)).bytes)
|
// File(URI("$localPath/$resource.1.A")).writeBytes(so.serialize(C(MultiOperations.A)).bytes)
|
||||||
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(MultiOperations.B)).bytes)
|
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(MultiOperations.B)).bytes)
|
||||||
@ -345,15 +346,15 @@ class EnumEvolveTests {
|
|||||||
Pair("$resource.5.G", MultiOperations.C))
|
Pair("$resource.5.G", MultiOperations.C))
|
||||||
|
|
||||||
fun load(l: List<Pair<String, MultiOperations>>) = l.map {
|
fun load(l: List<Pair<String, MultiOperations>>) = l.map {
|
||||||
Pair (DeserializationInput(sf).deserialize(SerializedBytes<C>(
|
Pair(DeserializationInput(sf).deserialize(SerializedBytes<C>(
|
||||||
File(EvolvabilityTests::class.java.getResource(it.first).toURI()).readBytes())), it.second)
|
File(EvolvabilityTests::class.java.getResource(it.first).toURI()).readBytes())), it.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
load (stage1Resources).forEach { assertEquals(it.second, it.first.e) }
|
load(stage1Resources).forEach { assertEquals(it.second, it.first.e) }
|
||||||
load (stage2Resources).forEach { assertEquals(it.second, it.first.e) }
|
load(stage2Resources).forEach { assertEquals(it.second, it.first.e) }
|
||||||
load (stage3Resources).forEach { assertEquals(it.second, it.first.e) }
|
load(stage3Resources).forEach { assertEquals(it.second, it.first.e) }
|
||||||
load (stage4Resources).forEach { assertEquals(it.second, it.first.e) }
|
load(stage4Resources).forEach { assertEquals(it.second, it.first.e) }
|
||||||
load (stage5Resources).forEach { assertEquals(it.second, it.first.e) }
|
load(stage5Resources).forEach { assertEquals(it.second, it.first.e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializationTransformEnumDefault(old = "A", new = "F")
|
@CordaSerializationTransformEnumDefault(old = "A", new = "F")
|
||||||
@ -363,7 +364,7 @@ class EnumEvolveTests {
|
|||||||
fun badNewValue() {
|
fun badNewValue() {
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
data class C (val e : BadNewValue)
|
data class C(val e: BadNewValue)
|
||||||
|
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
SerializationOutput(sf).serialize(C(BadNewValue.A))
|
SerializationOutput(sf).serialize(C(BadNewValue.A))
|
||||||
@ -374,13 +375,13 @@ class EnumEvolveTests {
|
|||||||
CordaSerializationTransformEnumDefault(new = "D", old = "E"),
|
CordaSerializationTransformEnumDefault(new = "D", old = "E"),
|
||||||
CordaSerializationTransformEnumDefault(new = "E", old = "A")
|
CordaSerializationTransformEnumDefault(new = "E", old = "A")
|
||||||
)
|
)
|
||||||
enum class OutOfOrder { A, B, C, D, E}
|
enum class OutOfOrder { A, B, C, D, E }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun outOfOrder() {
|
fun outOfOrder() {
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
|
|
||||||
data class C (val e : OutOfOrder)
|
data class C(val e: OutOfOrder)
|
||||||
|
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
SerializationOutput(sf).serialize(C(OutOfOrder.A))
|
SerializationOutput(sf).serialize(C(OutOfOrder.A))
|
||||||
|
@ -2,17 +2,14 @@ package net.corda.nodeapi.internal.serialization.amqp
|
|||||||
|
|
||||||
import net.corda.core.serialization.ClassWhitelist
|
import net.corda.core.serialization.ClassWhitelist
|
||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
import org.junit.Test
|
|
||||||
import java.time.DayOfWeek
|
|
||||||
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.io.NotSerializableException
|
|
||||||
|
|
||||||
import net.corda.core.serialization.SerializedBytes
|
import net.corda.core.serialization.SerializedBytes
|
||||||
import org.assertj.core.api.Assertions
|
import org.assertj.core.api.Assertions
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.io.NotSerializableException
|
||||||
|
import java.time.DayOfWeek
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class EnumTests {
|
class EnumTests {
|
||||||
enum class Bras {
|
enum class Bras {
|
||||||
@ -42,8 +39,8 @@ class EnumTests {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// the new state, note in the test we serialised with value UNDERWIRE so the spacer
|
// the new state, note in the test we serialised with value UNDERWIRE so the spacer
|
||||||
// occuring after this won't have changed the ordinality of our serialised value
|
// occurring after this won't have changed the ordinality of our serialised value
|
||||||
// and thus should still be deserialisable
|
// and thus should still be deserializable
|
||||||
enum class OldBras2 {
|
enum class OldBras2 {
|
||||||
TSHIRT, UNDERWIRE, PUSHUP, SPACER, BRALETTE, SPACER2
|
TSHIRT, UNDERWIRE, PUSHUP, SPACER, BRALETTE, SPACER2
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
// To regenerate any of the binary test files do the following
|
// To regenerate any of the binary test files do the following
|
||||||
@ -19,13 +18,14 @@ import kotlin.test.assertEquals
|
|||||||
// 5. Comment back out the generation code and uncomment the actual test
|
// 5. Comment back out the generation code and uncomment the actual test
|
||||||
class EvolvabilityTests {
|
class EvolvabilityTests {
|
||||||
// When regenerating the test files this needs to be set to the file system location of the resource files
|
// When regenerating the test files this needs to be set to the file system location of the resource files
|
||||||
|
@Suppress("UNUSED")
|
||||||
var localPath = projectRootDir.toUri().resolve(
|
var localPath = projectRootDir.toUri().resolve(
|
||||||
"node-api/src/test/resources/net/corda/nodeapi/internal/serialization/amqp")
|
"node-api/src/test/resources/net/corda/nodeapi/internal/serialization/amqp")
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun simpleOrderSwapSameType() {
|
fun simpleOrderSwapSameType() {
|
||||||
val sf = testDefaultFactory()
|
val sf = testDefaultFactory()
|
||||||
val resource= "EvolvabilityTests.simpleOrderSwapSameType"
|
val resource = "EvolvabilityTests.simpleOrderSwapSameType"
|
||||||
|
|
||||||
val A = 1
|
val A = 1
|
||||||
val B = 2
|
val B = 2
|
||||||
@ -89,7 +89,7 @@ class EvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals(A, deserializedC.a)
|
assertEquals(A, deserializedC.a)
|
||||||
assertEquals(null, deserializedC.b)
|
assertEquals(null, deserializedC.b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotSerializableException::class)
|
@Test(expected = NotSerializableException::class)
|
||||||
fun addAdditionalParam() {
|
fun addAdditionalParam() {
|
||||||
@ -369,6 +369,7 @@ class EvolvabilityTests {
|
|||||||
|
|
||||||
// Add a parameter to inner but keep outer unchanged
|
// Add a parameter to inner but keep outer unchanged
|
||||||
data class Inner(val a: Int, val b: String?)
|
data class Inner(val a: Int, val b: String?)
|
||||||
|
|
||||||
data class Outer(val a: Int, val b: Inner)
|
data class Outer(val a: Int, val b: Inner)
|
||||||
|
|
||||||
val path = EvolvabilityTests::class.java.getResource(resource)
|
val path = EvolvabilityTests::class.java.getResource(resource)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user