Skip to content

Commit 215f2a9

Browse files
author
Ronald Holshausen
committedFeb 13, 2020
fix: AbcMetric + use HttpBuilder after upgrade to Gradle 3 #1019
1 parent 544ce04 commit 215f2a9

File tree

9 files changed

+92
-56
lines changed

9 files changed

+92
-56
lines changed
 

‎consumer/pact-jvm-consumer-groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/ExampleGroovyConsumerPactTest.groovy

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.util.function.BiFunction
1414
class ExampleGroovyConsumerPactTest {
1515

1616
@Test
17+
@SuppressWarnings('AbcMetric')
1718
void "A service consumer side of a pact goes a little something like this"() {
1819

1920
def aliceService = new PactBuilder()
@@ -112,7 +113,7 @@ class ExampleGroovyConsumerPactTest {
112113
assert result.expectedRequests.size() == 1
113114
}
114115

115-
private static BiFunction<ChainedHttpConfig, FromServer, Object> DEFAULT_RESPONSE_HANDLER = { config, resp ->
116+
private static final BiFunction<ChainedHttpConfig, FromServer, Object> DEFAULT_RESPONSE_HANDLER = { config, resp ->
116117
resp
117118
}
118119
}

‎consumer/pact-jvm-consumer-groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/GroovyConsumerMatchersPactSpec.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import static groovyx.net.http.ContentTypes.JSON
1212

1313
class GroovyConsumerMatchersPactSpec extends Specification {
1414

15-
@SuppressWarnings('MethodSize')
15+
@SuppressWarnings(['MethodSize', 'AbcMetric'])
1616
def 'example V3 spec test'() {
1717
given:
1818
def matcherService = new PactBuilder()

‎consumer/pact-jvm-consumer-junit/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
testCompile "org.codehaus.groovy:groovy:${project.groovyVersion}"
2222
testCompile "org.codehaus.groovy:groovy-json:${project.groovyVersion}"
2323
testCompile "org.codehaus.groovy:groovy-xml:${project.groovyVersion}"
24-
testCompile "io.github.http-builder-ng:http-builder-ng-apache:http-builder:${project.httpBuilderVersion}"
24+
testCompile "io.github.http-builder-ng:http-builder-ng-apache:${project.httpBuilderVersion}"
2525
// Required for Java 9
2626
testCompile 'javax.xml.bind:jaxb-api:2.3.0'
2727
testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}"

‎consumer/pact-jvm-consumer-junit/src/test/groovy/au/com/dius/pact/consumer/junit/Defect342MultiTest.groovy

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package au.com.dius.pact.consumer.junit
22

3-
import au.com.dius.pact.core.model.annotations.Pact
43
import au.com.dius.pact.consumer.dsl.DslPart
54
import au.com.dius.pact.consumer.dsl.PactDslJsonArray
65
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
76
import au.com.dius.pact.core.model.RequestResponsePact
7+
import au.com.dius.pact.core.model.annotations.Pact
88
import groovy.json.JsonOutput
9-
import groovyx.net.http.ContentType
10-
import groovyx.net.http.HTTPBuilder
9+
import groovyx.net.http.FromServer
10+
import groovyx.net.http.HttpBuilder
1111
import org.apache.http.client.fluent.Request
12+
import org.apache.http.entity.ContentType
1213
import org.junit.Rule
1314
import org.junit.Test
1415

@@ -61,16 +62,25 @@ class Defect342MultiTest {
6162
@Test
6263
@PactVerification(fragment = 'createFragment1')
6364
void runTest1() {
64-
def http = new HTTPBuilder(mockProvider.url)
65+
def http = HttpBuilder.configure { request.uri = mockProvider.url }
66+
67+
http.post {
68+
request.uri.path = '/some-service/users'
69+
request.body = user()
70+
request.contentType = 'application/json'
6571

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)
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+
}
6976
}
7077

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+
}
7484
}
7585
}
7686

@@ -81,19 +91,19 @@ class Defect342MultiTest {
8191
.uponReceiving('A request with double precision number')
8292
.path('/numbertest')
8393
.method('PUT')
84-
.body('{"name": "harry","data": 1234.0 }', ContentType.JSON.toString())
94+
.body('{"name": "harry","data": 1234.0 }', 'application/json')
8595
.willRespondWith()
8696
.status(200)
87-
.body('{"responsetest": true, "name": "harry","data": 1234.0 }', ContentType.JSON.toString())
97+
.body('{"responsetest": true, "name": "harry","data": 1234.0 }', 'application/json')
8898
.toPact()
8999
}
90100

