Introduction to Groovy runtime metaprogramming and AST transforms
Stick to the rules - Consumer Driven Contracts. 2015.07 Confitura
1. Stick to the rules!
Consumer Driven Contracts
04.07.2015 - Confitura PL
Marcin Grzejszczak @mgrzejszczak
2. @confiturapl @mgrzejszczak / @4financeit
Swim for a dream
http://swimforadream.com/
Adam will swim 18.5 km from Hel to Gdynia
Money for 3 charity organizations
3. @confiturapl @mgrzejszczak / @4financeit
Marcin Grzejszczak
● Software Architect at 4financeIT
● Author of "Mockito Instant", "Mockito Cookbook"
● Co-author of "micro-infra-spring",
“spring-cloud-zookeeper”, “spring-cloud-sleuth”
Twitter: @MGrzejszczak
Blog: http://toomuchcoding.blogspot.com
Homepage: http://marcin.grzejszczak.pl
4. @confiturapl @mgrzejszczak / @4financeit
Agenda
● Short introduction
● Real life scenario with a hilarious joke
● How does it work?
● Live (hopefully) coding
● Summary
5. @confiturapl @mgrzejszczak / @4financeit
Consumer Driven Contracts
● TDD on architectural level
○ mistakes occur both in implementation and design
● Try to use API before implementing it
21. @confiturapl @mgrzejszczak / @4financeit
Workflow - Consumer side
1) ALTER THE CONTRACT LOCALLY
2) GENERATE AND COPY STUBS
3) USE STUBS IN CONSUMER TESTS
22. @confiturapl @mgrzejszczak / @4financeit
What is a stub?
● JSON representation of a Groovy DSL contract
● Understood by Wiremock Http Server Stub
23. @confiturapl @mgrzejszczak / @4financeit
Workflow - Consumer side
FILE A PULL REQUEST WITH
THE PROPOSED CONTRACT
24. @confiturapl @mgrzejszczak / @4financeit
Server tests - what happens there?
● server has DSLs with contracts
● tests are generated from the contracts
● stubs that consumers can use are
generated from the contracts
25. @confiturapl @mgrzejszczak / @4financeit
Workflow - Server side
● oh, I have a PR with the proposed contract
● I don’t have the implementation ready so
my generated tests are failing
● I’ll add the implementation, fix the tests
and merge the PR!
37. @confiturapl @mgrzejszczak / @4financeit
CDC benefits
● Rapid API prototyping
● Non-blocking development
● Behaviour Driven Development
38. @confiturapl @mgrzejszczak / @4financeit
CDC benefits
● Client tells what he needs
● Quality - continuously checking if contract
is valid
39. @confiturapl @mgrzejszczak / @4financeit
CDC benefits
● if server breaks API compatibility
consumer tests fail
● if server adds new API I can reuse it
immediately in my tests
40. @confiturapl @mgrzejszczak / @4financeit
CDC benefits
● The server tests are generated for you
● Any typos / misunderstandings will be found
out immediately
41. @confiturapl @mgrzejszczak / @4financeit
Not so fast...
● Maintaining datasets
● What exactly to verify for server side?
● Breaking changes
● Accurest under development
○ I also have to sleep sometimes