forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request corda#1053 from corda/kit-getServiceOf
Extending NetwokMapCache with a convenience method for by type servic…
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
node/src/integration-test/kotlin/net/corda/node/services/AdvertisedServiceTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.corda.node.services | ||
|
||
import co.paralleluniverse.fibers.Suspendable | ||
import net.corda.core.flows.FlowLogic | ||
import net.corda.core.flows.StartableByRPC | ||
import net.corda.core.messaging.startFlow | ||
import net.corda.core.node.services.ServiceInfo | ||
import net.corda.core.node.services.ServiceType | ||
import net.corda.nodeapi.User | ||
import net.corda.testing.driver.driver | ||
import org.bouncycastle.asn1.x500.X500Name | ||
import org.junit.Test | ||
import kotlin.test.assertTrue | ||
|
||
class AdvertisedServiceTests { | ||
private val serviceName = X500Name("CN=Custom Service,O=R3,OU=corda,L=London,C=GB") | ||
private val serviceType = ServiceType.corda.getSubType("custom") | ||
private val user = "bankA" | ||
private val pass = "passA" | ||
|
||
|
||
@StartableByRPC | ||
class ServiceTypeCheckingFlow : FlowLogic<Boolean>() { | ||
|
||
@Suspendable | ||
override fun call(): Boolean { | ||
return serviceHub.networkMapCache.getAnyServiceOfType(ServiceType.corda.getSubType("custom")) != null; | ||
} | ||
} | ||
|
||
@Test | ||
fun `service is accessible through getAnyServiceOfType`() { | ||
driver(startNodesInProcess = true) { | ||
val bankA = startNode(rpcUsers = listOf(User(user, pass, setOf(startFlowPermission<ServiceTypeCheckingFlow>())))).get() | ||
val bankB = startNode(advertisedServices = setOf(ServiceInfo(serviceType, serviceName))).get() | ||
bankA.rpcClientToNode().use(user, pass) { connection -> | ||
val result = connection.proxy.startFlow(::ServiceTypeCheckingFlow).returnValue.get() | ||
assertTrue(result) | ||
} | ||
} | ||
} | ||
} |