91101
@Test
92102
@PactVerification(fragment = 'createFragment2')
93103
void runTest2() {
94104
assert Request.Put(mockProvider.url + '/numbertest')
95-
.addHeader('Accept', ContentType.JSON.toString())
96-
.bodyString('{"name": "harry","data": 1234.0 }', org.apache.http.entity.ContentType.APPLICATION_JSON)
105+
.addHeader('Accept', 'application/json')
106+
.bodyString('{"name": "harry","data": 1234.0 }', ContentType.APPLICATION_JSON)
97107
.execute().returnContent().asString() == '{"responsetest":true,"name":"harry","data":1234.0}'
98108
}
99109

‎consumer/pact-jvm-consumer-junit/src/test/groovy/au/com/dius/pact/consumer/junit/Defect975XMLTest.groovy

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import au.com.dius.pact.consumer.dsl.PactDslWithProvider
44
import au.com.dius.pact.core.model.RequestResponsePact
55
import au.com.dius.pact.core.model.annotations.Pact
66
import au.com.dius.pact.core.model.matchingrules.EqualsMatcher
7-
import groovyx.net.http.ContentType
8-
import groovyx.net.http.HTTPBuilder
7+
import groovyx.net.http.FromServer
8+
import groovyx.net.http.HttpBuilder
99
import org.junit.Rule
1010
import org.junit.Test
1111

