/* Ċ Ġ* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠNet flix , ĠInc . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License ") Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ* Ċ Ġ*/ Ċ package Ġcom . netflix . spin n aker . ke el . events Ċ Ċ import Ġcom . netflix . spin n aker . ke el . api . act uation . Task Ċ import Ġcom . netflix . spin n aker . ke el . api . application Ċ import Ġcom . netflix . spin n aker . ke el . api . id Ċ import Ġcom . netflix . spin n aker . ke el . core . Resource Currently Un res olvable Ċ import Ġcom . netflix . spin n aker . ke el . exceptions . Invalid Resource FormatException Ċ import Ġcom . netflix . spin n aker . ke el . pause . Act uation Pa user Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . ACT U ATING Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . CREATED Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . CURRENT LY _ UN RESOL V ABLE Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . DIFF Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . ERROR Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . H AP PY Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . PA USED Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . RE SU MED Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Resource Status . UN H AP PY Ċ import Ġcom . netflix . spin n aker . ke el . persistence . memory . InMemory Paused Repository Ċ import Ġcom . netflix . spin n aker . ke el . services . Resource History Service Ċ import Ġcom . netflix . spin n aker . ke el . test . combined InMemory Repository Ċ import Ġcom . netflix . spin n aker . ke el . test . resource Ċ import Ġcom . netflix . spin n aker . time . Mutable Clock Ċ import Ġdev . min ut est . junit . JUnit 5 Min ut ests Ċ import Ġdev . min ut est . root Context Ċ import Ġio . mock k . every Ċ import Ġio . mock k . slot Ċ import Ġstri kt . api . expect That Ċ import Ġstri kt . assertions . isEqualTo Ċ Ċ internal Ġclass ĠResource Status Tests Ġ: ĠJ Unit 5 Min ut ests Ġ{ ĊĠ Ġobject ĠFix ture Ġ{ ĊĠĠĠ Ġval Ġclock Ġ= ĠMutable Clock () ĊĠĠĠ Ġval Ġrepository Ġ= Ġcombined InMemory Repository ( clock ) ĊĠĠĠ Ġval Ġpaused Repository Ġ= ĠIn Memory Paused Repository () ĊĠĠĠ Ġval Ġact uation Pa user Ġ= ĠAct uation Pa user ( repository . resource Repository , Ġpaused Repository , Ġrepository . publisher , Ġclock ) ĊĠĠĠ Ġval Ġresource History Service Ġ= ĠResource History Service ( repository , Ġact uation Pa user ) ĊĠĠĠ Ġval Ġresource Ġ= Ġresource () ĊĠĠĠ Ġval Ġcreated Event Ġ= ĠResource Created ( resource ) ĊĠĠĠ Ġval Ġmissing Event Ġ= ĠResource Missing ( resource ) ĊĠĠĠ Ġval Ġdelta Detected Event Ġ= ĠResource Delta Detected ( resource , Ġmap Of (" hi " Ġto Ġ" wow ")) ĊĠĠĠ Ġval Ġact uation La unched Event Ġ= ĠResource Act uation La unched ( resource , Ġ" resource Handler Plugin ", ĠlistOf ( Task (" 1 ", Ġ" task Ġname "))) ĊĠĠĠ Ġval Ġdelta Resolved Event Ġ= ĠResource Delta Resolved ( resource ) ĊĠĠĠ Ġval Ġdependency Missing Event Ġ= ĠResource Check Un res olvable ( resource , Ġobject Ġ: ĠResource Currently Un res olvable (" I Ġguess ĠI Ġcan 't Ġfind Ġthe ĠA MI Ġor Ġsomething ") Ġ{}) ĊĠĠĠ Ġval Ġerror Event Ġ= ĠResource Check Error ( resource , ĠInvalid Resource FormatException (" bad Ġresource ", Ġ" who Ġknows ")) ĊĠĠĠ Ġval Ġresource Valid Event Ġ= ĠResource Valid ( resource ) ĊĠĠĠ Ġval Ġuser Ġ= Ġ" ke el @ ke el . io " ĊĠ Ġ} ĊĊĠ Ġfun Ġtests () Ġ= Ġroot Context < Fixture > Ġ{ ĊĠĠĠ Ġfixture Ġ{ ĠFix ture Ġ} ĊĊĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠ Ġrepository . store Resource ( resource ) ĊĠĠĠĠĠ Ġrepository . append Resource History ( created Event ) ĊĊĠĠĠĠĠ Ġval Ġevent Ġ= Ġslot < Persistent Event >() ĊĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . publisher . publish Event ( capture ( event )) ĊĠĠĠĠĠ Ġ} Ġanswers Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( event . captured Ġis ĠApplication Event ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġrepository . append Application History ( event . captured Ġas ĠApplication Event ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġrepository . append Resource History ( event . captured Ġas ĠResource Event ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġafter Ġ{ ĊĠĠĠĠĠ Ġrepository . drop All () ĊĠĠĠĠĠ Ġpaused Repository . flush () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġcreated ") Ġ{ ĊĠĠĠĠĠ Ġtest (" returns Ġcreated Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( CREATED ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġmissing ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġdiff Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( DIFF ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġdelta Ġwas Ġdetected ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġdiff Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( DIFF ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġact uation Ġlaunched ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġact u ating Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( ACT U ATING ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġis Ġfl apping ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġun happy Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( UN H AP PY ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġconver ged Ġfinally ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Resolved Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġhappy Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( H AP PY ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġdelta Ġresolved ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( missing Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( act uation La unched Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Resolved Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġhappy Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( H AP PY ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġvalid ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( resource Valid Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġhappy Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( H AP PY ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġin Ġerror Ġstate ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( error Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġerror Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( ERROR ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġact uation Ġpaused ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġact uation Pa user . pause Resource ( resource . id , Ġuser ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġpaused Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( PA USED ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġact uation Ġres umed ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġact uation Pa user . pause Resource ( resource . id , Ġuser ) ĊĠĠĠĠĠĠĠ Ġclock . tick Minutes ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġact uation Pa user . resume Resource ( resource . id , Ġuser ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġres umed Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( RE SU MED ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" resource Ġdependency Ġis Ġmissing ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( delta Detected Event ) ĊĠĠĠĠĠĠĠ Ġrepository . append Resource History ( dependency Missing Event ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġdiff Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( CURRENT LY _ UN RESOL V ABLE ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" application Ġact uation Ġpaused ") Ġ{ ĊĠĠĠĠĠ Ġcontext (" after Ġresource Ġcreated ") Ġ{ ĊĠĠĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġact uation Pa user . pause Application ( resource . application , Ġuser ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġtest (" returns Ġpaused Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( PA USED ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġcontext (" before Ġresource Ġcreated ") Ġ{ ĊĠĠĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġrepository . delete Resource ( resource . id ) ĊĠĠĠĠĠĠĠĠĠ Ġact uation Pa user . pause Application ( resource . application , Ġuser ) ĊĠĠĠĠĠĠĠĠĠ Ġclock . tick Minutes ( 1 0 ) ĊĠĠĠĠĠĠĠĠĠ Ġrepository . store Resource ( resource ) ĊĠĠĠĠĠĠĠĠĠ Ġrepository . append Resource History ( created Event ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġtest (" returns Ġpaused Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( PA USED ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġcontext (" before Ġresource Ġcreated , Ġbut Ġres umed Ġafter ") Ġ{ ĊĠĠĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġrepository . delete Resource ( resource . id ) ĊĠĠĠĠĠĠĠĠĠ Ġact uation Pa user . pause Application ( resource . application , Ġuser ) ĊĠĠĠĠĠĠĠĠĠ Ġclock . tick Minutes ( 1 0 ) ĊĠĠĠĠĠĠĠĠĠ Ġrepository . store Resource ( resource ) ĊĠĠĠĠĠĠĠĠĠ Ġrepository . append Resource History ( created Event ) ĊĠĠĠĠĠĠĠĠĠ Ġclock . tick Minutes ( 1 0 ) ĊĠĠĠĠĠĠĠĠĠ Ġact uation Pa user . resume Application ( resource . application , Ġuser ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġtest (" returns Ġres umed Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( RE SU MED ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcontext (" application Ġact uation Ġpaused Ġand Ġres umed Ġafter Ġresource Ġcreated ") Ġ{ ĊĠĠĠĠĠ Ġbefore Ġ{ ĊĠĠĠĠĠĠĠ Ġact uation Pa user . pause Application ( resource . application , Ġuser ) ĊĠĠĠĠĠĠĠ Ġclock . tick Minutes ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġact uation Pa user . resume Application ( resource . application , Ġuser ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġtest (" returns Ġres umed Ġstatus ") Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect That ( resource History Service . getStatus ( resource . id )). isEqualTo ( RE SU MED ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