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
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
* 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 [consumer test](/src/test/java/io/reflectoring/UserClientTest.java)
* run `./gradlew publishToMavenLocal` in the [producer project](../spring-cloud-contract-provider)
to create a provider stubs
* run `./gradlew build` in this project to verify the feign client against the stub
* have a look at the [consumer test](/src/test/java/io/reflectoring/UserServiceConsumerTest.java)
* run `./gradlew build` to run all tests and create pact files into the folder `target/pacts`
* run `./gradlew pactPublish` to publish the pact files to a Pact Broker (must specify Pact Broker location and credentials in `build.gradle`)

View File

@@ -1,5 +1,3 @@
apply plugin: 'org.springframework.boot'
buildscript {
repositories {
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 {
mavenLocal()
@@ -25,3 +30,12 @@ dependencies {
testCompile("au.com.dius:pact-jvm-consumer-junit_2.11:3.5.2")
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
private UserClient userClient;
@Pact(state = "provider accepts a new person", provider = "userservice", consumer = "userclient")
@Pact(provider = "userservice", consumer = "userclient")
public RequestResponsePact createPersonPact(PactDslWithProvider builder) {
return builder
.given("provider accepts a new person")
@@ -42,19 +42,19 @@ public class UserServiceConsumerTest {
.toPact();
}
@Pact(state = "person 42 exists", provider = "userservice", consumer = "userclient")
@Pact(provider = "userservice", consumer = "userclient")
public RequestResponsePact updatePersonPact(PactDslWithProvider builder) {
return builder
.given("person 42 exists")
.uponReceiving("a request to PUT a person")
.path("/user-service/users/42")
.method("PUT")
.path("/user-service/users/42")
.method("PUT")
.willRespondWith()
.status(200)
.matchHeader("Content-Type", "application/json")
.body(new PactDslJsonBody()
.stringType("firstName", "Zaphod")
.stringType("lastName", "Beeblebrox"))
.status(200)
.matchHeader("Content-Type", "application/json")
.body(new PactDslJsonBody()
.stringType("firstName", "Zaphod")
.stringType("lastName", "Beeblebrox"))
.toPact();
}