mirror of
https://github.com/corda/corda.git
synced 2025-06-22 00:57:21 +00:00
Added test contents with a couple of todos.
This commit is contained in:
committed by
Clinton Alexander
parent
2334824a73
commit
6be21c7da4
@ -1,24 +1,44 @@
|
|||||||
package net.corda.vega
|
package net.corda.vega
|
||||||
|
|
||||||
|
import net.corda.core.getOrThrow
|
||||||
|
import net.corda.core.node.services.ServiceInfo
|
||||||
|
import net.corda.node.driver.driver
|
||||||
|
import net.corda.node.services.transactions.SimpleNotaryService
|
||||||
|
import net.corda.testing.IntegrationTestCategory
|
||||||
|
import net.corda.testing.getHostAndPort
|
||||||
|
import net.corda.testing.http.HttpApi
|
||||||
|
import net.corda.vega.api.PortfolioApi
|
||||||
|
import net.corda.vega.portfolio.Portfolio
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
class SimmValuationTest: IntegrationTestCategory {
|
class SimmValuationTest: IntegrationTestCategory {
|
||||||
|
|
||||||
@Test fun `runs SIMM valuation demo`() {
|
@Test fun `runs SIMM valuation demo`() {
|
||||||
driver(isDebug = true) {
|
driver(isDebug = true) {
|
||||||
|
val nodeBLegalName = "Bank B"
|
||||||
val controller = startNode("Controller", setOf(ServiceInfo(SimpleNotaryService.type))).getOrThrow()
|
val controller = startNode("Controller", setOf(ServiceInfo(SimpleNotaryService.type))).getOrThrow()
|
||||||
val nodeA = startNode("Bank A").getOrThrow()
|
val nodeAAddr = startNode("Bank A").getOrThrow().config.getHostAndPort("webAddress")
|
||||||
val nodeB = startNode("Bank B").getOrThrow()
|
val nodeBAddr = startNode(nodeBLegalName).getOrThrow().config.getHostAndPort("webAddress")
|
||||||
assert(createTrade())
|
|
||||||
assert(runValuations())
|
val nodeA = HttpApi.fromHostAndPort(nodeAAddr, "simmvaluationdemo")
|
||||||
|
|
||||||
|
val parties = getAvailablePartiesFor(nodeA)
|
||||||
|
val nodeB = parties.counterparties.single { it.text == nodeBLegalName}
|
||||||
|
assert(createTradeBetween(nodeA, nodeB))
|
||||||
|
assert(runValuationsBetween(nodeA, nodeB))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getAvailablePartiesFor(api: HttpApi): PortfolioApi.AvailableParties {
|
||||||
|
return api.getJson<PortfolioApi.AvailableParties>("whoami")
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: create, verify, run, verify or determine a better test structure.
|
// TODO: create, verify, run, verify or determine a better test structure.
|
||||||
private fun createTrade(): Boolean {
|
private fun createTradeBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean {
|
||||||
|
return api.postJson("{$counterparty.id}/trades", mapOf("a" to "a"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runValuations(): Boolean {
|
private fun runValuationsBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean {
|
||||||
|
return api.postJson("{$counterparty.id/trade/TODO/valuations/calculate")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -239,28 +239,23 @@ class PortfolioApi(val rpc: CordaRPCOps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ApiParty(val id: String, val text: String)
|
||||||
|
data class AvailableParties(val self: ApiParty, val counterparties: List<ApiParty>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the identity of the current node as well as a list of other counterparties that it is aware of.
|
* Returns the identity of the current node as well as a list of other counterparties that it is aware of.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("whoami")
|
@Path("whoami")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
fun getWhoAmI(): Any {
|
fun getWhoAmI(): AvailableParties {
|
||||||
val counterParties = rpc.networkMapUpdates().first.filter { it.legalIdentity.name != "NetworkMapService" && it.legalIdentity.name != "Notary" && it.legalIdentity.name != ownParty.name }
|
val counterParties = rpc.networkMapUpdates().first.filter {
|
||||||
return json {
|
it.legalIdentity.name != "NetworkMapService" && it.legalIdentity.name != "Notary" && it.legalIdentity.name != ownParty.name
|
||||||
obj(
|
|
||||||
"self" to obj(
|
|
||||||
"id" to ownParty.owningKey.toBase58String(),
|
|
||||||
"text" to ownParty.name
|
|
||||||
),
|
|
||||||
"counterparties" to counterParties.map {
|
|
||||||
obj(
|
|
||||||
"id" to it.legalIdentity.owningKey.toBase58String(),
|
|
||||||
"text" to it.legalIdentity.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return AvailableParties(
|
||||||
|
self = ApiParty(ownParty.owningKey.toBase58String(), ownParty.name),
|
||||||
|
counterparties = counterParties.map { ApiParty(it.legalIdentity.owningKey.toBase58String(), it.legalIdentity.name) })
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ValuationCreationParams(val valuationDate: LocalDate)
|
data class ValuationCreationParams(val valuationDate: LocalDate)
|
||||||
|
@ -18,7 +18,12 @@ class HttpApi(val root: URL) {
|
|||||||
*/
|
*/
|
||||||
fun postJson(path: String, data: Any = Unit) = HttpUtils.postJson(URL(root, path), toJson(data))
|
fun postJson(path: String, data: Any = Unit) = HttpUtils.postJson(URL(root, path), toJson(data))
|
||||||
|
|
||||||
private fun toJson(any: Any) = if (any is String) any else ObjectMapper().writeValueAsString(any)
|
/**
|
||||||
|
* Send a GET request to the path on the API specified.
|
||||||
|
*/
|
||||||
|
inline fun<reified T: Any> getJson(path: String, params: Map<String, String> = mapOf()) = HttpUtils.getJson<T>(URL(root, path), params)
|
||||||
|
|
||||||
|
private fun toJson(any: Any) = any as? String ?: ObjectMapper().writeValueAsString(any)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromHostAndPort(hostAndPort: HostAndPort, base: String, protocol: String = "http"): HttpApi
|
fun fromHostAndPort(hostAndPort: HostAndPort, base: String, protocol: String = "http"): HttpApi
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.testing.http
|
package net.corda.testing.http
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import net.corda.core.utilities.loggerFor
|
import net.corda.core.utilities.loggerFor
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -26,12 +27,30 @@ object HttpUtils {
|
|||||||
return makeRequest(Request.Builder().url(url).header("Content-Type", "application/json").post(body).build())
|
return makeRequest(Request.Builder().url(url).header("Content-Type", "application/json").post(body).build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun<reified T: Any> getJson(url: URL, params: Map<String, String> = mapOf()) : T {
|
||||||
|
val paramString = if(params.isEmpty()) "" else "?" + params.map { "${it.key}=${it.value}" }.joinToString("&")
|
||||||
|
val parameterisedUrl = URL(url.toExternalForm() + paramString)
|
||||||
|
return ObjectMapper().readValue(parameterisedUrl, T::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
private fun makeRequest(request: Request): Boolean {
|
private fun makeRequest(request: Request): Boolean {
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
|
|
||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
logger.error("Could not fulfill HTTP request of type ${request.method()} to ${request.url()}. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
logger.error("Could not fulfill HTTP request of type ${request.method()} to ${request.url()}. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.isSuccessful
|
return response.isSuccessful
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getRequest(request: Request): Pair<Boolean, String> {
|
||||||
|
val response = client.newCall(request).execute()
|
||||||
|
|
||||||
|
if (!response.isSuccessful) {
|
||||||
|
logger.error("Could not fulfill HTTP request of type ${request.method()} to ${request.url()}. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
||||||
|
return Pair(false, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
return Pair(true, response.body().string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user