Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Your Message-Driven Application With Spring

Testing Your Message-Driven Application With Spring

Jakub Pilimon

May 21, 2018
Tweet

More Decks by Jakub Pilimon

Other Decks in Programming

Transcript

  1. 1 © 2018 Pivotal Testing your Message-Driven Application with Spring

    Jakub Pilimon, @JakubPilimon https://github.com/spring-cloud-samples/messaging-application
  2. 2 Spring Developer Advocate @Pivotal Trainer @Bottega Interested in •

    Domain-Driven Design • Architecture • Test-Driven Development About me Twitter: @JakubPilimon Blog: http://pillopl.github.io #dddbyexamples
  3. 3

  4. 5 Why Messaging? CREDIT CARD APPLICATION CONTROLLER APPLY FOR CARD

    SERVICE CREDIT CARD DOMAIN EVENT PUBLISHER CREDIT CARD REPOSITORY CONSUMER (MAIL, REPORT, ETC)
  5. 6

  6. 7

  7. 8 Why Messaging? CREDIT CARD APPLICATION CONTROLLER APPLY FOR CARD

    SERVICE CREDIT CARD DOMAIN EVENT PUBLISHER CREDIT CARD REPOSITORY CONSUMER (MAIL, REPORT, ETC) def 'should emit CardGranted when client born in 70s or later'() { when: applyForCardService.apply("89121514667") then: 1 * domainEventsPublisher.publish( { it instanceof CardGranted } ) }
  8. 9 Why Messaging? CREDIT CARD APPLICATION CONTROLLER APPLY FOR CARD

    SERVICE CREDIT CARD DOMAIN EVENT PUBLISHER CREDIT CARD REPOSITORY CONSUMER (MAIL, REPORT, ETC) @Test public void shouldEmitCardGrantedEvent() { // when cardApplicationController.applyForCard(new CardApplication("70345678")); // then verify(domainEventsPublisher).publish(isA(CardGranted.class)); }
  9. 10 Why Messaging? CREDIT CARD APPLICATION CONTROLLER APPLY FOR CARD

    SERVICE CREDIT CARD DOMAIN EVENT PUBLISHER CREDIT CARD REPOSITORY CONSUMER (MAIL, REPORT, ETC) def 'should be able to get card when born in 70s or later'() { when: cardApplicationController.applyForCard(new CardApplication("70345678")) then: events.poll().getPayload().contains("card-granted") }
  10. 11

  11. 12 Why Messaging? CREDIT CARD APPLICATION CONTROLLER APPLY FOR CARD

    SERVICE CREDIT CARD DOMAIN EVENT PUBLISHER CREDIT CARD REPOSITORY CONSUMER (MAIL, REPORT, ETC) label: card_rejected input: triggeredBy: sendRejected() outputMessage: sentTo: channel headers: type: card-application-rejected contentType: application/json body: clientPesel: 86010156812 timestamp: 2018-01-01T12:12:12.000Z matchers: body: - path: $.timestamp type: by_regex predefined: iso_8601_with_offset
  12. 13