package Ġuk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . integration Ċ Ċ import Ġorg . fly way db . core . Fly way Ċ import Ġorg . junit . jupiter . api . After All Ċ import Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . context . SpringBootTest . Web Environment . RANDOM _ PORT Ċ import Ġorg . springframework . http . HttpHeaders Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . test . web . reactive . server . Web Test Client Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . Jwt Auth Helper Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . integration . wire mock . OAuth Mock Server Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . integration . wire mock . Pr ison Api Mock Server Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . integration . wire mock . Pr isoner Search Api Mock Server Ċ Ċ @ SpringBootTest ( web Environment Ġ= ĠR AN DOM _ PORT ) Ċ abstract Ġclass ĠIntegration TestBase Ġ{ ĊĊĠ Ġ@ Suppress (" Spring Java Injection Points Autow iring Inspection ") ĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġweb Test Client : ĠWeb Test Client ĊĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġfly way : ĠFly way ĊĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġjwt Auth Helper : ĠJwt Auth Helper ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġinternal Ġval Ġpr ison Api Mock Server Ġ= ĠPr ison Api Mock Server () ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġinternal Ġval Ġpr isoner Search Api Mock Server Ġ= ĠPr isoner Search Api Mock Server () ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġinternal Ġval Ġo Auth Mock Server Ġ= ĠOAuth Mock Server () ĊĊĠĠĠ Ġ@ Before All ĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġstart Mocks () Ġ{ ĊĠĠĠĠĠ Ġo Auth Mock Server . start () ĊĠĠĠĠĠ Ġo Auth Mock Server . stub Grant Token () ĊĊĠĠĠĠĠ Ġpr ison Api Mock Server . start () ĊĠĠĠĠĠ Ġpr isoner Search Api Mock Server . start () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After All ĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġstop Mocks () Ġ{ ĊĠĠĠĠĠ Ġpr ison Api Mock Server . stop () ĊĠĠĠĠĠ Ġpr isoner Search Api Mock Server . stop () ĊĠĠĠĠĠ Ġo Auth Mock Server . stop () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ After Each ĊĠ Ġfun Ġreset Db () Ġ{ ĊĠĠĠ Ġfly way . clean () ĊĠĠĠ Ġfly way . migrate () ĊĠ Ġ} ĊĊĠ Ġfun Ġset Headers ( contentType : ĠMediaType Ġ= ĠMediaType . APPLICATION _ JSON , Ġusername : ĠString ? Ġ= Ġ" IT AG _ USER "): Ġ( HttpHeaders ) Ġ-> ĠUnit Ġ= Ġ{ ĊĠĠĠ Ġit . set Bearer Auth ( jwt Auth Helper . create Jwt ( subject Ġ= Ġusername )) ĊĠĠĠ Ġit . contentType Ġ= ĠcontentType ĊĠ Ġ} ĊĊĠ Ġfun Ġload Resource File ( fileName : ĠString ): ĠString Ġ{ ĊĠĠĠ Ġval ĠpackageName Ġ= Ġ" uk . gov . just ice . digital . h mp ps . h mp ps restricted pat ients api . integration " ĊĠĠĠ Ġreturn Ġjava Class . getResource ("/ $ packageName /$ fileName "). read Text () ĊĠ Ġ} ĊĊĠ Ġfun Ġget Restricted Patient ( pr isoner Number : ĠString Ġ= Ġ" A 1 2 3 4 5 "): ĠWeb Test Client . Request Headers Spec < *> Ġ= ĊĠĠĠ Ġweb Test Client . get (). uri ("/ restricted - patient / pr ison - number /$ pr isoner Number ") ĊĠĠĠĠĠ Ġ. headers ( set Headers ()) ĊĊĠ Ġfun Ġdis charge Pr isoner Web Client ( ĊĠĠĠ Ġpr isoner Number : ĠString , ĊĠĠĠ Ġcomment Text : ĠString Ġ= Ġ" Pr isoner Ġwas Ġreleased Ġon Ġbail ", ĊĠĠĠ Ġdis charge Time : ĠString Ġ= Ġ" 2 0 2 1 - 0 6 - 0 7 T 1 3 : 4 0 : 3 2 . 4 9 8 Z ", ĊĠĠĠ Ġfrom Location Id : ĠString Ġ= Ġ" M DI ", ĊĠĠĠ Ġhospital Location Code : ĠString Ġ= Ġ" H AZ L WD ", ĊĠĠĠ Ġsupporting Pr ison Id : ĠString Ġ= Ġ" M DI " ĊĊĠ Ġ): ĠWeb Test Client . Request Headers Spec < *> Ġ{ ĊĠĠĠ Ġpr ison Api Mock Server . stub Ag ency Location For Pr is ons () ĊĠĠĠ Ġpr ison Api Mock Server . stub Ag ency Location For Ho sp it als () ĊĠĠĠ Ġpr ison Api Mock Server . stub Dis charge To Pr ison ( pr isoner Number ) ĊĠĠĠ Ġpr isoner Search Api Mock Server . stub Search By Pr ison Number ( pr isoner Number ) ĊĊĠĠĠ Ġreturn Ġweb Test Client ĊĠĠĠĠĠ Ġ. post () ĊĠĠĠĠĠ Ġ. uri ("/ dis charge - to - hospital ") ĊĠĠĠĠĠ Ġ. headers ( set Headers ()) ĊĠĠĠĠĠ Ġ. body Value ( ĊĠĠĠĠĠĠĠ Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠ Ġ" off ender No " Ġto Ġpr isoner Number , ĊĠĠĠĠĠĠĠĠĠ Ġ" comment Text " Ġto Ġcomment Text , ĊĠĠĠĠĠĠĠĠĠ Ġ" dis charge Time " Ġto Ġdis charge Time , ĊĠĠĠĠĠĠĠĠĠ Ġ" from Location Id " Ġto Ġfrom Location Id , ĊĠĠĠĠĠĠĠĠĠ Ġ" hospital Location Code " Ġto Ġhospital Location Code , ĊĠĠĠĠĠĠĠĠĠ Ġ" support ing Pr ison Id " Ġto Ġsupporting Pr ison Id ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