Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 我们可以嘲笑吗;CordaRPCops“;在Cordapp中进行测试?_Spring Boot_Kotlin_Testing_Mocking_Corda - Fatal编程技术网

Spring boot 我们可以嘲笑吗;CordaRPCops“;在Cordapp中进行测试?

Spring boot 我们可以嘲笑吗;CordaRPCops“;在Cordapp中进行测试?,spring-boot,kotlin,testing,mocking,corda,Spring Boot,Kotlin,Testing,Mocking,Corda,是否可以模拟CordaRPCops,以便在项目中执行流,而不创建独立节点或内存节点(如在模拟网络中)?请让我知道 在TestDSL中没有可用的特定类mockCordaRPCops。如果您指的是模拟cordapp测试节点的某些功能,则应使用MockNode 如果您想在客户端应用程序中模拟CordaRPCops,可以使用mockito进行模拟,示例如下: 测试: @Test public void testGetStateList(){ CordaRPCOps cordaRPCOps = M

是否可以模拟CordaRPCops,以便在项目中执行流,而不创建独立节点或内存节点(如在模拟网络中)?请让我知道


TestDSL
中没有可用的特定类mock
CordaRPCops
。如果您指的是模拟cordapp测试节点的某些功能,则应使用MockNode

如果您想在客户端应用程序中模拟
CordaRPCops
,可以使用mockito进行模拟,示例如下:

测试:

@Test
public void testGetStateList(){
    CordaRPCOps cordaRPCOps = Mockito.mock(CordaRPCOps.class);
    Service service = new Service(cordaRPCOps);
    Vault.Page<MyState> myStatePage =
            new Vault.Page<>(Collections.EMPTY_LIST, Collections.EMPTY_LIST, 0L, Vault.StateStatus.ALL, Collections.EMPTY_LIST);
    Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
    service.getStateList();
}
public class Service {
    CordaRPCOps cordaRPCOps;

    public Service(CordaRPCOps cordaRPCOps) {
        this.cordaRPCOps = cordaRPCOps;
    }

    public List<StateAndRef<MyState>> getStateList() {
        return cordaRPCOps.vaultQuery(MyState.class).getStates();
    }
}
@测试
public void testGetStateList(){
CordaRPCOps CordaRPCOps=Mockito.mock(CordaRPCOps.class);
服务=新服务(cordaRPCOps);
Vault.Page myStatePage=
新建Vault.Page(Collections.EMPTY_LIST,Collections.EMPTY_LIST,0L,Vault.StateStatus.ALL,Collections.EMPTY_LIST);
Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
getStateList();
}
服务:

@Test
public void testGetStateList(){
    CordaRPCOps cordaRPCOps = Mockito.mock(CordaRPCOps.class);
    Service service = new Service(cordaRPCOps);
    Vault.Page<MyState> myStatePage =
            new Vault.Page<>(Collections.EMPTY_LIST, Collections.EMPTY_LIST, 0L, Vault.StateStatus.ALL, Collections.EMPTY_LIST);
    Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
    service.getStateList();
}
public class Service {
    CordaRPCOps cordaRPCOps;

    public Service(CordaRPCOps cordaRPCOps) {
        this.cordaRPCOps = cordaRPCOps;
    }

    public List<StateAndRef<MyState>> getStateList() {
        return cordaRPCOps.vaultQuery(MyState.class).getStates();
    }
}
公共类服务{
CordaRPCOps CordaRPCOps;
公共服务(CordaRPCOps CordaRPCOps){
this.cordaRPCOps=cordaRPCOps;
}
公共列表getStateList(){
返回cordaRPCOps.vaultQuery(MyState.class).getStates();
}
}

TestDSL
中没有可用的特定类mock
CordaRPCops
。如果您指的是模拟cordapp测试节点的某些功能,则应使用MockNode

如果您想在客户端应用程序中模拟
CordaRPCops
,可以使用mockito进行模拟,示例如下:

测试:

@Test
public void testGetStateList(){
    CordaRPCOps cordaRPCOps = Mockito.mock(CordaRPCOps.class);
    Service service = new Service(cordaRPCOps);
    Vault.Page<MyState> myStatePage =
            new Vault.Page<>(Collections.EMPTY_LIST, Collections.EMPTY_LIST, 0L, Vault.StateStatus.ALL, Collections.EMPTY_LIST);
    Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
    service.getStateList();
}
public class Service {
    CordaRPCOps cordaRPCOps;

    public Service(CordaRPCOps cordaRPCOps) {
        this.cordaRPCOps = cordaRPCOps;
    }

    public List<StateAndRef<MyState>> getStateList() {
        return cordaRPCOps.vaultQuery(MyState.class).getStates();
    }
}
@测试
public void testGetStateList(){
CordaRPCOps CordaRPCOps=Mockito.mock(CordaRPCOps.class);
服务=新服务(cordaRPCOps);
Vault.Page myStatePage=
新建Vault.Page(Collections.EMPTY_LIST,Collections.EMPTY_LIST,0L,Vault.StateStatus.ALL,Collections.EMPTY_LIST);
Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
getStateList();
}
服务:

@Test
public void testGetStateList(){
    CordaRPCOps cordaRPCOps = Mockito.mock(CordaRPCOps.class);
    Service service = new Service(cordaRPCOps);
    Vault.Page<MyState> myStatePage =
            new Vault.Page<>(Collections.EMPTY_LIST, Collections.EMPTY_LIST, 0L, Vault.StateStatus.ALL, Collections.EMPTY_LIST);
    Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
    service.getStateList();
}
public class Service {
    CordaRPCOps cordaRPCOps;

    public Service(CordaRPCOps cordaRPCOps) {
        this.cordaRPCOps = cordaRPCOps;
    }

    public List<StateAndRef<MyState>> getStateList() {
        return cordaRPCOps.vaultQuery(MyState.class).getStates();
    }
}
公共类服务{
CordaRPCOps CordaRPCOps;
公共服务(CordaRPCOps CordaRPCOps){
this.cordaRPCOps=cordaRPCOps;
}
公共列表getStateList(){
返回cordaRPCOps.vaultQuery(MyState.class).getStates();
}
}

谢谢@Ashutosh。你能分享任何实现这个的github应用程序吗?啊。。。我刚刚编写了代码片段进行演示,让我检查一下是否有任何公共repo具有客户端测试类。谢谢@Ashutosh。你能分享任何实现这个的github应用程序吗?啊。。。我刚刚编写了代码片段进行演示,让我检查一下是否有任何具有客户机测试类的公共repo。