-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
ContractTest.kt
40 lines (32 loc) · 1.38 KB
/
ContractTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.demo
import au.com.dius.pact.consumer.ConsumerPactTestMk2
import au.com.dius.pact.consumer.MockServer
import au.com.dius.pact.consumer.dsl.PactDslJsonBody
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
import au.com.dius.pact.model.RequestResponsePact
import org.assertj.core.api.KotlinAssertions.assertThat
class ContractTest : ConsumerPactTestMk2() {
override fun providerName(): String = "user-data-provider"
override fun consumerName(): String = "user-data-cli"
override fun createPact(builder: PactDslWithProvider): RequestResponsePact {
val body = PactDslJsonBody()
.stringType("firstName")
.stringType("lastName")
.numberType("age")
.`object`("ids", PactDslJsonBody()
.integerType("id")
.uuid("uuid"))
return builder.uponReceiving("can get user data from user data provider")
.path("/user")
.method("GET")
.willRespondWith()
.status(200)
.body(body)
.toPact()
}
override fun runTest(mockServer: MockServer) {
val expectedKeys = listOf("firstName", "lastName", "ids", "age")
val result = UserClient("${mockServer.getUrl()}/user").callProducer()
assertThat(result.keys).containsAll(expectedKeys)
}
}