Reformat files in node-api

This commit is contained in:
Tommy Lillehagen
2017-10-06 15:27:39 +01:00
parent cb9e27a84a
commit f98942d7ad
36 changed files with 256 additions and 212 deletions

View File

@ -12,7 +12,8 @@ import java.util.List;
public class ListsSerializationJavaTest {
@CordaSerializable
interface Parent {}
interface Parent {
}
public static class Child implements Parent {
private final int value;
@ -123,7 +124,7 @@ public class ListsSerializationJavaTest {
}
// Have to have own version as Kotlin inline functions cannot be easily called from Java
private static<T> void assertEqualAfterRoundTripSerialization(T container, Class<T> clazz) throws Exception {
private static <T> void assertEqualAfterRoundTripSerialization(T container, Class<T> clazz) throws Exception {
SerializerFactory factory1 = new SerializerFactory(AllWhitelist.INSTANCE, ClassLoader.getSystemClassLoader());
SerializationOutput ser = new SerializationOutput(factory1);
SerializedBytes<Object> bytes = ser.serialize(container);

View File

@ -37,7 +37,7 @@ class AttachmentsClassLoaderStaticContractTests : TestDependencyInjectionBase()
fun generateInitial(owner: PartyAndReference, magicNumber: Int, notary: Party): TransactionBuilder {
val state = State(magicNumber)
return TransactionBuilder(notary)
.withItems(StateAndContract(state, ATTACHMENT_PROGRAM_ID), Command(Commands.Create(), owner.party.owningKey))
.withItems(StateAndContract(state, ATTACHMENT_PROGRAM_ID), Command(Commands.Create(), owner.party.owningKey))
}
}
@ -45,7 +45,7 @@ class AttachmentsClassLoaderStaticContractTests : TestDependencyInjectionBase()
@Before
fun `create service hub`() {
serviceHub = MockServices(cordappPackages=listOf("net.corda.nodeapi.internal"))
serviceHub = MockServices(cordappPackages = listOf("net.corda.nodeapi.internal"))
}
@After

View File

@ -45,6 +45,7 @@ class AttachmentsClassLoaderTests : TestDependencyInjectionBase() {
whenever(serviceHub.attachments).thenReturn(attachmentStorage)
return this.withServiceHub(serviceHub)
}
private fun SerializationContext.withServiceHub(serviceHub: ServiceHub): SerializationContext {
return this.withTokenContext(SerializeAsTokenContextImpl(serviceHub) {}).withProperty(attachmentsClassLoaderEnabledPropertyName, true)
}
@ -266,7 +267,7 @@ class AttachmentsClassLoaderTests : TestDependencyInjectionBase() {
@Test
fun `test serialization of sub-sequence OpaqueBytes`() {
val bytesSequence = ByteSequence.of("0123456789".toByteArray(), 3 ,2)
val bytesSequence = ByteSequence.of("0123456789".toByteArray(), 3, 2)
val bytes = bytesSequence.serialize()
val copiedBytesSequence = bytes.deserialize()
@ -310,8 +311,8 @@ class AttachmentsClassLoaderTests : TestDependencyInjectionBase() {
val attachmentRef = serviceHub.attachmentId
val bytes = run {
val outboundContext = SerializationFactory.defaultFactory.defaultContext
.withServiceHub(serviceHub)
.withClassLoader(child)
.withServiceHub(serviceHub)
.withClassLoader(child)
val wireTransaction = tx.toWireTransaction(serviceHub, outboundContext)
wireTransaction.serialize(context = outboundContext)
}

View File

@ -271,6 +271,7 @@ class CordaClassResolverTests {
}
open class SubHashSet<E> : HashSet<E>()
@Test
fun `Check blacklisted subclass`() {
expectedEx.expect(IllegalStateException::class.java)
@ -281,6 +282,7 @@ class CordaClassResolverTests {
}
class SubSubHashSet<E> : SubHashSet<E>()
@Test
fun `Check blacklisted subsubclass`() {
expectedEx.expect(IllegalStateException::class.java)
@ -291,6 +293,7 @@ class CordaClassResolverTests {
}
class ConnectionImpl(private val connection: Connection) : Connection by connection
@Test
fun `Check blacklisted interface impl`() {
expectedEx.expect(IllegalStateException::class.java)
@ -302,6 +305,7 @@ class CordaClassResolverTests {
interface SubConnection : Connection
class SubConnectionImpl(private val subConnection: SubConnection) : SubConnection by subConnection
@Test
fun `Check blacklisted super-interface impl`() {
expectedEx.expect(IllegalStateException::class.java)
@ -320,6 +324,7 @@ class CordaClassResolverTests {
@CordaSerializable
class CordaSerializableHashSet<E> : HashSet<E>()
@Test
fun `Check blacklist precedes CordaSerializable`() {
expectedEx.expect(IllegalStateException::class.java)

View File

@ -188,10 +188,10 @@ class KryoTests : TestDependencyInjectionBase() {
@Test
fun `serialize - deserialize PrivacySalt`() {
val expected = PrivacySalt(byteArrayOf(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32
))
val serializedBytes = expected.serialize(factory, context)
val actual = serializedBytes.deserialize(factory, context)
@ -267,7 +267,7 @@ class KryoTests : TestDependencyInjectionBase() {
assertEquals(exception.message, exception2.message)
assertEquals(1, exception2.suppressed.size)
assertNotNull({ exception2.suppressed.find { it.message == toBeSuppressedOnSenderSide.message }})
assertNotNull({ exception2.suppressed.find { it.message == toBeSuppressedOnSenderSide.message } })
val toBeSuppressedOnReceiverSide = IllegalStateException("bazz2")
exception2.addSuppressed(toBeSuppressedOnReceiverSide)

View File

@ -22,12 +22,12 @@ class ListsSerializationTest : TestDependencyInjectionBase() {
private companion object {
val javaEmptyListClass = Collections.emptyList<Any>().javaClass
fun<T : Any> verifyEnvelope(serBytes: SerializedBytes<T>, envVerBody: (Envelope) -> Unit) =
amqpSpecific("AMQP specific envelope verification") {
val context = SerializationFactory.defaultFactory.defaultContext
val envelope = DeserializationInput(SerializerFactory(context.whitelist, context.deserializationClassLoader)).getEnvelope(serBytes)
envVerBody(envelope)
}
fun <T : Any> verifyEnvelope(serBytes: SerializedBytes<T>, envVerBody: (Envelope) -> Unit) =
amqpSpecific("AMQP specific envelope verification") {
val context = SerializationFactory.defaultFactory.defaultContext
val envelope = DeserializationInput(SerializerFactory(context.whitelist, context.deserializationClassLoader)).getEnvelope(serBytes)
envVerBody(envelope)
}
}
@Test
@ -54,7 +54,7 @@ class ListsSerializationTest : TestDependencyInjectionBase() {
}
@Test
fun `check empty list serialises as Java emptyList`() = kryoSpecific("Kryo specific test"){
fun `check empty list serialises as Java emptyList`() = kryoSpecific("Kryo specific test") {
val nameID = 0
val serializedForm = emptyList<Int>().serialize()
val output = ByteArrayOutputStream().apply {
@ -86,7 +86,7 @@ class ListsSerializationTest : TestDependencyInjectionBase() {
data class Child(val value: Int) : Parent
@CordaSerializable
data class CovariantContainer<out T: Parent>(val payload: List<T>)
data class CovariantContainer<out T : Parent>(val payload: List<T>)
@Test
fun `check covariance`() {
@ -99,11 +99,11 @@ class ListsSerializationTest : TestDependencyInjectionBase() {
envelope.schema.types.single { typeNotation -> typeNotation.name == java.util.List::class.java.name + "<?>" }
}
assertEqualAfterRoundTripSerialization(container, {bytes -> verifyEnvelope(bytes, ::verifyEnvelopeBody)})
assertEqualAfterRoundTripSerialization(container, { bytes -> verifyEnvelope(bytes, ::verifyEnvelopeBody) })
}
}
internal inline fun<reified T : Any> assertEqualAfterRoundTripSerialization(obj: T, noinline streamValidation: ((SerializedBytes<T>) -> Unit)? = null) {
internal inline fun <reified T : Any> assertEqualAfterRoundTripSerialization(obj: T, noinline streamValidation: ((SerializedBytes<T>) -> Unit)? = null) {
val serializedForm: SerializedBytes<T> = obj.serialize()
streamValidation?.invoke(serializedForm)

View File

@ -12,7 +12,7 @@ import org.junit.Before
import org.junit.Test
import java.io.ByteArrayOutputStream
class SerializationTokenTest : TestDependencyInjectionBase() {
class SerializationTokenTest : TestDependencyInjectionBase() {
private lateinit var factory: SerializationFactory
private lateinit var context: SerializationContext
@ -58,7 +58,7 @@ class SerializationTokenTest : TestDependencyInjectionBase() {
val testContext = this.context.withTokenContext(context)
val serializedBytes = tokenizableBefore.serialize(factory, testContext)
val tokenizableAfter = serializedBytes.deserialize(factory, testContext)
assertThat(tokenizableAfter).isSameAs(tokenizableBefore)
assertThat(tokenizableAfter).isSameAs(tokenizableBefore)
}
@Test(expected = UnsupportedOperationException::class)
@ -92,11 +92,11 @@ class SerializationTokenTest : TestDependencyInjectionBase() {
val kryo: Kryo = DefaultKryoCustomizer.customize(CordaKryo(CordaClassResolver(this.context)))
val stream = ByteArrayOutputStream()
Output(stream).use {
it.write(KryoHeaderV0_1.bytes)
kryo.writeClass(it, SingletonSerializeAsToken::class.java)
kryo.writeObject(it, emptyList<Any>())
}
Output(stream).use {
it.write(KryoHeaderV0_1.bytes)
kryo.writeClass(it, SingletonSerializeAsToken::class.java)
kryo.writeObject(it, emptyList<Any>())
}
val serializedBytes = SerializedBytes<Any>(stream.toByteArray())
serializedBytes.deserialize(factory, testContext)
}
@ -105,6 +105,7 @@ class SerializationTokenTest : TestDependencyInjectionBase() {
object UnitSerializationToken : SerializationToken {
override fun fromToken(context: SerializeAsTokenContext): Any = UnitSerializeAsToken()
}
override fun toToken(context: SerializeAsTokenContext): SerializationToken = UnitSerializationToken
}

View File

@ -17,25 +17,28 @@ class DeserializeMapTests {
@Test
fun mapTest() {
data class C(val c: Map<String, Int>)
val c = C (mapOf("A" to 1, "B" to 2))
val c = C(mapOf("A" to 1, "B" to 2))
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
}
@Test(expected=java.io.NotSerializableException::class)
@Test(expected = java.io.NotSerializableException::class)
fun abstractMapFromMapOf() {
data class C(val c: AbstractMap<String, Int>)
val c = C (mapOf("A" to 1, "B" to 2) as AbstractMap)
val c = C(mapOf("A" to 1, "B" to 2) as AbstractMap)
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
}
@Test(expected=java.io.NotSerializableException::class)
@Test(expected = java.io.NotSerializableException::class)
fun abstractMapFromTreeMap() {
data class C(val c: AbstractMap<String, Int>)
val c = C (TreeMap(mapOf("A" to 1, "B" to 2)))
val c = C(TreeMap(mapOf("A" to 1, "B" to 2)))
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
@ -44,7 +47,8 @@ class DeserializeMapTests {
@Test
fun sortedMapTest() {
data class C(val c: SortedMap<String, Int>)
val c = C(sortedMapOf ("A" to 1, "B" to 2))
val c = C(sortedMapOf("A" to 1, "B" to 2))
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
}
@ -52,7 +56,8 @@ class DeserializeMapTests {
@Test
fun navigableMapTest() {
data class C(val c: NavigableMap<String, Int>)
val c = C(TreeMap (mapOf("A" to 1, "B" to 2)).descendingMap())
val c = C(TreeMap(mapOf("A" to 1, "B" to 2)).descendingMap())
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
@ -61,9 +66,10 @@ class DeserializeMapTests {
@Test
fun dictionaryTest() {
data class C(val c: Dictionary<String, Int>)
val v : Hashtable<String, Int> = Hashtable()
v.put ("a", 1)
v.put ("b", 2)
val v: Hashtable<String, Int> = Hashtable()
v.put("a", 1)
v.put("b", 2)
val c = C(v)
// expected to throw
@ -74,9 +80,10 @@ class DeserializeMapTests {
@Test
fun hashtableTest() {
data class C(val c: Hashtable<String, Int>)
val v : Hashtable<String, Int> = Hashtable()
v.put ("a", 1)
v.put ("b", 2)
val v: Hashtable<String, Int> = Hashtable()
v.put("a", 1)
v.put("b", 2)
val c = C(v)
// expected to throw
@ -86,8 +93,9 @@ class DeserializeMapTests {
@Test
fun hashMapTest() {
data class C(val c : HashMap<String, Int>)
val c = C (HashMap (mapOf("A" to 1, "B" to 2)))
data class C(val c: HashMap<String, Int>)
val c = C(HashMap(mapOf("A" to 1, "B" to 2)))
// expect this to throw
Assertions.assertThatThrownBy { TestSerializationOutput(VERBOSE, sf).serialize(c) }
@ -96,8 +104,9 @@ class DeserializeMapTests {
@Test
fun weakHashMapTest() {
data class C(val c : WeakHashMap<String, Int>)
val c = C (WeakHashMap (mapOf("A" to 1, "B" to 2)))
data class C(val c: WeakHashMap<String, Int>)
val c = C(WeakHashMap(mapOf("A" to 1, "B" to 2)))
Assertions.assertThatThrownBy { TestSerializationOutput(VERBOSE, sf).serialize(c) }
.isInstanceOf(IllegalArgumentException::class.java).hasMessageContaining("Weak references with map types not supported. Suggested fix: use java.util.LinkedHashMap instead.")
@ -106,7 +115,8 @@ class DeserializeMapTests {
@Test
fun concreteTreeMapTest() {
data class C(val c: TreeMap<String, Int>)
val c = C(TreeMap (mapOf("A" to 1, "B" to 3)))
val c = C(TreeMap(mapOf("A" to 1, "B" to 3)))
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)
@ -114,8 +124,9 @@ class DeserializeMapTests {
@Test
fun concreteLinkedHashMapTest() {
data class C(val c : LinkedHashMap<String, Int>)
val c = C (LinkedHashMap (mapOf("A" to 1, "B" to 2)))
data class C(val c: LinkedHashMap<String, Int>)
val c = C(LinkedHashMap(mapOf("A" to 1, "B" to 2)))
val serialisedBytes = TestSerializationOutput(VERBOSE, sf).serialize(c)
DeserializationInput(sf).deserialize(serialisedBytes)

View File

@ -402,7 +402,8 @@ class DeserializeSimpleTypesTests {
@Test
fun arrayOfArrayOfInt() {
class C(val c: Array<Array<Int>>)
val c = C (arrayOf (arrayOf(1,2,3), arrayOf(4,5,6)))
val c = C(arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)))
val serialisedC = TestSerializationOutput(VERBOSE, sf1).serialize(c)
val deserializedC = DeserializationInput(sf1).deserialize(serialisedC)
@ -421,7 +422,8 @@ class DeserializeSimpleTypesTests {
@Test
fun arrayOfIntArray() {
class C(val c: Array<IntArray>)
val c = C (arrayOf (IntArray(3), IntArray(3)))
val c = C(arrayOf(IntArray(3), IntArray(3)))
c.c[0][0] = 1; c.c[0][1] = 2; c.c[0][2] = 3
c.c[1][0] = 4; c.c[1][1] = 5; c.c[1][2] = 6
@ -444,22 +446,32 @@ class DeserializeSimpleTypesTests {
class C(val c: Array<Array<IntArray>>)
val c = C(arrayOf(arrayOf(IntArray(3), IntArray(3), IntArray(3)),
arrayOf(IntArray(3), IntArray(3), IntArray(3)),
arrayOf(IntArray(3), IntArray(3), IntArray(3))))
arrayOf(IntArray(3), IntArray(3), IntArray(3)),
arrayOf(IntArray(3), IntArray(3), IntArray(3))))
for (i in 0..2) { for (j in 0..2) { for (k in 0..2) { c.c[i][j][k] = i + j + k } } }
for (i in 0..2) {
for (j in 0..2) {
for (k in 0..2) {
c.c[i][j][k] = i + j + k
}
}
}
val serialisedC = TestSerializationOutput(VERBOSE, sf1).serialize(c)
val deserializedC = DeserializationInput(sf1).deserialize(serialisedC)
for (i in 0..2) { for (j in 0..2) { for (k in 0..2) {
assertEquals(c.c[i][j][k], deserializedC.c[i][j][k])
}}}
for (i in 0..2) {
for (j in 0..2) {
for (k in 0..2) {
assertEquals(c.c[i][j][k], deserializedC.c[i][j][k])
}
}
}
}
@Test
fun nestedRepeatedTypes() {
class A(val a : A?, val b: Int)
class A(val a: A?, val b: Int)
var a = A(A(A(A(A(null, 1), 2), 3), 4), 5)

View File

@ -49,7 +49,7 @@ class EnumTests {
}
enum class BrasWithInit (val someList: List<Int>) {
enum class BrasWithInit(val someList: List<Int>) {
TSHIRT(emptyList()),
UNDERWIRE(listOf(1, 2, 3)),
PUSHUP(listOf(100, 200)),
@ -90,7 +90,7 @@ class EnumTests {
assertEquals(8, schema_bras.choices.size)
Bras.values().forEach {
val bra = it
assertNotNull (schema_bras.choices.find { it.name == bra.name })
assertNotNull(schema_bras.choices.find { it.name == bra.name })
}
}
@ -115,7 +115,7 @@ class EnumTests {
assertEquals(8, schema_bras.choices.size)
Bras.values().forEach {
val bra = it
assertNotNull (schema_bras.choices.find { it.name == bra.name })
assertNotNull(schema_bras.choices.find { it.name == bra.name })
}
// Test the actual deserialised object
@ -124,13 +124,13 @@ class EnumTests {
@Test
fun multiEnum() {
data class Support (val top: Bras, val day : DayOfWeek)
data class WeeklySupport (val tops: List<Support>)
data class Support(val top: Bras, val day: DayOfWeek)
data class WeeklySupport(val tops: List<Support>)
val week = WeeklySupport (listOf(
Support (Bras.PUSHUP, DayOfWeek.MONDAY),
Support (Bras.UNDERWIRE, DayOfWeek.WEDNESDAY),
Support (Bras.PADDED, DayOfWeek.SUNDAY)))
val week = WeeklySupport(listOf(
Support(Bras.PUSHUP, DayOfWeek.MONDAY),
Support(Bras.UNDERWIRE, DayOfWeek.WEDNESDAY),
Support(Bras.PADDED, DayOfWeek.SUNDAY)))
val obj = DeserializationInput(sf1).deserialize(TestSerializationOutput(VERBOSE, sf1).serialize(week))
@ -146,7 +146,7 @@ class EnumTests {
fun enumWithInit() {
data class C(val c: BrasWithInit)
val c = C (BrasWithInit.PUSHUP)
val c = C(BrasWithInit.PUSHUP)
val obj = DeserializationInput(sf1).deserialize(TestSerializationOutput(VERBOSE, sf1).serialize(c))
assertEquals(c.c, obj.c)
@ -157,7 +157,7 @@ class EnumTests {
val path = EnumTests::class.java.getResource("EnumTests.changedEnum1")
val f = File(path.toURI())
data class C (val a: OldBras)
data class C(val a: OldBras)
// Original version of the class for the serialised version of this class
//
@ -177,7 +177,7 @@ class EnumTests {
val path = EnumTests::class.java.getResource("EnumTests.changedEnum2")
val f = File(path.toURI())
data class C (val a: OldBras2)
data class C(val a: OldBras2)
// DO NOT CHANGE THIS, it's important we serialise with a value that doesn't
// change position in the upated enum class
@ -197,9 +197,9 @@ class EnumTests {
@Test
fun enumNotWhitelistedFails() {
data class C (val c: Bras)
data class C(val c: Bras)
class WL (val allowed: String): ClassWhitelist {
class WL(val allowed: String) : ClassWhitelist {
override fun hasListed(type: Class<*>): Boolean {
return type.name == allowed
}
@ -214,7 +214,7 @@ class EnumTests {
@Test
fun enumWhitelisted() {
data class C (val c: Bras)
data class C(val c: Bras)
class WL : ClassWhitelist {
override fun hasListed(type: Class<*>): Boolean {
@ -231,7 +231,7 @@ class EnumTests {
@Test
fun enumAnnotated() {
@CordaSerializable data class C (val c: AnnotatedBras)
@CordaSerializable data class C(val c: AnnotatedBras)
class WL : ClassWhitelist {
override fun hasListed(type: Class<*>) = false
@ -245,21 +245,21 @@ class EnumTests {
@Test
fun deserializeNonWhitlistedEnum() {
data class C (val c: Bras)
data class C(val c: Bras)
class WL (val allowed: List<String>) : ClassWhitelist {
class WL(val allowed: List<String>) : ClassWhitelist {
override fun hasListed(type: Class<*>) = type.name in allowed
}
// first serialise the class using a context in which Bras are whitelisted
val factory = SerializerFactory(WL(listOf (classTestName("C"),
val factory = SerializerFactory(WL(listOf(classTestName("C"),
"net.corda.nodeapi.internal.serialization.amqp.EnumTests\$Bras")),
ClassLoader.getSystemClassLoader())
val bytes = TestSerializationOutput(VERBOSE, factory).serialize(C(Bras.UNDERWIRE))
// then take that serialised object and attempt to deserialize it in a context that
// disallows the Bras enum
val factory2 = SerializerFactory(WL(listOf (classTestName("C"))), ClassLoader.getSystemClassLoader())
val factory2 = SerializerFactory(WL(listOf(classTestName("C"))), ClassLoader.getSystemClassLoader())
Assertions.assertThatThrownBy {
DeserializationInput(factory2).deserialize(bytes)
}.isInstanceOf(NotSerializableException::class.java)

View File

@ -32,7 +32,7 @@ class EvolvabilityTests {
// f.writeBytes(sc.bytes)
// new version of the class, in this case the order of the parameters has been swapped
data class C (val b: Int, val a: Int)
data class C(val b: Int, val a: Int)
val sc2 = f.readBytes()
val deserializedC = DeserializationInput(sf).deserialize(SerializedBytes<C>(sc2))
@ -56,7 +56,7 @@ class EvolvabilityTests {
// f.writeBytes(sc.bytes)
// new version of the class, in this case the order of the parameters has been swapped
data class C (val b: String, val a: Int)
data class C(val b: String, val a: Int)
val sc2 = f.readBytes()
val deserializedC = DeserializationInput(sf).deserialize(SerializedBytes<C>(sc2))
@ -79,13 +79,13 @@ class EvolvabilityTests {
// f.writeBytes(sc.bytes)
// println ("Path = $path")
data class C (val a: Int, val b: Int?)
data class C(val a: Int, val b: Int?)
val sc2 = f.readBytes()
val deserializedC = DeserializationInput(sf).deserialize(SerializedBytes<C>(sc2))
assertEquals (A, deserializedC.a)
assertEquals (null, deserializedC.b)
assertEquals(A, deserializedC.a)
assertEquals(null, deserializedC.b)
}
@Test(expected = NotSerializableException::class)
@ -104,7 +104,7 @@ class EvolvabilityTests {
// println ("Path = $path")
// new version of the class, in this case a new parameter has been added (b)
data class C (val a: Int, val b: Int)
data class C(val a: Int, val b: Int)
val sc2 = f.readBytes()
@ -132,13 +132,13 @@ class EvolvabilityTests {
// f.writeBytes(scc.bytes)
// println ("Path = $path")
data class CC (val b: String, val d: Int)
data class CC(val b: String, val d: Int)
val sc2 = f.readBytes()
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
assertEquals (B, deserializedCC.b)
assertEquals (D, deserializedCC.d)
assertEquals(B, deserializedCC.b)
assertEquals(D, deserializedCC.d)
}
@Suppress("UNUSED_VARIABLE")
@ -185,16 +185,16 @@ class EvolvabilityTests {
// println ("Path = $path")
@Suppress("UNUSED")
data class CC (val a: Int, val b: String) {
data class CC(val a: Int, val b: String) {
@DeprecatedConstructorForDeserialization(1)
constructor (a: Int) : this (a, "hello")
constructor (a: Int) : this(a, "hello")
}
val sc2 = f.readBytes()
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
assertEquals (A, deserializedCC.a)
assertEquals ("hello", deserializedCC.b)
assertEquals(A, deserializedCC.a)
assertEquals("hello", deserializedCC.b)
}
@Test(expected = NotSerializableException::class)
@ -214,9 +214,9 @@ class EvolvabilityTests {
// f.writeBytes(scc.bytes)
// println ("Path = $path")
data class CC (val a: Int, val b: String) {
data class CC(val a: Int, val b: String) {
// constructor annotation purposefully omitted
constructor (a: Int) : this (a, "hello")
constructor (a: Int) : this(a, "hello")
}
// we expect this to throw as we should not find any constructors
@ -242,20 +242,20 @@ class EvolvabilityTests {
// println ("Path = $path")
@Suppress("UNUSED")
data class CC (val a: Int, val b: Int, val c: String, val d: String) {
data class CC(val a: Int, val b: Int, val c: String, val d: String) {
// ensure none of the original parameters align with the initial
// construction order
@DeprecatedConstructorForDeserialization(1)
constructor (c: String, a: Int, b: Int) : this (a, b, c, "wibble")
constructor (c: String, a: Int, b: Int) : this(a, b, c, "wibble")
}
val sc2 = f.readBytes()
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
assertEquals (A, deserializedCC.a)
assertEquals (B, deserializedCC.b)
assertEquals (C, deserializedCC.c)
assertEquals ("wibble", deserializedCC.d)
assertEquals(A, deserializedCC.a)
assertEquals(B, deserializedCC.b)
assertEquals(C, deserializedCC.c)
assertEquals("wibble", deserializedCC.d)
}
@Test
@ -277,20 +277,20 @@ class EvolvabilityTests {
// println ("Path = $path")
// b is removed, d is added
data class CC (val a: Int, val c: String, val d: String) {
data class CC(val a: Int, val c: String, val d: String) {
// ensure none of the original parameters align with the initial
// construction order
@Suppress("UNUSED")
@DeprecatedConstructorForDeserialization(1)
constructor (c: String, a: Int) : this (a, c, "wibble")
constructor (c: String, a: Int) : this(a, c, "wibble")
}
val sc2 = f.readBytes()
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
assertEquals (A, deserializedCC.a)
assertEquals (C, deserializedCC.c)
assertEquals ("wibble", deserializedCC.d)
assertEquals(A, deserializedCC.a)
assertEquals(C, deserializedCC.c)
assertEquals("wibble", deserializedCC.d)
}
@Test
@ -322,13 +322,15 @@ class EvolvabilityTests {
// println ("Path = $path1")
@Suppress("UNUSED")
data class C (val e: Int, val c: Int, val b: Int, val a: Int, val d: Int) {
data class C(val e: Int, val c: Int, val b: Int, val a: Int, val d: Int) {
@DeprecatedConstructorForDeserialization(1)
constructor (b: Int, a: Int) : this (-1, -1, b, a, -1)
constructor (b: Int, a: Int) : this(-1, -1, b, a, -1)
@DeprecatedConstructorForDeserialization(2)
constructor (a: Int, c: Int, b: Int) : this (-1, c, b, a, -1)
constructor (a: Int, c: Int, b: Int) : this(-1, c, b, a, -1)
@DeprecatedConstructorForDeserialization(3)
constructor (a: Int, b: Int, c: Int, d: Int) : this (-1, c, b, a, d)
constructor (a: Int, b: Int, c: Int, d: Int) : this(-1, c, b, a, d)
}
val sb1 = File(path1.toURI()).readBytes()
@ -376,15 +378,16 @@ class EvolvabilityTests {
// println ("Path = $path")
// Add a parameter to inner but keep outer unchanged
data class Inner (val a: Int, val b: String?)
data class Outer (val a: Int, val b: Inner)
data class Inner(val a: Int, val b: String?)
data class Outer(val a: Int, val b: Inner)
val sc2 = f.readBytes()
val outer = DeserializationInput(sf).deserialize(SerializedBytes<Outer>(sc2))
assertEquals (oa, outer.a)
assertEquals (ia, outer.b.a)
assertEquals (null, outer.b.b)
assertEquals(oa, outer.a)
assertEquals(ia, outer.b.a)
assertEquals(null, outer.b.b)
}
@Test
@ -416,15 +419,18 @@ class EvolvabilityTests {
// println ("Path = $path1")
@Suppress("UNUSED")
data class C (val b: Int, val c: Int, val d: Int, val e: Int, val f: Int, val g: Int) {
data class C(val b: Int, val c: Int, val d: Int, val e: Int, val f: Int, val g: Int) {
@DeprecatedConstructorForDeserialization(1)
constructor (b: Int, c: Int) : this (b, c, -1, -1, -1, -1)
constructor (b: Int, c: Int) : this(b, c, -1, -1, -1, -1)
@DeprecatedConstructorForDeserialization(2)
constructor (b: Int, c: Int, d: Int) : this (b, c, d, -1, -1, -1)
constructor (b: Int, c: Int, d: Int) : this(b, c, d, -1, -1, -1)
@DeprecatedConstructorForDeserialization(3)
constructor (b: Int, c: Int, d: Int, e: Int) : this (b, c, d, e, -1, -1)
constructor (b: Int, c: Int, d: Int, e: Int) : this(b, c, d, e, -1, -1)
@DeprecatedConstructorForDeserialization(4)
constructor (b: Int, c: Int, d: Int, e: Int, f: Int) : this (b, c, d, e, f, -1)
constructor (b: Int, c: Int, d: Int, e: Int, f: Int) : this(b, c, d, e, f, -1)
}
val sb1 = File(path1.toURI()).readBytes()

View File

@ -50,7 +50,7 @@ class SerializationOutputTests {
data class testShort(val s: Short)
data class testBoolean(val b : Boolean)
data class testBoolean(val b: Boolean)
interface FooInterface {
val pub: Int
@ -145,13 +145,13 @@ class SerializationOutputTests {
data class PolymorphicProperty(val foo: FooInterface?)
private inline fun<reified T : Any> serdes(obj: T,
factory: SerializerFactory = SerializerFactory (
AllWhitelist, ClassLoader.getSystemClassLoader()),
freshDeserializationFactory: SerializerFactory = SerializerFactory(
AllWhitelist, ClassLoader.getSystemClassLoader()),
expectedEqual: Boolean = true,
expectDeserializedEqual: Boolean = true): T {
private inline fun <reified T : Any> serdes(obj: T,
factory: SerializerFactory = SerializerFactory(
AllWhitelist, ClassLoader.getSystemClassLoader()),
freshDeserializationFactory: SerializerFactory = SerializerFactory(
AllWhitelist, ClassLoader.getSystemClassLoader()),
expectedEqual: Boolean = true,
expectDeserializedEqual: Boolean = true): T {
val ser = SerializationOutput(factory)
val bytes = ser.serialize(obj)
@ -446,10 +446,10 @@ class SerializationOutputTests {
try {
try {
throw IOException("Layer 1")
} catch(t: Throwable) {
} catch (t: Throwable) {
throw IllegalStateException("Layer 2", t)
}
} catch(t: Throwable) {
} catch (t: Throwable) {
val desThrowable = serdesThrowableWithInternalInfo(t, factory, factory2, false)
assertSerializedThrowableEquivalent(t, desThrowable)
}
@ -476,12 +476,12 @@ class SerializationOutputTests {
try {
try {
throw IOException("Layer 1")
} catch(t: Throwable) {
} catch (t: Throwable) {
val e = IllegalStateException("Layer 2")
e.addSuppressed(t)
throw e
}
} catch(t: Throwable) {
} catch (t: Throwable) {
val desThrowable = serdesThrowableWithInternalInfo(t, factory, factory2, false)
assertSerializedThrowableEquivalent(t, desThrowable)
}
@ -535,6 +535,7 @@ class SerializationOutputTests {
}
val FOO_PROGRAM_ID = "net.corda.nodeapi.internal.serialization.amqp.SerializationOutputTests.FooContract"
class FooState : ContractState {
override val participants: List<AbstractParty> = emptyList()
}

View File

@ -19,6 +19,7 @@ class SerializeAndReturnSchemaTest {
@Test
fun getSchema() {
data class C(val a: Int, val b: Int)
val a = 1
val b = 2

View File

@ -12,7 +12,7 @@ import java.lang.reflect.Type
import java.util.concurrent.ConcurrentHashMap
import kotlin.test.assertEquals
class InStatic : Exception ("Help!, help!, I'm being repressed")
class InStatic : Exception("Help!, help!, I'm being repressed")
class C {
companion object {
@ -28,7 +28,7 @@ class C {
// comment out the companion object from here, comment out the test code and uncomment
// the generation code, then re-run the test and copy the file shown in the output print
// to the resource directory
class C2 (var b: Int) {
class C2(var b: Int) {
/*
companion object {
init {
@ -39,14 +39,14 @@ class C2 (var b: Int) {
}
class StaticInitialisationOfSerializedObjectTest {
@Test(expected=java.lang.ExceptionInInitializerError::class)
@Test(expected = java.lang.ExceptionInInitializerError::class)
fun itBlowsUp() {
C()
}
@Test
fun KotlinObjectWithCompanionObject() {
data class D (val c : C)
data class D(val c: C)
val sf = SerializerFactory(AllWhitelist, ClassLoader.getSystemClassLoader())
@ -71,7 +71,7 @@ class StaticInitialisationOfSerializedObjectTest {
@Test
fun deserializeTest() {
data class D (val c : C2)
data class D(val c: C2)
val path = EvolvabilityTests::class.java.getResource("StaticInitialisationOfSerializedObjectTest.deserializeTest")
val f = File(path.toURI())
@ -86,7 +86,7 @@ class StaticInitialisationOfSerializedObjectTest {
class WL : ClassWhitelist {
override fun hasListed(type: Class<*>) =
type.name == "net.corda.nodeapi.internal.serialization.amqp" +
".StaticInitialisationOfSerializedObjectTest\$deserializeTest\$D"
".StaticInitialisationOfSerializedObjectTest\$deserializeTest\$D"
}
val sf2 = SerializerFactory(WL(), ClassLoader.getSystemClassLoader())
@ -100,14 +100,14 @@ class StaticInitialisationOfSerializedObjectTest {
// Version of a serializer factory that will allow the class carpenter living on the
// factory to have a different whitelist applied to it than the factory
class TestSerializerFactory(wl1: ClassWhitelist, wl2: ClassWhitelist) :
SerializerFactory (wl1, ClassLoader.getSystemClassLoader()) {
SerializerFactory(wl1, ClassLoader.getSystemClassLoader()) {
override val classCarpenter = ClassCarpenter(ClassLoader.getSystemClassLoader(), wl2)
}
// This time have the serilization factory and the carpenter use different whitelists
@Test
fun deserializeTest2() {
data class D (val c : C2)
data class D(val c: C2)
val path = EvolvabilityTests::class.java.getResource("StaticInitialisationOfSerializedObjectTest.deserializeTest2")
val f = File(path.toURI())