package Ġio . kf leet . owner . service . processors ĊĊ Ċ import Ġio . kf leet . commands . Command Status Ċ import Ġio . kf leet . common . configuration . ObjectMapper Config Ċ import Ġio . kf leet . common . custom Retry Ċ import Ġio . kf leet . owner . service . Web Configuration Ċ import Ġio . kf leet . owner . service . domain . Car Model Ċ import Ġio . kf leet . owner . service . repos .* Ċ import Ġio . kf leet . owner . service . web . New Car Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . condition . Enabled If EnvironmentVariable Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . context . annotation . Import Ċ import Ġorg . springframework . test . context . Context Configuration Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ import Ġtesting . Kafka Context Initializer Ċ import Ġkotlin . test .* Ċ Ċ @ Enabled If EnvironmentVariable ( named Ġ= Ġ" ENV ", Ġmatches Ġ= Ġ" ci ") Ċ @ Extend With ( Spring Extension :: class ) Ċ @ SpringBootTest ( web Environment Ġ= ĠSpring Boot Test . Web Environment . DEFINED _ PORT ) Ċ @ Context Configuration ( initial izers Ġ= Ġ[ Kafka Context Initializer :: class ]) Ċ @ Import ( ObjectMapper Config :: class , ĠWeb Configuration :: class ) Ċ class ĠProcessor Integration Tests Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġrepo : ĠOwner Repository ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġcommands Response Repository : ĠCommands Response Repository ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Create Owner Command () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġowner Name Ġ= Ġ" test " ĊĠĠĠĠĠĠĠ Ġval Ġowner Id Ġ= Ġ" 1 " ĊĠĠĠĠĠĠĠ Ġval Ġcreate Owner Params Ġ= ĠCreate Owner Params ( owner Id Ġ= Ġowner Id , Ġowner Name Ġ= Ġowner Name ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= Ġrepo . submit Create Owner Command ( create Owner Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Id ) Ġ{ Ġcommand . get OwnerId () Ġ} ĊĠĠĠĠĠĠĠ Ġexpect ( owner Name ) Ġ{ Ġcommand . getName () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Response Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( command . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . SUCCEEDED , Ġcommand Response . getStatus ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( owner Id , Ġcommand Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠ Ġassert Not Equals ( owner Id , Ġcommand Response . get Command Id ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġowner Ġ= Ġrepo ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. findById ( command Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry (). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( owner ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Name ) Ġ{ Ġowner . getName () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval ĠnewName Ġ= Ġ" test 2 " ĊĠĠĠĠĠĠĠ Ġval Ġupdate Owner Name Params Ġ= ĠUpdate Owner Params ( owner Id Ġ= Ġowner Id , Ġowner Name Ġ= ĠnewName ) ĊĊĠĠĠĠĠĠĠ Ġval Ġupdate Command Ġ= Ġrepo . submit Update Owner Name Command ( update Owner Name Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( update Command ) ĊĊĊĠĠĠĠĠĠĠ Ġval Ġupdate Command Response Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( update Command . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( update Command Response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . SUCCEEDED , Ġupdate Command Response . getStatus ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġupdated Owner Ġ= Ġrepo ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. findById ( update Command Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry (). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( updated Owner ) ĊĠĠĠĠĠĠĠ Ġexpect ( new Name ) Ġ{ Ġupdated Owner . getName () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Create Owner Command Rejected () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġowner Name Ġ= Ġ" test 2 " ĊĠĠĠĠĠĠĠ Ġval Ġowner Id Ġ= Ġ" 2 " ĊĠĠĠĠĠĠĠ Ġval Ġcreate Owner Params Ġ= ĠCreate Owner Params ( owner Id Ġ= Ġowner Id , Ġowner Name Ġ= Ġowner Name ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Succeeded Ġ= Ġrepo . submit Create Owner Command ( create Owner Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Succeeded ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Rejected Ġ= Ġrepo . submit Create Owner Command ( create Owner Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Rejected ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Response Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( command Rejected . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . RE JECT ED , Ġcommand Response . getStatus ()) ĊĠĠĠĠĠĠĠ ĠassertNull ( command Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠ Ġassert Not Equals ( owner Id , Ġcommand Response . get Command Id ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" Owner Ġwith Ġid Ġ$ owner Id Ġalready Ġexists ", Ġcommand Response . get Reason ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Delete Owner Command () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġowner Name Ġ= Ġ" test " ĊĠĠĠĠĠĠĠ Ġval Ġowner Id Ġ= Ġ" 1 " ĊĠĠĠĠĠĠĠ Ġval Ġcreate Owner Params Ġ= ĠCreate Owner Params ( owner Id Ġ= Ġowner Id , Ġowner Name Ġ= Ġowner Name ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= Ġrepo . submit Create Owner Command ( create Owner Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command ) ĊĊĠĠĠĠĠĠĠ Ġrepo . findById ( owner Id ). custom Retry (). block () ĊĊĊĠĠĠĠĠĠĠ Ġval Ġdelete Owner Command Ġ= ĠDelete Owner Params ( owner Id Ġ= Ġowner Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Delete Ġ= Ġrepo . submit Delete Owner Command ( delete Owner Command ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Delete ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Id ) Ġ{ Ġcommand Delete . get OwnerId () Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Delete Response Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( command Delete . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Delete Response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . SUCCEEDED , Ġcommand Delete Response . getStatus ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( owner Id , Ġcommand Delete Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠ Ġassert Not Equals ( owner Id , Ġcommand Delete Response . get Command Id ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Register An Dere gister Car Command () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġowner Name Ġ= Ġ" test " ĊĠĠĠĠĠĠĠ Ġval Ġowner Id Ġ= Ġ" 3 " ĊĠĠĠĠĠĠĠ Ġval Ġcreate Owner Params Ġ= ĠCreate Owner Params ( owner Id Ġ= Ġowner Id , Ġowner Name Ġ= Ġowner Name ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= Ġrepo . submit Create Owner Command ( create Owner Params ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command ) ĊĊĠĠĠĠĠĠĠ Ġrepo . findById ( owner Id ). custom Retry (). block () ĊĊĠĠĠĠĠĠĠ Ġval Ġnew Car Ġ= ĠNew Car ( Car Model . Model X ) ĊĠĠĠĠĠĠĠ Ġval Ġregister Car Command Ġ= ĠRegister Car Params ( owner Id Ġ= Ġowner Id , Ġnew Car Ġ= Ġnew Car ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Register Car Ġ= Ġrepo . submit Register Car Command ( register Car Command ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Register Car ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Id ) Ġ{ Ġcommand Register Car . get OwnerId () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Response Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( command Register Car . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . SUCCEEDED , Ġcommand Response . getStatus ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( owner Id , Ġcommand Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠ Ġassert Not Equals ( owner Id , Ġcommand Response . get Command Id ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġowner Ġ= Ġrepo ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. findById ( command Response . getR ess ource Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry (). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( owner ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Name ) Ġ{ Ġowner . getName () Ġ} ĊĠĠĠĠĠĠĠ Ġexpect ( 1 ) Ġ{ Ġowner . getC ars (). size Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġdere gister Car Command Ġ= ĠD ere gister Car Params ( owner Id Ġ= Ġowner Id , Ġcar Id Ġ= Ġowner . getC ars (). get ( 0 ). getId ()) ĊĠĠĠĠĠĠĠ Ġval Ġcommand Dere gister Car Ġ= Ġrepo . submit Dere gister Car Command ( dere gister Car Command ). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Dere gister Car ) ĊĠĠĠĠĠĠĠ Ġexpect ( owner Id ) Ġ{ Ġcommand Dere gister Car . get OwnerId () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcommand Response Dere g Ġ= Ġcommands Response Repository ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Command Response ( command Dere gister Car . get Command Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( command Response Dere g ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Command Status . SUCCEEDED , Ġcommand Response Dere g . getStatus ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġowner Dere gister ed Car Ġ= Ġrepo ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. findById ( command Response Dere g . getR ess ource Id ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. custom Retry (). block () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( owner Dere gister ed Car ) ĊĠĠĠĠĠĠĠ Ġexpect ( 0 ) Ġ{ Ġowner Dere gister ed Car . getC ars (). size Ġ} ĊĠĠĠ Ġ} Ċ } ĊĊĊ