无法调用PACT方法

时间:2018-01-29 17:07:27

标签: java pact

我有这段代码,同时尝试为我的服务创建一个pact文件,但它仍然无法调用pact方法。但是,当我运行正常的客户端请求时,它返回一个json对象,但是当尝试运行pact测试时,它会失败。以下是Test类的片段

java.lang.RuntimeException: Failed to invoke pact method

    at au.com.dius.pact.consumer.BaseProviderRule.getPacts(BaseProviderRule.java:188)
    at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:63)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at au.com.dius.pact.consumer.BaseProviderRule.getPacts(BaseProviderRule.java:186)
    ... 16 more
Caused by: java.lang.NoSuchMethodError: au.com.dius.pact.model.matchingrules.Category.addRule(Ljava/lang/String;Lau/com/dius/pact/model/matchingrules/MatchingRule;)V
    at au.com.dius.pact.consumer.dsl.PactDslJsonBody.stringType(PactDslJsonBody.java:155)
    at se.ff.bsc.WhatPrimesTest.createPact(WhatPrimesTest.java:33)
    ... 21 more

当我尝试运行此测试代码时出现此错误。

DslPart etaResults = new PactDslJsonBody()
                .stringType("requestedGtin", "4211")
                .integerType("nodeId", 6132)
                .eachLike("gtinList")
                .eachArrayLike("AVAILABLE", 4322)
                .asBody();

当我的服务被调用时,这就是我得到的回报。

  

[{requestedGtin:" 12348",nodeId:124,gtinList:[" 00000000012348"   ],primeOnHandQuantity:{AVAILABLE:0,CLAIMS:0}}]

你认为我做错了什么,我需要帮助,并且会感谢你能评论的任何事情。感谢

当我删除这段代码时

java.net.BindException: Can't assign requested address

    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:100)
    at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50)
    at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)
    at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130)
    at au.com.dius.pact.consumer.MockHttpServer.<init>(MockHttpServer.kt:206)
    at au.com.dius.pact.consumer.MockHttpServerKt.mockServer(MockHttpServer.kt:34)
    at au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:12)
    at au.com.dius.pact.consumer.BaseProviderRule.runPactTest(BaseProviderRule.java:148)
    at au.com.dius.pact.consumer.BaseProviderRule.access$100(BaseProviderRule.java:21)
    at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:76)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

并直接解析.body()函数中的预期正文,我收到此错误消息

from kucoin.client import Client

client = Client(api_key, api_secret)

# optionally pass the language you would like to use
# see client.get_languages() for options
#client = Client(api_key, api_secret, language='zh_CN)
client.get_languages()

0 个答案:

没有答案