Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

BDD-Driven Microservices

5,586 views

Published on

Think BDD is just for web sites? Think again! In this talk, we rethink traditional software testing strategies in the context of micro-services and Behaviour-Driven Development. We will see how traditional testing approaches are both inadequate and poorly targeted for micro-services development. We will learn how to use BDD techniques to discover, describe and document micro-service requirements, and tools like Cucumber and Serenity to turn these requirements into automated acceptance tests and living documentation. We will see how Consumer-Driven Contract tools help ensure that micro-services play well together, and how you can implement the details with the help of unit-testing tools like Spock and REST-Assured.

Published in: Software
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

BDD-Driven Microservices

  1. 1. Tools, techniques and reflections BDD-Driven Microservices in Java
  2. 2. John Ferguson Smart Introductions “I help teams of smart people 
 learn to work together more efficiently, 
 to deliver better software faster”
  3. 3. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  4. 4. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  5. 5. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  6. 6. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  7. 7. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  8. 8. Independently Deployable Bounded ContextsLoosely CoupledSingle Responsibility Microservices 101
  9. 9. Microservices 101 Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service REST/HTTP
  10. 10. Microservices 101 Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  11. 11. Microservices 101 Movie Catalog Service
  12. 12. Microservices 101 Movie Catalog Service Resource
  13. 13. Microservices 101 Movie Catalog Service Resource Service Layer Domain model Repositories
  14. 14. Microservices 101 Movie Catalog Service Resource Persistance Layer Service Layer Domain model Repositories
  15. 15. Microservices 101 Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories
  16. 16. The testing pyramid
  17. 17. The testing pyramid Unit Tests
  18. 18. The testing pyramid Unit Tests Integration Tests
  19. 19. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  20. 20. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  21. 21. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  22. 22. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  23. 23. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  24. 24. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  25. 25. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  26. 26. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  27. 27. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  28. 28. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  29. 29. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  30. 30. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  31. 31. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Unit Tests
  32. 32. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Integration Tests
  33. 33. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Integration Tests
  34. 34. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Integration Tests
  35. 35. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Integration Tests
  36. 36. The testing pyramid Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Integration Tests
  37. 37. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  38. 38. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  39. 39. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  40. 40. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  41. 41. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  42. 42. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  43. 43. The testing pyramid End-to-End Tests Movie Catalog Service Authentication Service Shopping Cart Service Delivery Service Payment Service Event Bus
  44. 44. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  45. 45. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  46. 46. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  47. 47. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  48. 48. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  49. 49. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  50. 50. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  51. 51. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  52. 52. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  53. 53. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  54. 54. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  55. 55. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  56. 56. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  57. 57. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  58. 58. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  59. 59. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  60. 60. To document how to interact with the microservice To document what the microservice does To ensure the service work correctly To ensure we are delivering valuable functionality Why test our micro-services?
  61. 61. “We test our micro-services so we can deploy new features quickly and with confidence”
  62. 62. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  63. 63. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  64. 64. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  65. 65. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  66. 66. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  67. 67. And with aggressive production monitoring Writing executable specifications and living documentation To a sufficient level of confidence Outside-in testing Pragmatic web service testing
  68. 68. Outside-in development
  69. 69. To deliver software that matters And a common language to build a shared understanding Using examples at multiple levels Collaborate to discover requirements and identify uncertainty The essence of BDD
  70. 70. To deliver software that matters And a common language to build a shared understanding Using examples at multiple levels Collaborate to discover requirements and identify uncertainty The essence of BDD
  71. 71. To deliver software that matters And a common language to build a shared understanding Using examples at multiple levels Collaborate to discover requirements and identify uncertainty The essence of BDD
  72. 72. To deliver software that matters And a common language to build a shared understanding Using examples at multiple levels Collaborate to discover requirements and identify uncertainty The essence of BDD
  73. 73. To deliver software that matters And a common language to build a shared understanding Using examples at multiple levels Collaborate to discover requirements and identify uncertainty The essence of BDD
  74. 74. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  75. 75. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  76. 76. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  77. 77. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  78. 78. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  79. 79. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  80. 80. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  81. 81. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  82. 82. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  83. 83. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  84. 84. The business owner tells the business analyst what he wants 1 2 The business analyst writes a requirements document 3 The developer translates the requirements into software 4 The tester translates the requirements into test cases 5 The technical writer translates the software into functional and technical documentation A traditional development process How does it work?
  85. 85. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  86. 86. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  87. 87. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  88. 88. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  89. 89. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  90. 90. How does it work? The business owner and the business analyst have a conversation about what he needs. 1 2 3 4 The tester uses these scenarios as the basis for her tests 5 The automated tests provide feedback on progress and help document the application The business analyst, the developer and the tester elaborate the requirements together. The scenarios guide the developer and act as automated tests They define requirements as structured, English- language format "scenarios" A BDD development process
  91. 91. But what about micro-services?
  92. 92. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  93. 93. The testing pyramid Unit Tests Integration Tests End-to-end Tests
  94. 94. A different testing pyramid
  95. 95. A different testing pyramid Executable Business Specifications
  96. 96. A different testing pyramid Slow-running executable technical specifications Executable Business Specifications
  97. 97. A different testing pyramid Fast-running executable technical specifications Slow-running executable technical specifications Executable Business Specifications
  98. 98. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Executable Business specs
  99. 99. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Executable Business specs Scenario: Search movies by director
 Given the catalog has the following movies:
 | title | director | actors |
 | Gladiator | Ridley Scott | Russel Crowe, Joaquin Phoenix |
 | Letters from Iwo Jima | Clint Eastwood | Ken Watanabe |
 | Gran Torino | Clint Eastwood | Clint Eastwood, Bee Vang |
 When I search for movies directed by Clint Eastwood
 Then I should be presented with the following movies:
 | title | director | actors |
 | Letters from Iwo Jima | Clint Eastwood | Ken Watanabe |
 | Gran Torino | Clint Eastwood | Clint Eastwood, Bee Vang |

  100. 100. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Slow-running technical specs
  101. 101. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Slow-running technical specs @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMoviesViaTheRestAPI extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def "should list movies by director"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 List<Movie> movies = when().get("/movies/findByDirector/Clint Eastwood").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Letters from Iwo Jima", "Gran Torino"]
 }
  102. 102. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Fast- running technical specs
  103. 103. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Fast- running technical specs def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 } Spock
  104. 104. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Fast- running technical specs
  105. 105. Outside-in development Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Fast- running technical specs class MovieControllerSpecs extends Specification {
 
 MovieRepository movieRepository = Mock()
 
 def "should find by director regardless of case (#director -> #filteredDirector)"() {
 given:
 def controller = new MovieController(repository: movieRepository)
 when:
 controller.findByDirector(director)
 then:
 1*movieRepository.findByDirector(filteredDirector)
 where:
 director | filteredDirector
 "Clint Eastwood" | "Clint Eastwood"
 "Clint eastwood" | "Clint Eastwood" Spock
  106. 106. Micro-service Contracts
  107. 107. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service Delivery Service REST/HTTP
  108. 108. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service REST/HTTP Delivery Service
  109. 109. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service REST/HTTP Consumer Delivery Service
  110. 110. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service REST/HTTP Consumer Producer Delivery Service
  111. 111. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service REST/HTTP Consumer Producer Contract Delivery Service
  112. 112. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service REST/HTTP Contract Delivery Service
  113. 113. Micro-service Contracts Movie Catalog Service Resource Persistance Layer Gateway Service Layer Domain model Repositories Shopping Cart Service Delivery Service REST/HTTP Contract Mock Shopping Cart Service
  114. 114. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app
  115. 115. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Producer
  116. 116. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer
  117. 117. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer
  118. 118. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer Consumer
  119. 119. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer Consumer Contract
  120. 120. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer Consumer Contract
  121. 121. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer Consumer Contract
  122. 122. Micro-service Contracts REST/HTTP Movie Catalog Service Web app iPhone app Android app Consumer Producer Consumer Consumer Contract The Producer API is the sum of the Consumer Contrats
  123. 123. Specialised ToolsPublished specificationsAutomated Acceptance Criteria Verifying the contracts
  124. 124. Specialised ToolsPublished specificationsAutomated Acceptance Criteria Verifying the contracts
  125. 125. Specialised ToolsPublished specificationsAutomated Acceptance Criteria Verifying the contracts
  126. 126. Specialised ToolsPublished specificationsAutomated Acceptance Criteria Verifying the contracts
  127. 127. Specialised ToolsPublished specificationsAutomated Acceptance Criteria Verifying the contracts
  128. 128. PactPactoMountebank More specialised tools
  129. 129. PactPactoMountebank More specialised tools
  130. 130. PactPactoMountebank More specialised tools
  131. 131. PactPactoMountebank More specialised tools
  132. 132. PactPactoMountebank More specialised tools
  133. 133. PactPactoMountebank More specialised tools
  134. 134. PactPactoMountebank More specialised tools
  135. 135. Pact and Pacto
 Consumer Driven Contract Testing 42 Consumer Movie Catalog Service
  136. 136. Pact and Pacto
 Consumer Driven Contract Testing 42 Consumer Movie Catalog Service Mock Service Pact help us create and configure a mock service
  137. 137. Pact and Pacto
 Consumer Driven Contract Testing 43 Consumer Movie Catalog Service Mock Service
  138. 138. Pact and Pacto
 Consumer Driven Contract Testing 43 Consumer Movie Catalog Service Mock Service We write specifications to describe the expected behaviour of the service
  139. 139. Pact and Pacto
 Consumer Driven Contract Testing 44 Consumer Movie Catalog Service Mock Service
  140. 140. Pact and Pacto
 Consumer Driven Contract Testing 44 Consumer Movie Catalog Service Mock Service When we run these specifications, the expected behaviour is recorded in a ‘pact’ file asdasdasda asdasdasdas asdasdasd asdasdasda asdasdasdasd asdasdasdasd asdasdasdas
  141. 141. Pact and Pacto
 Consumer Driven Contract Testing 45 Consumer Movie Catalog Service Mock Service asdasdasda asdasdasdas asdasdasd asdasdasda asdasdasdasd asdasdasdasd asdasdasdas
  142. 142. Pact and Pacto
 Consumer Driven Contract Testing 45 Consumer Movie Catalog Service Mock Service We can now use this ‘pact’ to test(drive) the service implementation asdasdasda asdasdasdas asdasdasd asdasdasda asdasdasdasd asdasdasdasd asdasdasdas
  143. 143. Levels of confidence
  144. 144. From BDD to TDD “How much automated testing?
 As much as you need, but no more.”
  145. 145. Acceptance testing
  146. 146. Acceptance testing
  147. 147. Acceptance testing
  148. 148. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog
  149. 149. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog
  150. 150. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog @When("I add this movie to the catalog")
 public void addMovieToCatalog() {
 movieId = rest().given().contentType("application/json")
 .content(newMovie)
 .post("/movies")
 .then().statusCode(200)
 .and().extract().jsonPath().getString("id");
 }
  151. 151. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog
  152. 152. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog
  153. 153. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog @Then("I should be able to find it in the catalog")
 public void shouldBeAbleToFindMovieInCatalog() {
 rest().given().contentType("application/json")
 .get("/movies/{movieId}", movieId)
 .then().statusCode(200)
 .and().body("title", equalTo(newMovie.getTitle()))
 .and().body("director", equalTo(newMovie.getDirector()));
 }
  154. 154. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog @Then("I should be able to find it in the catalog")
 public void shouldBeAbleToFindMovieInCatalog() {
 rest().given().contentType("application/json")
 .get("/movies/{movieId}", movieId)
 .then().statusCode(200)
 .and().body("title", equalTo(newMovie.getTitle()))
 .and().body("director", equalTo(newMovie.getDirector()));
 } Rest Assured + Serenity
  155. 155. Feature: Adding new movies
 In order to sell more movies
 As an online movie seller
 I want to be able to add movies to the catalog
 
 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog @Then("I should be able to find it in the catalog")
 public void shouldBeAbleToFindMovieInCatalog() {
 rest().given().contentType("application/json")
 .get("/movies/{movieId}", movieId)
 .then().statusCode(200)
 .and().body("title", equalTo(newMovie.getTitle()))
 .and().body("director", equalTo(newMovie.getDirector()));
 }
  156. 156. Testing REST services with Rest-Assured
  157. 157. Testing REST services with Rest-Assured get(“/movies/findByTitle/Gladiator") .then().body("title", equalTo("Gladiator"));
  158. 158. Testing REST services with Rest-Assured get(“/movies/findByTitle/Gladiator") .then().body("title", equalTo("Gladiator"));
  159. 159. Testing REST services with Rest-Assured when().get(“/movies/findByTitle/Gladiator”) .then().body("nominations.category", hasItems("Best Actor", "Special Effects"));
  160. 160. Testing REST services with Rest-Assured when().get(“/movies/findByTitle/Gladiator”) .then().body("nominations.category", hasItems("Best Actor", "Special Effects"));
  161. 161. Testing REST services with Rest-Assured given().contentType("application/json")
 .content(newMovie)
 .post("/movies")
 .then().statusCode(200)
 .and().extract().jsonPath().getString("id");
  162. 162. Testing REST services with Rest-Assured given().contentType("application/json")
 .content(newMovie)
 .post("/movies")
 .then().statusCode(200)
 .and().extract().jsonPath().getString("id"); Posting data
  163. 163. Testing REST services with Rest-Assured Movie matchingMovie = get("/movies/findByTitle/Gladiator").as(Movie.class);
  164. 164. Testing REST services with Rest-Assured Movie matchingMovie = get("/movies/findByTitle/Gladiator").as(Movie.class); Convert responses to Java objects
  165. 165. Testing REST services with Rest-Assured given().param("title","Unknown").
 when().get("/movies/search").
 then().statusCode(404);
  166. 166. Testing REST services with Rest-Assured given().param("title","Unknown").
 when().get("/movies/search").
 then().statusCode(404); Check for errors
  167. 167. Resource-level testing
  168. 168. Resource-level testing Spock
  169. 169. Resource-level testing Spock
  170. 170. Resource-level testing Spock
  171. 171. 57 @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMovies extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def setup() {
 movieRepository.deleteAll();
 RestAssured.port = port;
 }
 
 def "should list all movies"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 def movies = when().get("/movies").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Gladiator", 
 "Letters from Iwo Jima", 
 "Gran Torino"]
 }
  172. 172. 57 @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMovies extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def setup() {
 movieRepository.deleteAll();
 RestAssured.port = port;
 }
 
 def "should list all movies"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 def movies = when().get("/movies").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Gladiator", 
 "Letters from Iwo Jima", 
 "Gran Torino"]
 } Spring Context
  173. 173. 57 @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMovies extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def setup() {
 movieRepository.deleteAll();
 RestAssured.port = port;
 }
 
 def "should list all movies"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 def movies = when().get("/movies").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Gladiator", 
 "Letters from Iwo Jima", 
 "Gran Torino"]
 } Spring Integration Tests
  174. 174. 57 @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMovies extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def setup() {
 movieRepository.deleteAll();
 RestAssured.port = port;
 }
 
 def "should list all movies"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 def movies = when().get("/movies").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Gladiator", 
 "Letters from Iwo Jima", 
 "Gran Torino"]
 } Rest Assured
  175. 175. 57 @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest("server.port:0")
 class WhenFindingMovies extends Specification {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Value('${local.server.port}')
 int port;
 
 def setup() {
 movieRepository.deleteAll();
 RestAssured.port = port;
 }
 
 def "should list all movies"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO])
 when:
 def movies = when().get("/movies").as(List)
 then:
 movies.collect {movie -> movie.title} == ["Gladiator", 
 "Letters from Iwo Jima", 
 "Gran Torino"]
 }
  176. 176. Controller-level testing
  177. 177. Controller-level testing Spock
  178. 178. Controller-level testing Spock
  179. 179. @ContextConfiguration(loader = SpringApplicationContextLoader.class,
 classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest
 class WhenViewingActorDetailsViaTheController extends Specification {
 
 @Autowired
 ArtistController artistController;
 
 def "should retrieve actor details for an artist"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA,
 THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO])
 when:
 Artist artist = artistController.findArtistDetails("Clint Eastwood")
 then:
 artist.name == "Clint Eastwood"
 and:
 artist.filmsActedIn.containsAll(THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO)
 and:
 artist.filmsDirected.containsAll(LETTERS_FROM_IWO_JIMA, GRAN_TORINO)
 }
  180. 180. @ContextConfiguration(loader = SpringApplicationContextLoader.class,
 classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest
 class WhenViewingActorDetailsViaTheController extends Specification {
 
 @Autowired
 ArtistController artistController;
 
 def "should retrieve actor details for an artist"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA,
 THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO])
 when:
 Artist artist = artistController.findArtistDetails("Clint Eastwood")
 then:
 artist.name == "Clint Eastwood"
 and:
 artist.filmsActedIn.containsAll(THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO)
 and:
 artist.filmsDirected.containsAll(LETTERS_FROM_IWO_JIMA, GRAN_TORINO)
 } Use a fully wired controller
  181. 181. @ContextConfiguration(loader = SpringApplicationContextLoader.class,
 classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest
 class WhenViewingActorDetailsViaTheController extends Specification {
 
 @Autowired
 ArtistController artistController;
 
 def "should retrieve actor details for an artist"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA,
 THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO])
 when:
 Artist artist = artistController.findArtistDetails("Clint Eastwood")
 then:
 artist.name == "Clint Eastwood"
 and:
 artist.filmsActedIn.containsAll(THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO)
 and:
 artist.filmsDirected.containsAll(LETTERS_FROM_IWO_JIMA, GRAN_TORINO)
 } Use domain objects rather than REST calls
  182. 182. @ContextConfiguration(loader = SpringApplicationContextLoader.class,
 classes = MovieServiceApplication.class)
 @WebAppConfiguration
 @IntegrationTest
 class WhenViewingActorDetailsViaTheController extends Specification {
 
 @Autowired
 ArtistController artistController;
 
 def "should retrieve actor details for an artist"() {
 given:
 movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA,
 THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO])
 when:
 Artist artist = artistController.findArtistDetails("Clint Eastwood")
 then:
 artist.name == "Clint Eastwood"
 and:
 artist.filmsActedIn.containsAll(THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO)
 and:
 artist.filmsDirected.containsAll(LETTERS_FROM_IWO_JIMA, GRAN_TORINO)
 }
  183. 183. Service or domain-level testing
  184. 184. Service or domain-level testing Spock
  185. 185. MovieRepository repository
 def artistService
 
 def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 }
  186. 186. MovieRepository repository
 def artistService
 
 def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 } Mocked repositories
  187. 187. MovieRepository repository
 def artistService
 
 def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 } Call the service
  188. 188. MovieRepository repository
 def artistService
 
 def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 } Check the outcomes
  189. 189. MovieRepository repository
 def artistService
 
 def setup() {
 repository = Mock(MovieRepository)
 artistService = new ArtistService(movieRepository: repository)
 }
 
 def "should build actor details from films the artist has acted in and has directed"() {
 given: "Clint Eastwood has directed some films"
 repository.findByDirector("Clint Eastwood") >> [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 and: "Clint Eastwood has starred in some films"
 repository.findByActors("Clint Eastwood") >> [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO]
 when:
 def artistDetails = artistService.findArtistByName("Clint Eastwood")
 then:
 artistDetails.isPresent()
 and:
 artistDetails.get().name == "Clint Eastwood" &&
 artistDetails.get().filmsActedIn == [THE_GOOD_THE_BAD_AND_THE_UGLY, GRAN_TORINO] &&
 artistDetails.get().filmsDirected == [LETTERS_FROM_IWO_JIMA, GRAN_TORINO]
 }
  190. 190. Living Documentation
  191. 191. Living Documentation
  192. 192. Living Functional Documentation with Serenity and Cucumber
  193. 193. 65 Scenario: Adding movies
 Given the following movie has just come out
 | title | director | actors |
 | Jurassic World | Colin Trevorrow | Chris Pratt, Bryce Dallas Howard |
 When I add this movie to the catalog
 Then I should be able to find it in the catalog Executable Specifications Automated tests Living documentation
  194. 194. 66
  195. 195. 66 Context
  196. 196. 66 Context Narrative
  197. 197. 67
  198. 198. 67 Technical details
  199. 199. Living API Documentation 
 with Swagger Springfox
  200. 200. 69 YAML Specifications Documentation website Client libraries Test stubs
  201. 201. 70 @RequestMapping(method = GET)
 @ApiOperation("List all the movies in the catalog")
 public List<Movie> findAll() {
 return repository.findAll();
 }
 
 @RequestMapping(method = POST)
 @ApiOperation(value = "Add a new movie to the catalog", httpMethod = "POST")
 public Movie add(@RequestBody Movie newMovie) {
 return repository.save(newMovie);
 }
 
 @RequestMapping(value = "/{id}", method = DELETE)
 @ApiOperation(value = "Removing a movie from the catalog", httpMethod = "DELETE")
 public void delete(@PathVariable String id) {
 repository.delete(id);
 }
 Springfox Some annotations… Swagger and Spring Boot
  202. 202. 70 @RequestMapping(method = GET)
 @ApiOperation("List all the movies in the catalog")
 public List<Movie> findAll() {
 return repository.findAll();
 }
 
 @RequestMapping(method = POST)
 @ApiOperation(value = "Add a new movie to the catalog", httpMethod = "POST")
 public Movie add(@RequestBody Movie newMovie) {
 return repository.save(newMovie);
 }
 
 @RequestMapping(value = "/{id}", method = DELETE)
 @ApiOperation(value = "Removing a movie from the catalog", httpMethod = "DELETE")
 public void delete(@PathVariable String id) {
 repository.delete(id);
 }
 Springfox Some annotations… Swagger and Spring Boot
  203. 203. 70 @RequestMapping(method = GET)
 @ApiOperation("List all the movies in the catalog")
 public List<Movie> findAll() {
 return repository.findAll();
 }
 
 @RequestMapping(method = POST)
 @ApiOperation(value = "Add a new movie to the catalog", httpMethod = "POST")
 public Movie add(@RequestBody Movie newMovie) {
 return repository.save(newMovie);
 }
 
 @RequestMapping(value = "/{id}", method = DELETE)
 @ApiOperation(value = "Removing a movie from the catalog", httpMethod = "DELETE")
 public void delete(@PathVariable String id) {
 repository.delete(id);
 }
 Springfox Some annotations… Swagger and Spring Boot
  204. 204. 70 @RequestMapping(method = GET)
 @ApiOperation("List all the movies in the catalog")
 public List<Movie> findAll() {
 return repository.findAll();
 }
 
 @RequestMapping(method = POST)
 @ApiOperation(value = "Add a new movie to the catalog", httpMethod = "POST")
 public Movie add(@RequestBody Movie newMovie) {
 return repository.save(newMovie);
 }
 
 @RequestMapping(value = "/{id}", method = DELETE)
 @ApiOperation(value = "Removing a movie from the catalog", httpMethod = "DELETE")
 public void delete(@PathVariable String id) {
 repository.delete(id);
 }
 Springfox Some annotations… Swagger and Spring Boot
  205. 205. 71 Springfox @EnableAutoConfiguration
 @EnableSwagger2
 public class MovieServiceApplication {
 
 public static void main(String[] args) {
 SpringApplication.run(MovieServiceApplication.class, args);
 }
 
 @Bean
 public Docket moviesApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .select()
 .apis(RequestHandlerSelectors.any())
 .paths(PathSelectors.any())
 .build()
 .pathMapping("/")
 .directModelSubstitute(LocalDate.class, String.class)
 .genericModelSubstitutes(ResponseEntity.class);
 }
 } Some configuration… Swagger and Spring Boot
  206. 206. 72 Springfox Documentation
 bundled with your web services Swagger and Spring Boot
  207. 207. Production monitoring
  208. 208. Automated MonitoringFast provisioningA fast deployment pipeline So you want to micro-service?
  209. 209. Automated health checksReal operationsSmoke tests in production Simple checks may not be enough
  210. 210. An example with Spring Actuator @Component
 public class CatalogHealth implements HealthIndicator {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Override
 public Health health() {
 return (isCatalogStocked()) ? 
 Health.status(new Status("UP", "Movie count: " + movieRepository.count())).build() 
 : Health.down().build();
 }
 
 private boolean isCatalogStocked() {
 return (movieRepository.count() > 0);
 }
 }
  211. 211. An example with Spring Actuator @Component
 public class CatalogHealth implements HealthIndicator {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Override
 public Health health() {
 return (isCatalogStocked()) ? 
 Health.status(new Status("UP", "Movie count: " + movieRepository.count())).build() 
 : Health.down().build();
 }
 
 private boolean isCatalogStocked() {
 return (movieRepository.count() > 0);
 }
 } A Spring Actuator Health Check
  212. 212. An example with Spring Actuator @Component
 public class CatalogHealth implements HealthIndicator {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Override
 public Health health() {
 return (isCatalogStocked()) ? 
 Health.status(new Status("UP", "Movie count: " + movieRepository.count())).build() 
 : Health.down().build();
 }
 
 private boolean isCatalogStocked() {
 return (movieRepository.count() > 0);
 }
 } A Spring Actuator Health Check Custom logic to decide if the app is working
  213. 213. An example with Spring Actuator @Component
 public class MovieTransactionHealth implements HealthIndicator {
 
 @Autowired
 MovieController movieController;
 
 @Override
 public Health health() {
 return Health.status(transactionStatus()).build();
 }
 
 private Status transactionStatus() {
 try {
 Movie movie = new Movie("TEST title", "TEST description", "TEST director", ImmutableList.of("TEST actor"));
 Movie reloadedMovie = movieController.add(movie);
 movieController.delete(reloadedMovie.getId());
 return Status.UP;
 } catch (Throwable e) {
 return new Status("DOWN", e.toString());
 }
 }
 }
  214. 214. An example with Spring Actuator @Component
 public class MovieTransactionHealth implements HealthIndicator {
 
 @Autowired
 MovieController movieController;
 
 @Override
 public Health health() {
 return Health.status(transactionStatus()).build();
 }
 
 private Status transactionStatus() {
 try {
 Movie movie = new Movie("TEST title", "TEST description", "TEST director", ImmutableList.of("TEST actor"));
 Movie reloadedMovie = movieController.add(movie);
 movieController.delete(reloadedMovie.getId());
 return Status.UP;
 } catch (Throwable e) {
 return new Status("DOWN", e.toString());
 }
 }
 } More complex custom logic
  215. 215. An example with Spring Actuator @Component
 public class MovieTransactionHealth implements HealthIndicator {
 
 @Autowired
 MovieController movieController;
 
 @Override
 public Health health() {
 return Health.status(transactionStatus()).build();
 }
 
 private Status transactionStatus() {…}
 } @Component
 public class CatalogHealth implements HealthIndicator {
 
 @Autowired
 MovieRepository movieRepository;
 
 @Override
 public Health health() {
 return (isCatalogStocked()) ? 
 Health.status(new Status("UP", "Movie count: " + 
 movieRepository.count())).build() 
 : Health.down().build();
 }
 
 private boolean isCatalogStocked() {…}
 }
  216. 216. Try all this out at home! Install Gradle Install MongoDB Clone the repowakaleo/movie-service
  217. 217. Questions? John Ferguson Smart john.smart@wakaleo.com wakaleo http://www.wakaleo.com

×