Compare commits

...

2 Commits

Author SHA1 Message Date
Tom Hombergs
d8fa325ae0 updated README 2018-03-17 21:24:18 +01:00
Tom Hombergs
fceb1d898d added pact publish task 2018-03-17 21:21:22 +01:00
3 changed files with 30 additions and 18 deletions

View File

@@ -1,13 +1,11 @@
# Testing a Spring Boot REST API Consumer against a Contract with Spring Cloud Contract # Creating a Consumer-Driven Contract with Feign and Pact
## Companion Blog Article ## Companion Blog Article
Read the [companion blog article](https://reflectoring.io/consumer-driven-contract-consumer-spring-cloud-contract/) to this repository. Read the [companion blog article](https://reflectoring.io/consumer-driven-contract-feign-pact/) to this repository.
## Getting Started ## Getting Started
* have a look at the [contract](/src/test/resources/contracts)
* have a look at the [feign client](/src/main/java/io/reflectoring/UserClient.java) * have a look at the [feign client](/src/main/java/io/reflectoring/UserClient.java)
* have a look at the [consumer test](/src/test/java/io/reflectoring/UserClientTest.java) * have a look at the [consumer test](/src/test/java/io/reflectoring/UserServiceConsumerTest.java)
* run `./gradlew publishToMavenLocal` in the [producer project](../spring-cloud-contract-provider) * run `./gradlew build` to run all tests and create pact files into the folder `target/pacts`
to create a provider stubs * run `./gradlew pactPublish` to publish the pact files to a Pact Broker (must specify Pact Broker location and credentials in `build.gradle`)
* run `./gradlew build` in this project to verify the feign client against the stub

View File

@@ -1,5 +1,3 @@
apply plugin: 'org.springframework.boot'
buildscript { buildscript {
repositories { repositories {
mavenLocal() mavenLocal()
@@ -10,6 +8,13 @@ buildscript {
} }
} }
plugins {
id "au.com.dius.pact" version "3.5.13"
}
apply plugin: 'org.springframework.boot'
version '1.0.0.SNAPSHOT'
repositories { repositories {
mavenLocal() mavenLocal()
@@ -25,3 +30,12 @@ dependencies {
testCompile("au.com.dius:pact-jvm-consumer-junit_2.11:3.5.2") testCompile("au.com.dius:pact-jvm-consumer-junit_2.11:3.5.2")
testCompile("org.springframework.boot:spring-boot-starter-test:${springboot_version}") testCompile("org.springframework.boot:spring-boot-starter-test:${springboot_version}")
} }
pact {
publish {
pactDirectory = 'target/pacts'
pactBrokerUrl = 'URL'
pactBrokerUsername = 'USERNAME'
pactBrokerPassword = 'PASSWORD'
}
}

View File

@@ -27,7 +27,7 @@ public class UserServiceConsumerTest {
@Autowired @Autowired
private UserClient userClient; private UserClient userClient;
@Pact(state = "provider accepts a new person", provider = "userservice", consumer = "userclient") @Pact(provider = "userservice", consumer = "userclient")
public RequestResponsePact createPersonPact(PactDslWithProvider builder) { public RequestResponsePact createPersonPact(PactDslWithProvider builder) {
return builder return builder
.given("provider accepts a new person") .given("provider accepts a new person")
@@ -42,19 +42,19 @@ public class UserServiceConsumerTest {
.toPact(); .toPact();
} }
@Pact(state = "person 42 exists", provider = "userservice", consumer = "userclient") @Pact(provider = "userservice", consumer = "userclient")
public RequestResponsePact updatePersonPact(PactDslWithProvider builder) { public RequestResponsePact updatePersonPact(PactDslWithProvider builder) {
return builder return builder
.given("person 42 exists") .given("person 42 exists")
.uponReceiving("a request to PUT a person") .uponReceiving("a request to PUT a person")
.path("/user-service/users/42") .path("/user-service/users/42")
.method("PUT") .method("PUT")
.willRespondWith() .willRespondWith()
.status(200) .status(200)
.matchHeader("Content-Type", "application/json") .matchHeader("Content-Type", "application/json")
.body(new PactDslJsonBody() .body(new PactDslJsonBody()
.stringType("firstName", "Zaphod") .stringType("firstName", "Zaphod")
.stringType("lastName", "Beeblebrox")) .stringType("lastName", "Beeblebrox"))
.toPact(); .toPact();
} }