@@ -7,9 +7,10 @@ import au.com.dius.pact.consumer.dsl.PactDslJsonArray
7
7
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
8
8
import au.com.dius.pact.core.model.RequestResponsePact
9
9
import groovy.json.JsonOutput
10
- import groovyx.net.http.ContentType
11
- import groovyx.net.http.HTTPBuilder
10
+ import groovyx.net.http.FromServer
11
+ import groovyx.net.http.HttpBuilder
12
12
import org.apache.http.client.fluent.Request
13
+ import org.apache.http.entity.ContentType
13
14
import org.junit.jupiter.api.Disabled
14
15
import org.junit.jupiter.api.Test
15
16
import org.junit.jupiter.api.extension.ExtendWith
@@ -61,17 +62,27 @@ class MultiTest {
61
62
@Test
62
63
@PactTestFor (pactMethod = ' createFragment1' )
63
64
void runTest1 (MockServer mockServer ) {
64
- def http = new HTTPBuilder ( mockServer. url)
65
+ def http = HttpBuilder . configure { request . uri = mockServer. url }
65
66
66
- http. post(path : ' /some-service/users' , body : user(), requestContentType : ContentType . JSON ) { response ->
67
- assert response. status == 201
68
- assert response. headers[' location' ]?. toString()?. contains(SOME_SERVICE_USER )
67
+ http. post {
68
+ request. uri. path = ' /some-service/users'
69
+ request. body = user()
70
+ request. contentType = ' application/json'
71
+
72
+ response. success { FromServer fs , Object body ->
73
+ assert fs. statusCode == 201
74
+ assert fs. headers. find { it. key == ' Location' }?. value?. contains(SOME_SERVICE_USER )
75
+ }
69
76
}
70
77
71
- http. get(path : SOME_SERVICE_USER + EXPECTED_USER_ID ,
72
- headers : [' Content-Type' : ContentType . JSON . toString()]) { response ->
73
- assert response. status == 200
78
+ http. get {
79
+ request. uri. path = SOME_SERVICE_USER + EXPECTED_USER_ID
80
+ request. contentType = ' application/json'
81
+ response. success { FromServer fs , Object body ->
82
+ assert fs. statusCode == 200
83
+ }
74
84
}
85
+
75
86
}
76
87
77
88
@Pact (provider = ' multitest_provider' , consumer = ' test_consumer' )
@@ -81,19 +92,19 @@ class MultiTest {
81
92
.uponReceiving(' A request with double precision number' )
82
93
.path(' /numbertest' )
83
94
.method(' PUT' )
84
- .body(' {"name": "harry","data": 1234.0 }' , ContentType . JSON . toString() )
95
+ .body(' {"name": "harry","data": 1234.0 }' , ' application/json ' )
85
96
.willRespondWith()
86
97
.status(200 )
87
- .body(' {"responsetest": true, "name": "harry","data": 1234.0 }' , ContentType . JSON . toString() )
98
+ .body(' {"responsetest": true, "name": "harry","data": 1234.0 }' , ' application/json ' )
88
99
.toPact()
89
100
}
90
101
91
102
@Test
92
103
@PactTestFor (pactMethod = ' createFragment2' )
93
104
void runTest2 (MockServer mockServer ) {
94
105
assert Request.Put (mockServer. url + ' /numbertest' )
95
- .addHeader(' Accept' , ContentType . JSON . toString() )
96
- .bodyString(' {"name": "harry","data": 1234.0 }' , org.apache.http.entity. ContentType. APPLICATION_JSON )
106
+ .addHeader(' Accept' , ' application/json ' )
107
+ .bodyString(' {"name": "harry","data": 1234.0 }' , ContentType . APPLICATION_JSON )
97
108
.execute(). returnContent(). asString() == ' {"responsetest":true,"name":"harry","data":1234.0}'
98
109
}
99
110
0 commit comments