package Ġlibrary . integration . slack . messaging Ċ Ċ import Ġau . com . di us . p act . consumer . Message P act Builder Ċ import Ġau . com . di us . p act . consumer . P act Ċ import Ġau . com . di us . p act . consumer . dsl . P act Dsl Json Body Ċ import Ġau . com . di us . p act . consumer . junit 5 . P act Consumer Test Ext Ċ import Ġau . com . di us . p act . consumer . junit 5 . P act Test For Ċ import Ġau . com . di us . p act . consumer . junit 5 . Provider Type Ċ import Ġau . com . di us . p act . model . v 3 . messaging . Message Ċ import Ġau . com . di us . p act . model . v 3 . messaging . Message P act Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . check Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġlibrary . integration . slack . core . Book Added EventHandler Ċ import Ġlibrary . integration . slack . core . Slack Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . springframework . amqp . core . Message Properties Ċ import Ġorg . springframework . amqp . rabbit . connection . ConnectionFactory Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Component Scan Ċ import Ġorg . springframework . test . context . Context Configuration Ċ import Ġutils . shouldBe EqualTo Ċ import Ġutils . classification . Contract Test Ċ import Ġutils . extensions . Enable Spring Extension Ċ import Ġutils . messaging . Book Events Message Provider . Companion . book Added Event Ċ import Ġutils . object Mapper Ċ Ċ @ SpringBootTest Ċ @ Contract Test Ċ @ Enable Spring Extension Ċ @ Extend With ( P act Consumer Test Ext :: class ) Ċ @ Context Configuration ( classes Ġ= Ġ[ Book Added Message Contract Test . Test Configuration :: class ]) Ċ class ĠBook Added Message Contract Test Ġ{ ĊĊĠĠĠ Ġ@ Component Scan ( base Package Classes Ġ= Ġ[ Book Added Message Consumer :: class , ĠBook Added EventHandler :: class ]) ĊĠĠĠ Ġclass ĠTest Configuration Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Bean ĊĠĠĠĠĠĠĠ Ġfun ĠobjectMapper Custom () Ġ= ĠobjectMapper () ĊĊĠĠĠĠĠĠĠ Ġ@ Bean ĊĠĠĠĠĠĠĠ Ġfun Ġslack (): ĠSlack Ġ= Ġmock () ĊĊĠĠĠĠĠĠĠ Ġ@ Bean ĊĠĠĠĠĠĠĠ Ġfun Ġconnection Factory (): ĠConnection Factory Ġ= Ġmock () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠCON SUM ER Ġ= Ġ" library - integration - slack " ĊĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠPRO VIDER Ġ= Ġ" library - service " ĊĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠP ACT _ DIR Ġ= Ġ" build / p acts " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġbook Added EventHandler : ĠBook Added EventHandler ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar ĠobjectMapper : ĠObjectMapper ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġbook Added Message Consumer : ĠBook Added Message Consumer ĊĊĊĠĠĠ Ġ@ P act ( provider Ġ= ĠPRO VIDER , Ġconsumer Ġ= ĠCON SUM ER ) ĊĠĠĠ Ġfun Ġcreate P act ( builder : ĠMessage P act Builder ): ĠMessage P act Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. given (" new Ġbook Ġhas Ġbeen Ġadded Ġto Ġthe Ġlibrary ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect sTo Receive (" event Ġfor Ġbook - added Ġis Ġreceived ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Content ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠP act Dsl Json Body () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. string Type (" isbn ", Ġbook Added Event . isbn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. string Type (" title ", Ġbook Added Event . title ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to P act () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ P act Test For ( p act Method Ġ= Ġ" create P act ", Ġprovider Type Ġ= ĠProvider Type . ASY N CH ) ĊĠĠĠ Ġfun Ġ` book Ġadded Ġevent Ġcontract Ġtest `( messages : ĠList < Message >) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// gets Ġthe Ġmessage Ġfrom Ġthe Ġp act Ġmock Ġserver ĊĠĠĠĠĠĠĠ Ġval Ġmessage Converted Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġorg . springframework . amqp . core . Message ( messages . first (). contents As Bytes (), ĠMessage Properties ()) ĊĊĠĠĠĠĠĠĠ Ġbook Added Message Consumer . on Message ( message Converted ) Ġ// Ġmessage Ġis Ġsent Ġon Ġthe Ġconsumer ĊĊĠĠĠĠĠĠĠ Ġverify ( book Added EventHandler ). handle Book Added ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit . isbn ĠshouldBe EqualTo Ġbook Added Event . isbn ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit . title ĠshouldBe EqualTo Ġbook Added Event . title ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ }