15
Stick to the rules! Consumer Driven Contracts Marcin Grzejszczak @mgrzejszczak Jakub Kubrynski @jkubrynski

4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

  • Upload
    proidea

  • View
    102

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Stick to the rules!Consumer Driven Contracts

Marcin Grzejszczak @mgrzejszczak

Jakub Kubrynski @jkubrynski

Page 2: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Jakub Kubryński

@jkubrynski

www.kubrynski.com

Marcin Grzejszczak

@mgrzejszczak

toomuchcoding.blogspot.com

Page 3: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

TDD on architectural level

@mgrzejszczak @jkubrynski

Page 4: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

What is Consumer Driven Contract

@mgrzejszczak @jkubrynski

● Server● Consumer● Contract

Page 5: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Consumer Driven Contractbenefits

@mgrzejszczak @jkubrynski

Page 6: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Example

@mgrzejszczak @jkubrynski

Page 7: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Example

@mgrzejszczak @jkubrynski

Page 8: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

How to solve it

@mgrzejszczak @jkubrynski

● Consumer’s tests● Server tests

Page 9: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Contract definition

@mgrzejszczak @jkubrynski

● Contract defines communication● Your stub is your contract - verify it!● Expose your stub to your consumers

Page 10: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Consumer Technology

@mgrzejszczak @jkubrynski

Wiremock

http://wiremock.org

testCompile 'com.github.tomakehurst:wiremock:1.53'

{ "request": { "method": "GET", "url": "/hello" }, "response": { "status": 200, "body": "Hello world!", "headers": { "Content-Type": "text/plain" } }}

Page 11: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Server Technology

@mgrzejszczak @jkubrynski

Accurate REST

https://github.com/Codearte/accurest

buildscript { repositories { mavenCentral() } dependencies { classpath 'io.codearte.accurest:accurest-gradle-plugin:0.5.0' }}

apply plugin: 'accurest'

Page 12: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Server Technology

@mgrzejszczak @jkubrynski

Accurate REST

def shouldMarkClientAsNotFraud() {given:

def request = given() .header('Content-Type', 'application/frud+json')

.body('{"clientPesel":"12345678901", "loanAmount":123.123}')

when:def response = given().spec(request)

.put("/fraudcheck")

then:response.statusCode == 200response.header('Content-Type') == 'application/fraud+json'

and:def responseBody = parseText(response.body.asString())responseBody.fraudCheckStatus == "OK"

}

Page 13: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Example

@mgrzejszczak @jkubrynski

Page 14: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Live coding

@mgrzejszczak @jkubrynski

Page 15: 4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

Q&A

@mgrzejszczak @jkubrynski

github.com/marcingrzejszczak/4developers_cdc_examples