mirror of
https://github.com/corda/corda.git
synced 2025-04-05 10:27:11 +00:00
CORDA-2871: Ensure ClassLoader.loadClass() throws ClassNotFoundException for all cases where the class cannot be found. (#64)
This commit is contained in:
parent
062acf89be
commit
1a53f1a22a
@ -0,0 +1,69 @@
|
||||
package net.corda.djvm.serialization
|
||||
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.node.services.AttachmentId
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.internal._contextSerializationEnv
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.djvm.serialization.SandboxType.*
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.api.fail
|
||||
import java.util.function.Function
|
||||
|
||||
@ExtendWith(LocalSerialization::class)
|
||||
class DeserializeKotlinAliasTest : TestBase(KOTLIN) {
|
||||
@Test
|
||||
fun `test deserializing kotlin alias`() {
|
||||
val attachmentId = SecureHash.allOnesHash
|
||||
val data = attachmentId.serialize()
|
||||
|
||||
sandbox {
|
||||
_contextSerializationEnv.set(createSandboxSerializationEnv(classLoader))
|
||||
|
||||
val sandboxAttachmentId = data.deserializeFor(classLoader)
|
||||
|
||||
val taskFactory = classLoader.createRawTaskFactory()
|
||||
val showAlias = classLoader.createTaskFor(taskFactory, ShowAlias::class.java)
|
||||
val result = showAlias.apply(sandboxAttachmentId) ?: fail("Result cannot be null")
|
||||
|
||||
assertEquals(ShowAlias().apply(attachmentId), result.toString())
|
||||
assertEquals(SANDBOX_STRING, result::class.java.name)
|
||||
}
|
||||
}
|
||||
|
||||
class ShowAlias : Function<AttachmentId, String> {
|
||||
override fun apply(id: AttachmentId): String {
|
||||
return id.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test deserializing data with kotlin alias`() {
|
||||
val attachment = AttachmentData(SecureHash.allOnesHash)
|
||||
val data = attachment.serialize()
|
||||
|
||||
sandbox {
|
||||
_contextSerializationEnv.set(createSandboxSerializationEnv(classLoader))
|
||||
|
||||
val sandboxAttachment = data.deserializeFor(classLoader)
|
||||
|
||||
val taskFactory = classLoader.createRawTaskFactory()
|
||||
val showAliasData = classLoader.createTaskFor(taskFactory, ShowAliasData::class.java)
|
||||
val result = showAliasData.apply(sandboxAttachment) ?: fail("Result cannot be null")
|
||||
|
||||
assertEquals(ShowAliasData().apply(attachment), result.toString())
|
||||
assertEquals(SANDBOX_STRING, result::class.java.name)
|
||||
}
|
||||
}
|
||||
|
||||
class ShowAliasData: Function<AttachmentData, String> {
|
||||
override fun apply(data: AttachmentData): String {
|
||||
return data.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
data class AttachmentData(val id: AttachmentId)
|
Loading…
x
Reference in New Issue
Block a user