mirror of
https://github.com/corda/corda.git
synced 2025-02-10 21:01:27 +00:00
Added an openAttachment endpoint to the RPC interface and tests for the open, upload and exists attachment RPC interfaces.
This commit is contained in:
parent
cbf0c7eec4
commit
061597deff
@ -15,6 +15,7 @@ import net.corda.core.node.services.Vault
|
|||||||
import net.corda.core.transactions.SignedTransaction
|
import net.corda.core.transactions.SignedTransaction
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
data class StateMachineInfo(
|
data class StateMachineInfo(
|
||||||
@ -98,6 +99,11 @@ interface CordaRPCOps : RPCOps {
|
|||||||
*/
|
*/
|
||||||
fun attachmentExists(id: SecureHash): Boolean
|
fun attachmentExists(id: SecureHash): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download an attachment JAR by ID
|
||||||
|
*/
|
||||||
|
fun openAttachment(id: SecureHash): InputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a jar to the node, returns it's hash.
|
* Uploads a jar to the node, returns it's hash.
|
||||||
*/
|
*/
|
||||||
|
@ -101,6 +101,7 @@ class CordaRPCOpsImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun attachmentExists(id: SecureHash) = services.storageService.attachments.openAttachment(id) != null
|
override fun attachmentExists(id: SecureHash) = services.storageService.attachments.openAttachment(id) != null
|
||||||
|
override fun openAttachment(id: SecureHash) = services.storageService.attachments.openAttachment(id)!!.open()
|
||||||
override fun uploadAttachment(jar: InputStream) = services.storageService.attachments.importAttachment(jar)
|
override fun uploadAttachment(jar: InputStream) = services.storageService.attachments.importAttachment(jar)
|
||||||
override fun currentNodeTime(): Instant = Instant.now(services.clock)
|
override fun currentNodeTime(): Instant = Instant.now(services.clock)
|
||||||
override fun uploadFile(dataType: String, name: String?, file: InputStream): String {
|
override fun uploadFile(dataType: String, name: String?, file: InputStream): String {
|
||||||
|
@ -24,15 +24,22 @@ import net.corda.testing.expectEvents
|
|||||||
import net.corda.testing.node.MockNetwork
|
import net.corda.testing.node.MockNetwork
|
||||||
import net.corda.testing.node.MockNetwork.MockNode
|
import net.corda.testing.node.MockNetwork.MockNode
|
||||||
import net.corda.testing.sequence
|
import net.corda.testing.sequence
|
||||||
|
import org.apache.commons.io.IOUtils
|
||||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
|
|
||||||
class CordaRPCOpsImplTest {
|
class CordaRPCOpsImplTest {
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
val testJar = "net/corda/node/testing/test.jar"
|
||||||
|
}
|
||||||
|
|
||||||
lateinit var network: MockNetwork
|
lateinit var network: MockNetwork
|
||||||
lateinit var aliceNode: MockNode
|
lateinit var aliceNode: MockNode
|
||||||
lateinit var notaryNode: MockNode
|
lateinit var notaryNode: MockNode
|
||||||
@ -196,4 +203,24 @@ class CordaRPCOpsImplTest {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `can upload an attachment`() {
|
||||||
|
val inputJar = Thread.currentThread().contextClassLoader.getResourceAsStream(testJar)
|
||||||
|
val secureHash = rpc.uploadAttachment(inputJar)
|
||||||
|
assert(rpc.attachmentExists(secureHash))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `can download an uploaded attachment`() {
|
||||||
|
val inputJar = Thread.currentThread().contextClassLoader.getResourceAsStream(testJar)
|
||||||
|
val secureHash = rpc.uploadAttachment(inputJar)
|
||||||
|
val bufferFile = ByteArrayOutputStream()
|
||||||
|
val bufferRpc = ByteArrayOutputStream()
|
||||||
|
|
||||||
|
IOUtils.copy(Thread.currentThread().contextClassLoader.getResourceAsStream(testJar), bufferFile)
|
||||||
|
IOUtils.copy(rpc.openAttachment(secureHash), bufferRpc)
|
||||||
|
|
||||||
|
assert(Arrays.equals(bufferFile.toByteArray(), bufferRpc.toByteArray()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
node/src/test/resources/net/corda/node/testing/test.jar
Normal file
BIN
node/src/test/resources/net/corda/node/testing/test.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user