package Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . integration . listener Ċ Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Zero Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġreactor . core . publisher . Mono Ċ import Ġsoftware . amazon . aw ssdk . services . sns . model . Message AttributeValue Ċ import Ġsoftware . amazon . aw ssdk . services . sns . model . Publish Request Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . component . Community ApiClient Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . component . EventType . ACTION _ PLAN _ SUBMIT TED Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . component . Inter ventions ApiClient Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . integration . Integration TestBase Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . Inter ventions Event Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . community api . Contact Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . community api . Create Notification Request Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . crs . Action Plan Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . crs . Contract Type Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . crs . Inter vention Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . crs . Sent Ref erral Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps deli us inter vention se vent listener . model . crs . ServiceProvider Ċ import Ġjava . net . URI Ċ import Ġjava . time . Offset DateTime Ċ import Ġjava . util . UUID Ċ Ċ class ĠS QS Listener Action Plan Submitted Test Ġ: ĠIntegration TestBase () Ġ{ ĊĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar ĠobjectMapper : ĠObjectMapper ĊĊĠ Ġ@ Value ("\ ${ h mp ps . sqs . topics . inter vention event stop ic . arn }") ĊĠ Ġlateinit Ġvar Ġinter ventions Event Topic Arn : ĠString ĊĊĠ Ġ@ Mock Bean ĊĠ Ġlateinit Ġvar Ġinter ventions ApiClient : ĠInter ventions ApiClient ĊĊĠ Ġ@ Mock Bean ĊĠ Ġlateinit Ġvar Ġcommunity ApiClient : ĠCommunity ApiClient ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Message Ġis Ġconsumed Ġof Ġqueue Ġbound Ġto Ġtopic `() Ġ{ ĊĊĠĠĠ Ġ// ĠGiven ĊĠĠĠ Ġval Ġservice Provider Ġ= ĠService Provider (" SP ĠName ", Ġ" 5 5 5 5 5 ") ĊĠĠĠ Ġval Ġinter vention Ġ= ĠInter vention ( UUID . randomUUID (), Ġ" Title ", Ġ" Desc ", Ġservice Provider , ĠContract Type (" ACC ", Ġ" Ac commod ation ")) ĊĠĠĠ Ġval Ġref erral Ġ= ĠSent Ref erral ( UUID . randomUUID (), Ġinter vention . id , Ġ" CR N 4 4 4 ", Ġ 1 2 3 L , Ġ" ABCDEF GH ", ĠOffset DateTime . now ()) ĊĠĠĠ Ġval Ġaction Plan Ġ= ĠAction Plan ( UUID . randomUUID (), Ġref erral . id , ĠOffset DateTime . now ()) ĊĠĠĠ Ġval Ġinter ventions BaseUrl Ġ= Ġ" http :// localhost : 8 0 8 0 " ĊĊĠĠĠ ĠsetUp Action Plan Lookup ( inter ventions BaseUrl , Ġaction Plan ) ĊĠĠĠ ĠsetUp Ref erral Lookup ( inter ventions BaseUrl , Ġref erral ) ĊĠĠĠ ĠsetUp Inter ventions Lookup ( inter ventions BaseUrl , Ġinter vention ) ĊĊĠĠĠ Ġval Ġcommunity Api BaseUrl Ġ= Ġ" http :// localhost : 8 0 9 1 " ĊĠĠĠ Ġval Ġnotification RequestBody Ġ= Ġbuild Notification Request ( inter vention , Ġref erral , Ġaction Plan ) ĊĊĠĠĠ ĠsetUp Community Api Call ( community Api BaseUrl , Ġnotification RequestBody ) ĊĊĠĠĠ Ġ// ĠWhen ĊĠĠĠ Ġval Ġmessage Ġ= ĠsetUp Action Plan Submitted Inter ventions Message ( inter ventions BaseUrl , Ġaction Plan ) ĊĠĠĠ Ġsns Client !!. publish ( message ) ĊĊĠĠĠ Ġ// ĠThen ĊĠĠĠ Ġverify Community Api Call ( community Api BaseUrl , Ġnotification RequestBody ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Message Ġis Ġplaced Ġin Ġdead Ġletter Ġqueue Ġafter Ġsuccess ive Ġfailures `() Ġ{ ĊĊĠĠĠ Ġ// ĠGiven ĊĠĠĠ Ġval Ġservice Provider Ġ= ĠService Provider (" SP ĠName ", Ġ" 5 5 5 5 5 ") ĊĠĠĠ Ġval Ġinter vention Ġ= ĠInter vention ( UUID . randomUUID (), Ġ" Title ", Ġ" Desc ", Ġservice Provider , ĠContract Type (" ACC ", Ġ" Ac commod ation ")) ĊĠĠĠ Ġval Ġref erral Ġ= ĠSent Ref erral ( UUID . randomUUID (), Ġinter vention . id , Ġ" CR N 4 4 4 ", Ġ 1 2 3 L , Ġ" ABCDEF GH ", ĠOffset DateTime . now ()) ĊĠĠĠ Ġval Ġaction Plan Ġ= ĠAction Plan ( UUID . randomUUID (), Ġref erral . id , ĠOffset DateTime . now ()) ĊĠĠĠ Ġval Ġinter ventions BaseUrl Ġ= Ġ" http :// localhost : 8 0 8 0 " ĊĊĠĠĠ ĠsetUp Action Plan Lookup NotFound ( inter ventions BaseUrl , Ġaction Plan . id ) ĊĊĠĠĠ Ġ// ĠWhen ĊĠĠĠ Ġval Ġmessage Ġ= ĠsetUp Action Plan Submitted Inter ventions Message ( inter ventions BaseUrl , Ġaction Plan ) ĊĠĠĠ Ġsns Client !!. publish ( message ) ĊĊĠĠĠ Ġ// ĠThen ĊĠĠĠ Ġverify Message On Dead Letter Queue After Failure () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġverify Community Api Call ( community Api BaseUrl : ĠString , Ġexpected Notification RequestBody : ĠCreate Notification Request ) Ġ{ ĊĠĠĠ Ġno Messages Currently On Queue ( sqs Client , Ġqueue Url !! ) ĊĠĠĠ Ġno Messages Currently On Queue ( sqs Client , Ġdead Letter Queue Url !! ) ĊĊĠĠĠ Ġverify ( community ApiClient ). post ( ĊĠĠĠĠĠ Ġeq ( URI . create ("$ community Api BaseUrl / secure / off enders / cr n / CR N 4 4 4 / sentences / 1 2 3 / notifications / context / commission ed - reh abil itation - services ")), ĊĠĠĠĠĠ Ġeq ( expected Notification RequestBody ), ĊĠĠĠĠĠ Ġeq ( Contact :: class ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġverify Message On Dead Letter Queue After Failure () Ġ{ ĊĠĠĠ Ġverify Zero Interactions ( community ApiClient ) ĊĠĠĠ Ġno Messages Currently On Queue ( sqs Client , Ġqueue Url !! ) ĊĠĠĠ Ġone Message Currently On Queue ( sqs Client , Ġdead Letter Queue Url !! ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Action Plan Lookup ( inter ventions BaseUrl : ĠString , Ġaction Plan : ĠAction Plan ) Ġ{ ĊĠĠĠ Ġwhenever ( inter ventions ApiClient . get ( eq ( URI . create ("$ inter ventions BaseUrl / action - plan /${ action Plan . id }") ), Ġeq ( Action Plan :: class ))). thenReturn ( Mono . just ( action Plan )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Action Plan Lookup NotFound ( inter ventions BaseUrl : ĠString , Ġaction Plan Id : ĠUUID ) Ġ{ ĊĠĠĠ Ġwhenever ( inter ventions ApiClient . get ( eq ( URI . create ("$ inter ventions BaseUrl / action - plan /$ action Plan Id ")), Ġeq ( Action Plan :: class ))). thenReturn ( Mono . empty ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Ref erral Lookup ( inter ventions BaseUrl : ĠString , Ġref erral : ĠSent Ref erral ) Ġ{ ĊĠĠĠ Ġwhenever ( inter ventions ApiClient . get ( eq ( URI . create ("$ inter ventions BaseUrl / sent - ref erral /${ ref erral . id }") ), Ġeq ( Sent Ref erral :: class ))). thenReturn ( Mono . just ( ref erral )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Inter ventions Lookup ( inter ventions BaseUrl : ĠString , Ġinter vention : ĠInter vention ) Ġ{ ĊĠĠĠ Ġwhenever ( inter ventions ApiClient . get ( eq ( URI . create ("$ inter ventions BaseUrl / inter vention /${ inter vention . id }") ), Ġeq ( Inter vention :: class ))). thenReturn ( Mono . just ( inter vention )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Community Api Call ( community Api BaseUrl : ĠString , Ġcreate Notification Request : ĠCreate Notification Request ) Ġ{ ĊĠĠĠ Ġwhenever ( ĊĠĠĠĠĠ Ġcommunity ApiClient . post ( ĊĠĠĠĠĠĠĠ Ġeq ( URI . create ("$ community Api BaseUrl / secure / off enders / cr n / CR N 4 4 4 / sentences / 1 2 3 / notifications / context / commission ed - reh abil itation - services ")), ĊĠĠĠĠĠĠĠ Ġeq ( create Notification Request ), ĊĠĠĠĠĠĠĠ Ġeq ( Contact :: class ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ). thenReturn ( Mono . just ( Contact ( 9 9 9 L ))) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetUp Action Plan Submitted Inter ventions Message ( inter ventions BaseUrl : ĠString , Ġaction Plan : ĠAction Plan ): ĠPublish Request ? Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= ĠInter ventions Event ( 1 , ĠACTION _ PLAN _ SUBMIT TED . value , Ġ" Description ", Ġ"$ inter ventions BaseUrl / action - plan /${ action Plan . id }", ĠOffset DateTime . now (), Ġempty Map ()) ĊĠĠĠ Ġval Ġmessage Attributes Ġ= Ġmap Of ( ĊĠĠĠĠĠ Ġ" eventType " Ġto ĠMessage AttributeValue . builder () ĊĠĠĠĠĠĠĠ Ġ. dataType (" String ") ĊĠĠĠĠĠĠĠ Ġ. stringValue ( ACTION _ PLAN _ SUBMIT TED . value ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ) ĊĠĠĠ Ġreturn ĠPublish Request . builder () ĊĠĠĠĠĠ Ġ. message Attributes ( message Attributes ) ĊĠĠĠĠĠ Ġ. message ( object Mapper . writeValue AsString ( event )) ĊĠĠĠĠĠ Ġ. topic Arn ( inter ventions Event Topic Arn ) ĊĠĠĠĠĠ Ġ. build () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġbuild Notification Request ( inter vention : ĠInter vention , Ġref erral : ĠSent Ref erral , Ġaction Plan : ĠAction Plan ) Ġ= ĊĠĠĠ ĠCreate Notification Request ( ĊĠĠĠĠĠ Ġinter vention . contract Type . code , ĊĠĠĠĠĠ Ġref erral . sent At , ĊĠĠĠĠĠ Ġref erral . id , ĊĠĠĠĠĠ Ġaction Plan . submitted At , ĊĠĠĠĠĠ Ġ""" Action ĠPlan ĠSub mitted Ġfor Ġ${ inter vention . contract Type . name } ĠRef erral Ġ${ ref erral . reference Number } Ġwith ĠPrime ĠProvider Ġ${ inter vention . service Provider . name } Ċ http :// localhost : 3 0 0 0 / prob ation - pract itioner / ref err als /${ ref erral . id }/ action - plan Ċ ( not ified Ġvia Ġdeli us - inter ventions - event - listener ) """, ĊĠĠĠ Ġ) Ċ } Ċ