@@ -51,7 +51,7 @@ class Defect975XMLTest {
5151
@Test
5252
@PactVerification
5353
void runTest1() {
54-
def http = new HTTPBuilder(mockProvider.url)
54+
def http = HttpBuilder.configure { request.uri = mockProvider.url }
5555
def xml = '''<?xml version="1.0" encoding="UTF-8"?>
5656
<providerService version="1.0">
5757
<attribute1>
@@ -67,8 +67,13 @@ class Defect975XMLTest {
6767
</providerService>
6868
'''
6969

70-
http.post(path: '/attr', body: xml, requestContentType: ContentType.XML) { response ->
71-
assert response.status == 201
70+
http.post {
71+
request.uri.path = '/attr'
72+
request.body = xml
73+
request.contentType = 'application/xml'
74+
response.success { FromServer fs, Object body ->
75+
assert fs.statusCode == 201
76+
}
7277
}
7378
}
7479
}

‎consumer/pact-jvm-consumer-junit/src/test/groovy/au/com/dius/pact/consumer/junit/MultiCookieTest.groovy

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package au.com.dius.pact.consumer.junit
33
import au.com.dius.pact.core.model.annotations.Pact
44
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
55
import au.com.dius.pact.core.model.RequestResponsePact
6-
import groovyx.net.http.ContentType
7-
import groovyx.net.http.HTTPBuilder
6+
import groovyx.net.http.FromServer
7+
import groovyx.net.http.HttpBuilder
88
import org.junit.Rule
99
import org.junit.Test
1010

@@ -31,13 +31,18 @@ class MultiCookieTest {
3131
@Test
3232
@PactVerification
3333
void runTest() {
34-
def http = new HTTPBuilder(mockProvider.url)
34+
def http = HttpBuilder.configure { request.uri = mockProvider.url }
3535

36-
http.post(path: '/provider', requestContentType: ContentType.JSON) { response ->
37-
assert response.status == 200
38-
assert response.headers.iterator().findAll { it.name == 'set-cookie' }*.value == [
39-
'someCookie=someValue; Path=/', 'someOtherCookie=someValue; Path=/', 'someThirdCookie=someValue; Path=/'
40-
]
36+
http.post {
37+
request.uri.path = '/provider'
38+
request.contentType = 'application/json'
39+
40+
response.success { FromServer fs, Object body ->
41+
assert fs.statusCode == 200
42+
assert fs.headers.findAll { it.key == 'set-cookie' }*.value == [
43+
'someCookie=someValue; Path=/', 'someOtherCookie=someValue; Path=/', 'someThirdCookie=someValue; Path=/'
44+
]
45+
}
4146
}
4247
}
4348
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package au.com.dius.pact.consumer.junit.formpost
22

3-
import groovyx.net.http.ContentType
4-
import groovyx.net.http.HTTPBuilder
3+
import groovyx.net.http.ContentTypes
4+
import groovyx.net.http.HttpBuilder
55

66
class ZooClient {
77
private final String url
@@ -11,16 +11,23 @@ class ZooClient {
1111
}
1212

1313
Animal saveAnimal(String type, String name) {
14-
def http = new HTTPBuilder(url)
15-
def response = http.post(path: '/zoo-ws/animals', body: [type: type, name: name],
16-
requestContentType: ContentType.URLENC)
14+
def http = HttpBuilder.configure { request.uri = url }
15+
def response = http.post {
16+
request.uri.path = '/zoo-ws/animals'
17+
request.body = [type: type, name: name]
18+
request.contentType = ContentTypes.URLENC[0]
19+
}
1720
new Animal(response)
1821
}
1922

2023
Animal saveAnimal(String type, String name, String level) {
21-
def http = new HTTPBuilder(url)
22-
def response = http.post(path: '/zoo-ws/animals', query: [level: level], body: [type: type, name: name],
23-
requestContentType: ContentType.URLENC)
24+
def http = HttpBuilder.configure { request.uri = url }
25+
def response = http.post {
26+
request.uri.path = '/zoo-ws/animals'
27+
request.uri.query = [level: level]
28+
request.body = [type: type, name: name]
29+
request.contentType = ContentTypes.URLENC[0]
30+
}
2431
new Animal(response)
2532
}
2633
}

‎consumer/pact-jvm-consumer-junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy

+24-13
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import au.com.dius.pact.consumer.dsl.PactDslJsonArray
77
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
88
import au.com.dius.pact.core.model.RequestResponsePact
99
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
1212
import org.apache.http.client.fluent.Request
13+
import org.apache.http.entity.ContentType
1314
import org.junit.jupiter.api.Disabled
1415
import org.junit.jupiter.api.Test
1516
import org.junit.jupiter.api.extension.ExtendWith
@@ -61,17 +62,27 @@ class MultiTest {
6162
@Test
6263
@PactTestFor(pactMethod = 'createFragment1')
6364
void runTest1(MockServer mockServer) {
64-
def http = new HTTPBuilder(mockServer.url)
65+
def http = HttpBuilder.configure { request.uri = mockServer.url }
6566

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+
}
6976
}
7077

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+
}
7484
}
85+
7586
}
7687

7788
@Pact(provider= 'multitest_provider', consumer= 'test_consumer')
@@ -81,19 +92,19 @@ class MultiTest {
8192
.uponReceiving('A request with double precision number')
8293
.path('/numbertest')
8394
.method('PUT')
84-
.body('{"name": "harry","data": 1234.0 }', ContentType.JSON.toString())
95+
.body('{"name": "harry","data": 1234.0 }', 'application/json')
8596
.willRespondWith()
8697
.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')
8899
.toPact()
89100
}
90101

91102
@Test
92103
@PactTestFor(pactMethod = 'createFragment2')
93104
void runTest2(MockServer mockServer) {
94105
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)
97108
.execute().returnContent().asString() == '{"responsetest":true,"name":"harry","data":1234.0}'
98109
}
99110

‎provider/pact-jvm-provider/src/test/groovy/au/com/dius/pact/provider/ConsumerInfoSpec.groovy

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ class ConsumerInfoSpec extends Specification {
2525

2626
where:
2727

28-
source | expectedSource
29-
new URL('file:/var/tmp/file') | UrlSource
30-
new FileSource(new File('/var/tmp/file')) | FileSource
31-
{ -> } | ClosurePactSource
32-
'/var/tmp/file' | FileSource
28+
source << [new URL('file:/var/tmp/file'), new FileSource('/var/tmp/file' as File), { -> }, '/var/tmp/file']
29+
expectedSource << [UrlSource, FileSource, ClosurePactSource, FileSource]
3330
}
3431

3532
def 'include the tag when converting from a PactBrokerConsumer'() {

0 commit comments

Comments
 (0)
Please sign in to comment.