diff --git a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt index 8101b82096..023ceb92f3 100644 --- a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt +++ b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt @@ -12,6 +12,7 @@ import net.corda.testing.http.HttpApi import net.corda.vega.api.PortfolioApi import net.corda.vega.api.PortfolioApiUtils import net.corda.vega.api.SwapDataModel +import net.corda.vega.api.SwapDataView import net.corda.vega.portfolio.Portfolio import org.junit.Test import java.math.BigDecimal @@ -25,6 +26,7 @@ class SimmValuationTest: IntegrationTestCategory { val valuationDate = LocalDate.parse("2016-06-06") val nodeALegalName = "Bank A" val nodeBLegalName = "Bank B" + val testTradeId = "trade1" } @Test fun `runs SIMM valuation demo`() { @@ -35,8 +37,8 @@ class SimmValuationTest: IntegrationTestCategory { val nodeBParty = getPartyWithName(nodeA, nodeBLegalName) val nodeAParty = getPartyWithName(nodeB, nodeALegalName) - assert(createTradeBetween(nodeA, nodeBParty)) - assert(tradeExists(nodeB, nodeAParty)) + assert(createTradeBetween(nodeA, nodeBParty, testTradeId)) + assert(tradeExists(nodeB, nodeAParty, testTradeId)) assert(runValuationsBetween(nodeA, nodeBParty)) assert(valuationExists(nodeB, nodeAParty)) } @@ -54,15 +56,15 @@ class SimmValuationTest: IntegrationTestCategory { return api.getJson("whoami") } - private fun createTradeBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean { - val trade = SwapDataModel("trade1", "desc", valuationDate, "EUR_FIXED_1Y_EURIBOR_3M", + private fun createTradeBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty, tradeId: String): Boolean { + val trade = SwapDataModel(tradeId, "desc", valuationDate, "EUR_FIXED_1Y_EURIBOR_3M", valuationDate, LocalDate.parse("2020-01-02"), BuySell.BUY, BigDecimal.valueOf(1000), BigDecimal.valueOf(0.1)) return api.putJson("${counterparty.id}/trades", trade) } - private fun tradeExists(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean { - val trades = api.getJson>>("${counterparty.id}/trades") - return (!trades.isEmpty()) + private fun tradeExists(api: HttpApi, counterparty: PortfolioApi.ApiParty, tradeId: String): Boolean { + val trades = api.getJson>("${counterparty.id}/trades") + return (trades.find { it.id == tradeId } != null) } private fun runValuationsBetween(api: HttpApi, counterparty: PortfolioApi.ApiParty): Boolean { diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt index 6a9ffd6482..9105fc2d11 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt @@ -115,15 +115,21 @@ class PortfolioApiUtils(private val ownParty: Party) { ) } - fun createTradeView(state: IRSState): Any { + data class TradeView( + val fixedLeg: Map, + val floatingLeg: Map, + val common: Map, + val ref: String) + + fun createTradeView(state: IRSState): TradeView { val trade = if (state.buyer.name == ownParty.name) state.swap.toFloatingLeg() else state.swap.toFloatingLeg() val fixedLeg = trade.product.legs.first { it.type == SwapLegType.FIXED } as RateCalculationSwapLeg val floatingLeg = trade.product.legs.first { it.type != SwapLegType.FIXED } as RateCalculationSwapLeg val fixedRate = fixedLeg.calculation as FixedRateCalculation val floatingRate = floatingLeg.calculation as IborRateCalculation - return mapOf( - "fixedLeg" to mapOf( + return TradeView( + fixedLeg = mapOf( "fixedRatePayer" to state.buyer.name, "notional" to mapOf( "token" to fixedLeg.currency.code, @@ -139,7 +145,7 @@ class PortfolioApiUtils(private val ownParty: Party) { "calendar" to listOf("TODO"), "paymentCalendar" to mapOf() // TODO ), - "floatingLeg" to mapOf( + floatingLeg = mapOf( "floatingRatePayer" to state.seller.name, "notional" to mapOf( "token" to floatingLeg.currency.code, @@ -154,7 +160,7 @@ class PortfolioApiUtils(private val ownParty: Party) { "paymentCalendar" to listOf("TODO"), "fixingCalendar" to mapOf() // TODO ), - "common" to mapOf( + common = mapOf( "valuationDate" to trade.product.startDate.unadjusted, "hashLegalDocs" to state.contract.legalContractReference.toString(), "interestRate" to mapOf( @@ -165,7 +171,7 @@ class PortfolioApiUtils(private val ownParty: Party) { ) ) ), - "ref" to trade.info.id.get().value + ref = trade.info.id.get().value ) } }