mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
Introduced a few more extension methods to Path, which are clearer than the static methods in Files. (#2985)
Also migrated code away from the old File API.
This commit is contained in:
@ -5,20 +5,21 @@ import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.list
|
||||
import net.corda.core.internal.readLines
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.internal.NodeStartup
|
||||
import net.corda.node.services.Permissions.Companion.startFlow
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import net.corda.testing.node.User
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import net.corda.testing.driver.DriverParameters
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.node.User
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.io.*
|
||||
import java.nio.file.Files
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class BootTests {
|
||||
@ -40,13 +41,13 @@ class BootTests {
|
||||
driver(DriverParameters(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString()))) {
|
||||
val alice = startNode(providedName = ALICE_NAME).get()
|
||||
val logFolder = alice.baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME
|
||||
val logFile = logFolder.toFile().listFiles { _, name -> name.endsWith(".log") }.single()
|
||||
val logFile = logFolder.list { it.filter { it.fileName.toString().endsWith(".log") }.findAny().get() }
|
||||
// Start second Alice, should fail
|
||||
assertThatThrownBy {
|
||||
startNode(providedName = ALICE_NAME).getOrThrow()
|
||||
}
|
||||
// We count the number of nodes that wrote into the logfile by counting "Logs can be found in"
|
||||
val numberOfNodesThatLogged = Files.lines(logFile.toPath()).filter { NodeStartup.LOGS_CAN_BE_FOUND_IN_STRING in it }.count()
|
||||
val numberOfNodesThatLogged = logFile.readLines { it.filter { NodeStartup.LOGS_CAN_BE_FOUND_IN_STRING in it }.count() }
|
||||
assertEquals(1, numberOfNodesThatLogged)
|
||||
}
|
||||
}
|
||||
|
@ -4,57 +4,56 @@ import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigException
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.writeText
|
||||
import net.corda.node.internal.cordapp.CordappConfigFileProvider
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
class CordappConfigFileProviderTests {
|
||||
private companion object {
|
||||
val cordappConfDir = File("build/tmp/cordapps/config")
|
||||
val cordappName = "test"
|
||||
val cordappConfFile = File(cordappConfDir, cordappName + ".conf").toPath()
|
||||
val cordappConfDir = Paths.get("build") / "tmp" / "cordapps" / "config"
|
||||
const val cordappName = "test"
|
||||
val cordappConfFile = cordappConfDir / "$cordappName.conf"
|
||||
|
||||
val validConfig = ConfigFactory.parseString("key=value")
|
||||
val alternateValidConfig = ConfigFactory.parseString("key=alternateValue")
|
||||
val invalidConfig = "Invalid"
|
||||
val validConfig: Config = ConfigFactory.parseString("key=value")
|
||||
val alternateValidConfig: Config = ConfigFactory.parseString("key=alternateValue")
|
||||
const val invalidConfig = "Invalid"
|
||||
}
|
||||
|
||||
val provider = CordappConfigFileProvider(cordappConfDir)
|
||||
private val provider = CordappConfigFileProvider(cordappConfDir)
|
||||
|
||||
@Test
|
||||
fun `test that config can be loaded`() {
|
||||
writeConfig(validConfig, cordappConfFile)
|
||||
writeConfig(validConfig)
|
||||
assertThat(provider.getConfigByName(cordappName)).isEqualTo(validConfig)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `config is idempotent if the underlying file is not changed`() {
|
||||
writeConfig(validConfig, cordappConfFile)
|
||||
writeConfig(validConfig)
|
||||
assertThat(provider.getConfigByName(cordappName)).isEqualTo(validConfig)
|
||||
assertThat(provider.getConfigByName(cordappName)).isEqualTo(validConfig)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `config is not idempotent if the underlying file is changed`() {
|
||||
writeConfig(validConfig, cordappConfFile)
|
||||
writeConfig(validConfig)
|
||||
assertThat(provider.getConfigByName(cordappName)).isEqualTo(validConfig)
|
||||
|
||||
writeConfig(alternateValidConfig, cordappConfFile)
|
||||
writeConfig(alternateValidConfig)
|
||||
assertThat(provider.getConfigByName(cordappName)).isEqualTo(alternateValidConfig)
|
||||
}
|
||||
|
||||
@Test(expected = ConfigException.Parse::class)
|
||||
fun `an invalid config throws an exception`() {
|
||||
Files.write(cordappConfFile, invalidConfig.toByteArray())
|
||||
|
||||
cordappConfFile.writeText(invalidConfig)
|
||||
provider.getConfigByName(cordappName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the config to the path provided - will (and must) overwrite any existing config
|
||||
*/
|
||||
private fun writeConfig(config: Config, to: Path) = Files.write(cordappConfFile, config.root().render(ConfigRenderOptions.concise()).toByteArray())
|
||||
private fun writeConfig(config: Config) = cordappConfFile.writeText(config.root().render(ConfigRenderOptions.concise()))
|
||||
}
|
@ -8,6 +8,7 @@ import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.internal.concurrent.transpose
|
||||
import net.corda.core.internal.copyTo
|
||||
import net.corda.core.internal.createDirectories
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.toLedgerTransaction
|
||||
@ -30,15 +31,14 @@ import net.corda.testing.core.TestIdentity
|
||||
import net.corda.testing.driver.DriverDSL
|
||||
import net.corda.testing.driver.NodeHandle
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.internal.MockCordappConfigProvider
|
||||
import net.corda.testing.internal.rigorousMock
|
||||
import net.corda.testing.internal.withoutTestSerialization
|
||||
import net.corda.testing.internal.MockCordappConfigProvider
|
||||
import net.corda.testing.services.MockAttachmentStorage
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Files
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class AttachmentLoadingTests {
|
||||
@ -54,7 +54,7 @@ class AttachmentLoadingTests {
|
||||
private companion object {
|
||||
private val logger = contextLogger()
|
||||
val isolatedJAR = AttachmentLoadingTests::class.java.getResource("isolated.jar")!!
|
||||
val ISOLATED_CONTRACT_ID = "net.corda.finance.contracts.isolated.AnotherDummyContract"
|
||||
const val ISOLATED_CONTRACT_ID = "net.corda.finance.contracts.isolated.AnotherDummyContract"
|
||||
|
||||
val bankAName = CordaX500Name("BankA", "Zurich", "CH")
|
||||
val bankBName = CordaX500Name("BankB", "Zurich", "CH")
|
||||
@ -74,11 +74,7 @@ class AttachmentLoadingTests {
|
||||
// Copy the app jar to the first node. The second won't have it.
|
||||
val path = (baseDirectory(nodeName) / "cordapps").createDirectories() / "isolated.jar"
|
||||
logger.info("Installing isolated jar to $path")
|
||||
isolatedJAR.openStream().buffered().use { input ->
|
||||
Files.newOutputStream(path).buffered().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
isolatedJAR.openStream().use { it.copyTo(path) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
import kotlin.streams.toList
|
||||
|
||||
class NetworkMapTest {
|
||||
@Rule
|
||||
@ -197,7 +196,7 @@ class NetworkMapTest {
|
||||
// Make sure the nodes aren't getting the node infos from their additional directories
|
||||
val nodeInfosDir = baseDirectory / CordformNode.NODE_INFO_DIRECTORY
|
||||
if (nodeInfosDir.exists()) {
|
||||
assertThat(nodeInfosDir.list { it.toList() }).isEmpty()
|
||||
assertThat(nodeInfosDir.list()).isEmpty()
|
||||
}
|
||||
assertThat(rpc.networkMapSnapshot()).containsOnly(*nodes)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.google.common.jimfs.Jimfs
|
||||
import net.corda.cordform.CordformNode
|
||||
import net.corda.core.internal.createDirectories
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.size
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.services.KeyManagementService
|
||||
import net.corda.nodeapi.internal.NodeInfoAndSigned
|
||||
@ -15,7 +16,6 @@ import net.corda.testing.internal.createNodeInfoAndSigned
|
||||
import net.corda.testing.node.internal.MockKeyManagementService
|
||||
import net.corda.testing.node.makeTestIdentityService
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.contentOf
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -65,9 +65,9 @@ class NodeInfoWatcherTest {
|
||||
assertEquals(1, nodeInfoFiles.size)
|
||||
val fileName = nodeInfoFiles.first()
|
||||
assertTrue(fileName.startsWith(NodeInfoFilesCopier.NODE_INFO_FILE_NAME_PREFIX))
|
||||
val file = (tempFolder.root.path / fileName).toFile()
|
||||
val file = (tempFolder.root.path / fileName)
|
||||
// Just check that something is written, another tests verifies that the written value can be read back.
|
||||
assertThat(contentOf(file)).isNotEmpty()
|
||||
assertThat(file.size).isGreaterThan(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,7 +93,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() {
|
||||
val legalName = CordaX500Name("MegaCorp", "London", "GB")
|
||||
certificatesDirectory.createDirectories()
|
||||
if (!trustStoreFile.exists()) {
|
||||
javaClass.classLoader.getResourceAsStream("certificates/cordatruststore.jks").copyTo(trustStoreFile)
|
||||
javaClass.classLoader.getResourceAsStream("certificates/cordatruststore.jks").use { it.copyTo(trustStoreFile) }
|
||||
}
|
||||
|
||||
val clientKeyPair = Crypto.generateKeyPair(X509Utilities.DEFAULT_TLS_SIGNATURE_SCHEME)
|
||||
|
@ -2,33 +2,34 @@ package net.corda.node.internal.cordapp
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import java.io.File
|
||||
import net.corda.core.internal.createDirectories
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.exists
|
||||
import net.corda.core.internal.isDirectory
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
class CordappConfigFileProvider(val configDir: File = DEFAULT_CORDAPP_CONFIG_DIR) : CordappConfigProvider {
|
||||
class CordappConfigFileProvider(private val configDir: Path = DEFAULT_CORDAPP_CONFIG_DIR) : CordappConfigProvider {
|
||||
companion object {
|
||||
val DEFAULT_CORDAPP_CONFIG_DIR = File("cordapps/config")
|
||||
val CONFIG_EXT = ".conf"
|
||||
val logger = loggerFor<CordappConfigFileProvider>()
|
||||
val DEFAULT_CORDAPP_CONFIG_DIR = Paths.get("cordapps") / "config"
|
||||
const val CONFIG_EXT = ".conf"
|
||||
val logger = contextLogger()
|
||||
}
|
||||
|
||||
init {
|
||||
configDir.mkdirs()
|
||||
configDir.createDirectories()
|
||||
}
|
||||
|
||||
override fun getConfigByName(name: String): Config {
|
||||
val configFile = File(configDir, name + CONFIG_EXT)
|
||||
val configFile = configDir / "$name$CONFIG_EXT"
|
||||
return if (configFile.exists()) {
|
||||
if (configFile.isDirectory) {
|
||||
throw IllegalStateException("File at ${configFile.absolutePath} is a directory, expected a config file")
|
||||
} else {
|
||||
logger.info("Found config for cordapp $name in ${configFile.absolutePath}")
|
||||
ConfigFactory.parseFile(configFile)
|
||||
}
|
||||
check(!configFile.isDirectory()) { "${configFile.toAbsolutePath()} is a directory, expected a config file" }
|
||||
logger.info("Found config for cordapp $name in ${configFile.toAbsolutePath()}")
|
||||
ConfigFactory.parseFile(configFile.toFile())
|
||||
} else {
|
||||
logger.info("No config found for cordapp $name in ${configFile.absolutePath}")
|
||||
logger.info("No config found for cordapp $name in ${configFile.toAbsolutePath()}")
|
||||
ConfigFactory.empty()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,15 +20,13 @@ import net.corda.node.services.config.NodeConfiguration
|
||||
import net.corda.nodeapi.internal.coreContractClasses
|
||||
import net.corda.nodeapi.internal.serialization.DefaultWhitelist
|
||||
import org.apache.commons.collections4.map.LRUMap
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.lang.reflect.Modifier
|
||||
import java.net.JarURLConnection
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.attribute.FileTime
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
@ -78,8 +76,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
||||
* Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath
|
||||
* and cordapps directory. This is intended mostly for use by the driver.
|
||||
*
|
||||
* @param baseDir See [createDefault.baseDir]
|
||||
* @param testPackages See [createWithTestPackages.testPackages]
|
||||
* @param testPackages See [createWithTestPackages]
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun createDefaultWithTestPackages(configuration: NodeConfiguration, testPackages: List<String>): CordappLoader {
|
||||
@ -129,31 +126,26 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
||||
}
|
||||
|
||||
/** Takes a package of classes and creates a JAR from them - only use in tests. */
|
||||
private fun createDevCordappJar(scanPackage: String, path: URL, jarPackageName: String): URI {
|
||||
if (!generatedCordapps.contains(path)) {
|
||||
val cordappDir = File("build/tmp/generated-test-cordapps")
|
||||
cordappDir.mkdirs()
|
||||
val cordappJAR = File(cordappDir, "$scanPackage-${UUID.randomUUID()}.jar")
|
||||
private fun createDevCordappJar(scanPackage: String, url: URL, jarPackageName: String): URI {
|
||||
return generatedCordapps.computeIfAbsent(url) {
|
||||
val cordappDir = (Paths.get("build") / "tmp" / "generated-test-cordapps").createDirectories()
|
||||
val cordappJAR = cordappDir / "$scanPackage-${UUID.randomUUID()}.jar"
|
||||
logger.info("Generating a test-only cordapp of classes discovered in $scanPackage at $cordappJAR")
|
||||
FileOutputStream(cordappJAR).use {
|
||||
JarOutputStream(it).use { jos ->
|
||||
val scanDir = File(path.toURI())
|
||||
scanDir.walkTopDown().forEach {
|
||||
val entryPath = jarPackageName + "/" + scanDir.toPath().relativize(it.toPath()).toString().replace('\\', '/')
|
||||
val time = FileTime.from(Instant.EPOCH)
|
||||
val entry = ZipEntry(entryPath).setCreationTime(time).setLastAccessTime(time).setLastModifiedTime(time)
|
||||
jos.putNextEntry(entry)
|
||||
if (it.isFile) {
|
||||
Files.copy(it.toPath(), jos)
|
||||
}
|
||||
jos.closeEntry()
|
||||
JarOutputStream(cordappJAR.outputStream()).use { jos ->
|
||||
val scanDir = url.toPath()
|
||||
scanDir.walk { it.forEach {
|
||||
val entryPath = "$jarPackageName/${scanDir.relativize(it).toString().replace('\\', '/')}"
|
||||
val time = FileTime.from(Instant.EPOCH)
|
||||
val entry = ZipEntry(entryPath).setCreationTime(time).setLastAccessTime(time).setLastModifiedTime(time)
|
||||
jos.putNextEntry(entry)
|
||||
if (it.isRegularFile()) {
|
||||
it.copyTo(jos)
|
||||
}
|
||||
}
|
||||
jos.closeEntry()
|
||||
} }
|
||||
}
|
||||
generatedCordapps[path] = cordappJAR.toURI()
|
||||
cordappJAR.toUri()
|
||||
}
|
||||
|
||||
return generatedCordapps[path]!!
|
||||
}
|
||||
|
||||
private fun getCordappsInDirectory(cordappsDir: Path): List<RestrictedURL> {
|
||||
|
@ -32,7 +32,6 @@ import net.corda.nodeapi.internal.persistence.contextTransactionOrNull
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.IOException
|
||||
import java.nio.file.Paths
|
||||
import java.sql.SQLException
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
@ -576,7 +575,7 @@ val Class<out FlowLogic<*>>.flowVersionAndInitiatingClass: Pair<Int, Class<out F
|
||||
|
||||
val Class<out FlowLogic<*>>.appName: String
|
||||
get() {
|
||||
val jarFile = Paths.get(protectionDomain.codeSource.location.toURI())
|
||||
val jarFile = protectionDomain.codeSource.location.toPath()
|
||||
return if (jarFile.isRegularFile() && jarFile.toString().endsWith(".jar")) {
|
||||
jarFile.fileName.toString().removeSuffix(".jar")
|
||||
} else {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.corda.node.services.transactions
|
||||
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.writer
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.core.utilities.debug
|
||||
import java.io.FileWriter
|
||||
import java.io.PrintWriter
|
||||
import java.net.InetAddress
|
||||
import java.net.Socket
|
||||
@ -48,7 +48,7 @@ class BFTSMaRtConfig(private val replicaAddresses: List<NetworkHostAndPort>, deb
|
||||
|
||||
private fun configWriter(name: String, block: PrintWriter.() -> Unit) {
|
||||
// Default charset, consistent with loaders:
|
||||
FileWriter((path / name).toFile()).use {
|
||||
(path / name).writer().use {
|
||||
PrintWriter(it).use {
|
||||
it.run(block)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.corda.node.services.transactions
|
||||
|
||||
import net.corda.core.internal.deleteRecursively
|
||||
import net.corda.core.internal.uncheckedCast
|
||||
import net.corda.nodeapi.internal.addShutdownHook
|
||||
import java.io.Closeable
|
||||
@ -9,7 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
private class DeleteOnExitPath(internal val path: Path) {
|
||||
private val shutdownHook = addShutdownHook { dispose() }
|
||||
internal fun dispose() {
|
||||
path.toFile().deleteRecursively()
|
||||
path.deleteRecursively()
|
||||
shutdownHook.cancel()
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class RaftUniquenessProvider(
|
||||
get() = _clientFuture.get()
|
||||
|
||||
fun start() {
|
||||
log.info("Creating Copycat server, log stored in: ${storagePath.toFile()}")
|
||||
log.info("Creating Copycat server, log stored in: ${storagePath.toAbsolutePath()}")
|
||||
val stateMachineFactory = {
|
||||
RaftTransactionCommitLog(db, clock, RaftUniquenessProvider.Companion::createMap)
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package net.corda.node.utilities
|
||||
import com.ea.agentloader.AgentLoader
|
||||
import net.corda.core.internal.exists
|
||||
import net.corda.core.internal.isRegularFile
|
||||
import net.corda.core.internal.toPath
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
@ -43,7 +45,7 @@ object JVMAgentRegistry {
|
||||
} else {
|
||||
(this::class.java.classLoader as? URLClassLoader)
|
||||
?.urLs
|
||||
?.map { Paths.get(it.toURI()) }
|
||||
?.map(URL::toPath)
|
||||
?.firstOrNull { it.fileName.toString() == jarFileName }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.node
|
||||
|
||||
import joptsimple.OptionException
|
||||
import net.corda.core.internal.delete
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.nodeapi.internal.crypto.X509KeyStore
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -8,7 +9,6 @@ import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.slf4j.event.Level
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.test.assertEquals
|
||||
@ -140,7 +140,7 @@ class ArgsParserTest {
|
||||
assertEquals(truststorePath.toAbsolutePath(), cmdLineOptions.nodeRegistrationOption?.networkRootTrustStorePath)
|
||||
assertEquals("password-test", cmdLineOptions.nodeRegistrationOption?.networkRootTrustStorePassword)
|
||||
} finally {
|
||||
Files.delete(truststorePath)
|
||||
truststorePath.delete()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,10 @@ package net.corda.node.internal
|
||||
import com.nhaarman.mockito_kotlin.doReturn
|
||||
import com.nhaarman.mockito_kotlin.whenever
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.internal.delete
|
||||
import net.corda.core.internal.list
|
||||
import net.corda.core.internal.readObject
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.node.VersionInfo
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
@ -18,7 +19,7 @@ import net.corda.testing.node.MockServices.Companion.makeTestDataSourcePropertie
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
@ -32,14 +33,21 @@ class NodeTest {
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
private fun nodeInfoFile() = temporaryFolder.root.listFiles().singleOrNull { it.name.startsWith(NODE_INFO_FILE_NAME_PREFIX) }
|
||||
private fun nodeInfoFile(): Path? {
|
||||
return temporaryFolder.root.toPath().list { paths ->
|
||||
paths.filter { it.fileName.toString().startsWith(NODE_INFO_FILE_NAME_PREFIX) }.findAny().orElse(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun AbstractNode.generateNodeInfo(): NodeInfo {
|
||||
assertNull(nodeInfoFile())
|
||||
generateAndSaveNodeInfo()
|
||||
val path = nodeInfoFile()!!.toPath()
|
||||
val nodeInfo = path.readObject<SignedNodeInfo>().raw.deserialize()
|
||||
Files.delete(path)
|
||||
return nodeInfo
|
||||
val path = nodeInfoFile()!!
|
||||
try {
|
||||
return path.readObject<SignedNodeInfo>().verified()
|
||||
} finally {
|
||||
path.delete()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user