mirror of
https://github.com/corda/corda.git
synced 2025-02-04 02:01:13 +00:00
Fix unit tests causing problems on windows
This commit is contained in:
parent
a47a45037d
commit
8f1d58a508
@ -149,7 +149,7 @@ class AttachmentClassLoaderTests {
|
|||||||
val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data")))
|
val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data")))
|
||||||
|
|
||||||
val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! })
|
val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! })
|
||||||
val txt = IOUtils.toString(cl.getResourceAsStream("file1.txt"))
|
val txt = IOUtils.toString(cl.getResourceAsStream("file1.txt"), Charsets.UTF_8.name())
|
||||||
assertEquals("some data", txt)
|
assertEquals("some data", txt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.node.utilities.registration
|
package net.corda.node.utilities.registration
|
||||||
|
|
||||||
|
import com.google.common.net.MediaType
|
||||||
import net.corda.core.crypto.CertificateStream
|
import net.corda.core.crypto.CertificateStream
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest
|
||||||
@ -50,7 +51,7 @@ class HTTPNetworkRegistrationService(val server: URL) : NetworkRegistrationServi
|
|||||||
conn.outputStream.write(request.encoded)
|
conn.outputStream.write(request.encoded)
|
||||||
|
|
||||||
return when (conn.responseCode) {
|
return when (conn.responseCode) {
|
||||||
HTTP_OK -> IOUtils.toString(conn.inputStream)
|
HTTP_OK -> IOUtils.toString(conn.inputStream, conn.charset)
|
||||||
HTTP_FORBIDDEN -> throw IOException("Client version $clientVersion is forbidden from accessing permissioning server, please upgrade to newer version.")
|
HTTP_FORBIDDEN -> throw IOException("Client version $clientVersion is forbidden from accessing permissioning server, please upgrade to newer version.")
|
||||||
else -> throwUnexpectedResponseCode(conn)
|
else -> throwUnexpectedResponseCode(conn)
|
||||||
}
|
}
|
||||||
@ -60,5 +61,7 @@ class HTTPNetworkRegistrationService(val server: URL) : NetworkRegistrationServi
|
|||||||
throw IOException("Unexpected response code ${connection.responseCode} - ${connection.errorMessage}")
|
throw IOException("Unexpected response code ${connection.responseCode} - ${connection.errorMessage}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private val HttpURLConnection.errorMessage: String get() = IOUtils.toString(errorStream)
|
private val HttpURLConnection.charset: String get() = MediaType.parse(getContentType()).charset().or(Charsets.UTF_8).name()
|
||||||
|
|
||||||
|
private val HttpURLConnection.errorMessage: String get() = IOUtils.toString(errorStream, charset)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
alice = second
|
alice = second
|
||||||
}
|
}
|
||||||
network.runNetwork()
|
network.runNetwork()
|
||||||
|
lastSerial = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -197,10 +198,18 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
return response.getOrThrow().node
|
return response.getOrThrow().node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastSerial = Long.MIN_VALUE
|
||||||
|
|
||||||
private fun MockNode.registration(addOrRemove: AddOrRemove,
|
private fun MockNode.registration(addOrRemove: AddOrRemove,
|
||||||
serial: Long = System.currentTimeMillis()): ListenableFuture<RegistrationResponse> {
|
serial: Long? = null): ListenableFuture<RegistrationResponse> {
|
||||||
|
val distinctSerial = if (serial == null) {
|
||||||
|
++lastSerial
|
||||||
|
} else {
|
||||||
|
lastSerial = serial
|
||||||
|
serial
|
||||||
|
}
|
||||||
val expires = Instant.now() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
val expires = Instant.now() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||||
val nodeRegistration = NodeRegistration(info, serial, addOrRemove, expires)
|
val nodeRegistration = NodeRegistration(info, distinctSerial, addOrRemove, expires)
|
||||||
val request = RegistrationRequest(nodeRegistration.toWire(services.legalIdentityKey.private), info.address)
|
val request = RegistrationRequest(nodeRegistration.toWire(services.legalIdentityKey.private), info.address)
|
||||||
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
network.runNetwork()
|
||||||
@ -235,6 +244,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
private fun addNewNodeToNetworkMap(legalName: String): MockNode {
|
private fun addNewNodeToNetworkMap(legalName: String): MockNode {
|
||||||
val node = network.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
|
val node = network.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
|
||||||
network.runNetwork()
|
network.runNetwork()
|
||||||
|
lastSerial = System.currentTimeMillis()
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,14 +74,14 @@ class IRSDemoTest : IntegrationTestCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun runTrade(nodeAddr: HostAndPort, fixedRatePayer: Party, floatingRatePayer: Party) {
|
private fun runTrade(nodeAddr: HostAndPort, fixedRatePayer: Party, floatingRatePayer: Party) {
|
||||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"))
|
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"), Charsets.UTF_8.name())
|
||||||
val tradeFile = fileContents.replace("tradeXXX", "trade1")
|
val tradeFile = fileContents.replace("tradeXXX", "trade1")
|
||||||
val url = URL("http://$nodeAddr/api/irs/deals")
|
val url = URL("http://$nodeAddr/api/irs/deals")
|
||||||
assert(postJson(url, tradeFile))
|
assert(postJson(url, tradeFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runUploadRates(host: HostAndPort) {
|
private fun runUploadRates(host: HostAndPort) {
|
||||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
|
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"), Charsets.UTF_8.name())
|
||||||
val url = URL("http://$host/upload/interest-rates")
|
val url = URL("http://$host/upload/interest-rates")
|
||||||
assert(uploadFile(url, fileContents))
|
assert(uploadFile(url, fileContents))
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class IRSDemoClientApi(private val hostAndPort: HostAndPort) {
|
|||||||
private val api = HttpApi.fromHostAndPort(hostAndPort, apiRoot)
|
private val api = HttpApi.fromHostAndPort(hostAndPort, apiRoot)
|
||||||
|
|
||||||
fun runTrade(tradeId: String): Boolean {
|
fun runTrade(tradeId: String): Boolean {
|
||||||
val fileContents = IOUtils.toString(javaClass.classLoader.getResourceAsStream("example-irs-trade.json"))
|
val fileContents = IOUtils.toString(javaClass.classLoader.getResourceAsStream("example-irs-trade.json"), Charsets.UTF_8.name())
|
||||||
val tradeFile = fileContents.replace("tradeXXX", tradeId)
|
val tradeFile = fileContents.replace("tradeXXX", tradeId)
|
||||||
return api.postJson("deals", tradeFile)
|
return api.postJson("deals", tradeFile)
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ class IRSDemoClientApi(private val hostAndPort: HostAndPort) {
|
|||||||
|
|
||||||
// TODO: Add uploading of files to the HTTP API
|
// TODO: Add uploading of files to the HTTP API
|
||||||
fun runUploadRates() {
|
fun runUploadRates() {
|
||||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
|
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"), Charsets.UTF_8.name())
|
||||||
val url = URL("http://$hostAndPort/upload/interest-rates")
|
val url = URL("http://$hostAndPort/upload/interest-rates")
|
||||||
assert(uploadFile(url, fileContents))
|
assert(uploadFile(url, fileContents))
|
||||||
}
|
}
|
||||||
|
@ -37,5 +37,6 @@ private fun makeRequest(request: Request): Boolean {
|
|||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
println("Could not fulfill HTTP request. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
println("Could not fulfill HTTP request. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
||||||
}
|
}
|
||||||
|
response.close()
|
||||||
return response.isSuccessful
|
return response.isSuccessful
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user