Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
Testing PactDslJsonBody无法创建JSON对象_Testing_Integration_Pact_Pact Jvm - Fatal编程技术网

Testing PactDslJsonBody无法创建JSON对象

Testing PactDslJsonBody无法创建JSON对象,testing,integration,pact,pact-jvm,Testing,Integration,Pact,Pact Jvm,@契约(提供者=“预约提供者”,消费者=“预约消费者”) public PactFragment CreateFragmentAppointDetails(PactDslWithProvider builder)引发ParseException{ Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", "application/json");

@契约(提供者=“预约提供者”,消费者=“预约消费者”) public PactFragment CreateFragmentAppointDetails(PactDslWithProvider builder)引发ParseException{

        Map<String, String> headers = new HashMap<>(); 
        headers.put("Content-Type", "application/json"); 


        return builder
                .given("GetAppoinment")
                .uponReceiving("Get Appointment information")
                .path("/getappointment")
                .query("apptId=11207")
                .method("GET")
                .willRespondWith()
                .headers(headers)
                .status(200)
                .body(new PactDslJsonBody()
                        .object("appointments")
                        .stringValue("type","Test \\u0026 Turn up")
                        .stringValue("apptId","11207")
                        .closeObject()
                        )
                .toFragment()
                ;
Map headers=newhashmap();
headers.put(“内容类型”、“应用程序/json”);
返回生成器
.给定(“获得任命”)
.uponReceiving(“获取预约信息”)
.path(“/getappointment”)
.query(“apptId=11207”)
.方法(“获取”)
.willrespondbith()
.标题(标题)
.现状(200)
.body(新的PactDslJsonBody()
.反对(“任命”)
.stringValue(“类型”,“测试\\u0026打开”)
.stringValue(“apptId”、“11207”)
.closeObject()
)
.toFragment()
;

}啊,我想我现在看到了。您需要使用
closeObject()
结束
new PactDslJsonBody()
(因此,自从您在其中打开另一个对象以来,最后有2个对象),因为JsonBody本身创建了一个对象。应该是这样的:

builder
    .given("GetAppoinment")
    .uponReceiving("Get Appointment information")
    .path("/getappointment")
    .query("apptId=11207")
    .method("GET")
    .willRespondWith()
    .headers(headers)
    .status(200)
    .body(
            new PactDslJsonBody() // This opens a root object
                .object("appointments") // creates a new object with in the root one
                    .stringValue("type","Test \\u0026 Turn up")
                    .stringValue("apptId","11207")
                .closeObject() // closes the child object
           .closeObject() // closes the root object
    )
    .toFragment();

java.lang.RuntimeException:未能在au.com.dius.pact.consumer.PactProviderRule.getPacts(PactProviderRule.java:269)调用au.com.dius.pact.consumer.PactProviderRule$1.evaluate(PactProviderRule.java:145)上的pact方法原因:java.lang.NoClassDefFoundError:org/json/jsonObject听起来你缺少依赖项-你能发布依赖项吗?@Nisha你能提供更多的上下文,也许是一个更好的例子,包括与Pact相关的所有内容吗?听起来你缺少了一个依赖项,你是如何将这个契约依赖项添加到你的项目中的?你能给我们看一下这个文件吗?这是添加的两个pact依赖项au.com.dius pact-jvm-consumer-junit_2.11 3.5.4 org.codehaus.groovy groovy all au.com.dius pact-jvm-provider-junit_2.11 3.5.4