diff --git a/README.md b/README.md index 0643771..869061e 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,11 @@ open class DemoApplicationTests { val myFlowArgs = MyFlowArgs(aliceNode.memberX500Name, bobNode.memberX500Name) val createdStatus = aliceNode.waitForFlow( FlowRequest( - flowClassName = MyFlow::class.java.canonicalName, - requestBody = myFlowArgs + flowClass = MyFlow::class.java, + requestBody = myFlowArgs, + // Either String or the type + // (here MyFlowResult) marshaled to string by the flow, + flowResultClass = MyFlowResult::class.java ) ) // Check flow status diff --git a/gradle.properties b/gradle.properties index 10a88b6..2c4e08e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.github.manosbatsis.corda5.testutils -version=1.0.3 +version=1.0.5 vendorName=Manos Batsis kotlin.code.style=official diff --git a/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandle.kt b/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandle.kt index 645e90c..5f4d60c 100644 --- a/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandle.kt +++ b/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandle.kt @@ -1,5 +1,6 @@ package com.github.manosbatsis.corda5.testutils.integration.junit5.nodehandles +import com.fasterxml.jackson.databind.ObjectMapper import com.github.manosbatsis.corda5.testutils.rest.client.FlowsClient import com.github.manosbatsis.corda5.testutils.rest.client.loggerFor import com.github.manosbatsis.corda5.testutils.rest.client.model.FlowRequest @@ -10,16 +11,24 @@ import java.util.concurrent.TimeUnit data class NodeHandle( val memberX500Name: MemberX500Name, val holdingIdentityShortHash: String, - var flowsClient: FlowsClient + var flowsClient: FlowsClient, + val objectMapper: ObjectMapper ) { companion object { private val logger = loggerFor(NodeHandle::class.java) } - fun waitForFlow(flowRequest: FlowRequest, maxWaitSec: Int = 60): FlowStatusResponse { + fun waitForFlow( + flowRequest: FlowRequest, + maxWaitSec: Int = 60 + ): FlowStatusResponse { val clientRequestId: String = flowRequest.clientRequestId - var flowStatusResponse: FlowStatusResponse = flowsClient.flow(flowRequest, holdingIdentityShortHash) + var flowStatusResponse = flowsClient.flow( + // OpenFeign won't do generics, switch to string temporarily + flowRequest.withFlowResultClass(String::class.java), + holdingIdentityShortHash + ) for (i in 0..maxWaitSec) { TimeUnit.SECONDS.sleep(1) flowStatusResponse = flowsClient.flowStatus(holdingIdentityShortHash, clientRequestId) @@ -28,6 +37,11 @@ data class NodeHandle( else -> logger.info("Non-final flow status will retry $flowStatusResponse") } } - return flowStatusResponse + + return flowStatusResponse.withFlowResult( + flowStatusResponse.flowResult?.let { + objectMapper.readValue(it, flowRequest.flowResultClass) + } + ) } } diff --git a/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandlesHelper.kt b/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandlesHelper.kt index 6979b9e..e344b2f 100644 --- a/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandlesHelper.kt +++ b/integration-junit5/src/main/kotlin/com/github/manosbatsis/corda5/testutils/integration/junit5/nodehandles/NodeHandlesHelper.kt @@ -118,7 +118,8 @@ class NodeHandlesHelper( NodeHandle( MemberX500Name.parse(it.holdingIdentity.x500Name), it.holdingIdentity.shortHash, - flowsClient + flowsClient, + objectMapper ) } return NodeHandles(nodes) diff --git a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/FlowsClient.kt b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/FlowsClient.kt index efce33d..9529211 100644 --- a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/FlowsClient.kt +++ b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/FlowsClient.kt @@ -7,14 +7,14 @@ import feign.RequestLine interface FlowsClient { @RequestLine("POST /flow/{holdingidentityshorthash}") - fun flow( - flowRequest: FlowRequest, + fun flow( + flowRequest: FlowRequest, @Param("holdingidentityshorthash") shortHash: String - ): FlowStatusResponse + ): FlowStatusResponse @RequestLine("GET /flow/{holdingidentityshorthash}/{clientrequestid}") - fun flowStatus( + fun flowStatus( @Param("holdingidentityshorthash") shortHash: String, @Param("clientrequestid") requestId: String - ): FlowStatusResponse + ): FlowStatusResponse } diff --git a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/LoggingUtil.kt b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/LoggingUtil.kt index 5f26b8d..9581e88 100644 --- a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/LoggingUtil.kt +++ b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/LoggingUtil.kt @@ -1,7 +1,7 @@ package com.github.manosbatsis.corda5.testutils.rest.client -import kotlin.reflect.full.companionObject import java.util.logging.Logger +import kotlin.reflect.full.companionObject fun loggerFor(forClass: Class<*>): Logger = Logger.getLogger( diff --git a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowRequest.kt b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowRequest.kt index 19e461e..77943da 100644 --- a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowRequest.kt +++ b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowRequest.kt @@ -1,9 +1,26 @@ package com.github.manosbatsis.corda5.testutils.rest.client.model +import com.fasterxml.jackson.annotation.JsonIgnore import java.util.* -data class FlowRequest( +data class FlowRequest( val clientRequestId: String = UUID.randomUUID().toString(), val flowClassName: String, - val requestBody: Any? -) + val requestBody: Any?, + @JsonIgnore + val flowResultClass: Class, +) { + constructor( + clientRequestId: String = UUID.randomUUID().toString(), + flowClass: Class<*>, + requestBody: Any?, + flowResultClass: Class, + ) : this(clientRequestId, flowClass.canonicalName, requestBody, flowResultClass) + + fun withFlowResultClass(other: Class) = FlowRequest( + clientRequestId = clientRequestId, + flowClassName = flowClassName, + requestBody = requestBody, + flowResultClass = other + ) +} diff --git a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowStatusResponse.kt b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowStatusResponse.kt index cb7f93a..3313e5e 100644 --- a/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowStatusResponse.kt +++ b/rest-client/src/main/kotlin/com/github/manosbatsis/corda5/testutils/rest/client/model/FlowStatusResponse.kt @@ -18,12 +18,12 @@ import java.time.Instant * @param timestamp The timestamp of when the status was last updated (in UTC) */ @JsonIgnoreProperties(ignoreUnknown = true) -data class FlowStatusResponse( +data class FlowStatusResponse( val holdingIdentityShortHash: String, val clientRequestId: String?, val flowId: String?, val flowStatus: String, - val flowResult: String?, + val flowResult: T?, val flowError: FlowStateErrorResponse?, val timestamp: Instant ) { @@ -33,6 +33,16 @@ data class FlowStatusResponse( val finalStatuses = setOf(COMPLETED, FAILED) } + fun withFlowResult(result: N?) = FlowStatusResponse( + holdingIdentityShortHash = holdingIdentityShortHash, + clientRequestId = clientRequestId, + flowId = flowId, + flowStatus = flowStatus, + flowResult = result, + flowError = flowError, + timestamp = timestamp, + ) + @JsonIgnore fun isFinal() = finalStatuses.contains(this.flowStatus)