package Ġuk . gov . just ice . digital . h mp ps . dp ss mo ket est . service Ċ Ċ import Ġorg . springframework . beans . factory . annotation . Qualifier Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . stereotype . Service Ċ import Ġorg . springframework . web . reactive . function . Body Inser ters Ċ import Ġorg . springframework . web . reactive . function . client . Web Client Ċ import Ġorg . springframework . web . reactive . function . client . Web ClientResponse Exception Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ import Ġuk . gov . just ice . digital . h mp ps . dp ss mo ket est . resource . S moke Test Resource . Test Status Ċ import Ġuk . gov . just ice . digital . h mp ps . dp ss mo ket est . resource . S moke Test Resource . Test Status . Test Progress . COMPLETE Ċ import Ġuk . gov . just ice . digital . h mp ps . dp ss mo ket est . resource . S moke Test Resource . Test Status . Test Progress . FAIL Ċ import Ġuk . gov . just ice . digital . h mp ps . dp ss mo ket est . resource . S moke Test Resource . Test Status . Test Progress . SUCCESS Ċ import Ġjava . time . Duration Ċ Ċ @ Service Ċ class ĠCommunity Service ( ĊĠ Ġ@ Value ("\ ${ test . maxLength Seconds }") Ġprivate Ġval Ġtest MaxLength Seconds : ĠLong , ĊĠ Ġ@ Value ("\ ${ test . result Poll Ms }") Ġprivate Ġval Ġtest Result Poll Ms : ĠLong , ĊĠ Ġ@ Qualifier (" community Api Web Client ") Ġprivate Ġval Ġweb Client : ĠWeb Client Ċ ) Ġ{ ĊĊĠ Ġfun Ġreset Cust ody TestData ( cr n : ĠString ): ĠMono < Test Status > Ġ{ ĊĊĠĠĠ Ġfun Ġfail On NotFound (): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Reset ĠCommunity Ġtest Ġfailed . ĠThe Ġoff ender Ġ$ cr n Ġcan Ġnot Ġbe Ġfound ", ĠFAIL )) ĊĊĠĠĠ Ġfun Ġfail OnError ( exception : ĠThrowable ): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Reset ĠCommunity Ġtest Ġdata Ġfor Ġ$ cr n Ġfailed Ġdue Ġto Ġ${ exception . message }", ĠFAIL )) ĊĊĠĠĠ Ġreturn Ġweb Client . post () ĊĠĠĠĠĠ Ġ. uri ("/ secure / smo ket est / off enders / cr n /{ cr n }/ cust ody / reset ", Ġcr n ) ĊĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠ Ġ. retrieve () ĊĠĠĠĠĠ Ġ. to B od ile ss Entity () ĊĠĠĠĠĠ Ġ. map Ġ{ ĠTest Status (" Reset ĠCommunity Ġtest Ġdata Ġfor Ġ$ cr n ") Ġ} ĊĠĠĠĠĠ Ġ. onError Resume ( Web ClientResponse Exception . NotFound :: class . java ) Ġ{ Ġfail On NotFound () Ġ} ĊĠĠĠĠĠ Ġ. onError Resume (:: fail OnError ) ĊĠ Ġ} ĊĊĠ Ġfun Ġset Off ender Details TestData ( cr n : ĠString , ĠfirstName : ĠString , Ġs urname : ĠString ): ĠMono < Test Status > Ġ{ ĊĊĠĠĠ Ġfun Ġfail On NotFound (): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Update Ġoff ender Ġdetails Ġtest Ġfailed . ĠThe Ġoff ender Ġ$ cr n Ġcan Ġnot Ġbe Ġfound ", ĠFAIL )) ĊĊĠĠĠ Ġfun Ġfail OnError ( exception : ĠThrowable ): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Update Ġoff ender Ġdetails Ġtest Ġfailed Ġfor Ġ$ cr n Ġfailed Ġdue Ġto Ġ${ exception . message }", ĠFAIL )) ĊĊĠĠĠ Ġreturn Ġweb Client . post () ĊĠĠĠĠĠ Ġ. uri ("/ secure / smo ket est / off enders / cr n /{ cr n }/ details ", Ġcr n ) ĊĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠ Ġ. body ( ĊĠĠĠĠĠĠĠ ĠBody Inser ters . from Value ( ĊĠĠĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" firstName ": Ġ"$ firstName ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" surname ": Ġ"$ surname " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ""" . trim Indent () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ. retrieve () ĊĠĠĠĠĠ Ġ. to B od ile ss Entity () ĊĠĠĠĠĠ Ġ. map Ġ{ ĠTest Status (" Off ender Ġdetails Ġset Ġfor Ġ$ cr n ") Ġ} ĊĠĠĠĠĠ Ġ. onError Resume ( Web ClientResponse Exception . NotFound :: class . java ) Ġ{ Ġfail On NotFound () Ġ} ĊĠĠĠĠĠ Ġ. onError Resume (:: fail OnError ) ĊĠ Ġ} ĊĊĠ Ġfun ĠwaitFor Test To Complete ( nom s Number : ĠString , Ġbooking Number : ĠString ): ĠFlux < Test Status > Ġ= ĊĠĠĠ ĠFlux . interval ( Duration . of Millis ( test Result Poll Ms )) ĊĠĠĠĠĠ Ġ. take ( Duration . of Seconds ( test MaxLength Seconds )) ĊĠĠĠĠĠ Ġ. flatMap Ġ{ Ġcheck Cust ody Test Complete ( nom s Number , Ġbooking Number ) Ġ} ĊĠĠĠĠĠ Ġ. take Until ( Test Status :: test Complete ) ĊĊĠ Ġfun Ġcheck Cust ody Test Complete ( nom s Number : ĠString , Ġbook Number : ĠString ): ĠMono < Test Status > Ġ{ ĊĊĠĠĠ Ġfun Ġtest Incomplete On NotFound (): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Still Ġwaiting Ġfor Ġoff ender Ġ$ nom s Number Ġwith Ġbooking Ġ$ book Number Ġto Ġbe Ġupdated ")) ĊĊĠĠĠ Ġfun Ġfail OnError ( exception : ĠThrowable ): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Check Ġtest Ġresults Ġfor Ġ$ nom s Number Ġfailed Ġdue Ġto Ġ${ exception . message }", ĠFAIL )) ĊĊĠĠĠ Ġreturn Ġweb Client . get () ĊĠĠĠĠĠ Ġ. uri ("/ secure / off enders / nom s Number /{ nom s Number }/ cust ody / booking Number /{ booking Number }", Ġnom s Number , Ġbook Number ) ĊĠĠĠĠĠ Ġ. retrieve () ĊĠĠĠĠĠ Ġ. to B od ile ss Entity () ĊĠĠĠĠĠ Ġ. map Ġ{ ĠTest Status (" Test Ġfor Ġoff ender Ġ$ nom s Number Ġwith Ġbooking Ġ$ book Number Ġhas Ġcompleted ", ĠCOMP LETE ) Ġ} ĊĠĠĠĠĠ Ġ. onError Resume ( Web ClientResponse Exception . NotFound :: class . java ) Ġ{ Ġtest Incomplete On NotFound () Ġ} ĊĠĠĠĠĠ Ġ. onError Resume (:: fail OnError ) ĊĠ Ġ} ĊĊĠ Ġfun Ġcheck Off ender Exists ( cr n : ĠString ): ĠMono < Test Status > Ġ{ ĊĊĠĠĠ Ġfun Ġfail OnError ( exception : ĠThrowable ): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Off ender Ġwe Ġexpected Ġto Ġexist Ġ$ cr n Ġfailed Ġdue Ġto Ġ Ġ${ exception . message }", ĠFAIL )) ĊĊĠĠĠ Ġfun Ġfail On NotFound (): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Off ender Ġwe Ġexpected Ġto Ġexist Ġ$ cr n Ġwas Ġnot Ġfound . ĠCheck Ġthe Ġoff ender Ġhas Ġnot Ġbe Ġdeleted Ġin ĠDel ius ", ĠFAIL )) ĊĊĠĠĠ Ġreturn Ġweb Client . get () ĊĠĠĠĠĠ Ġ. uri ("/ secure / off enders / cr n /{ cr n }", Ġcr n ) ĊĠĠĠĠĠ Ġ. retrieve () ĊĠĠĠĠĠ Ġ. body To Mono ( Off ender Details :: class . java ) ĊĠĠĠĠĠ Ġ. map Ġ{ ĠTest Status (" Off ender Ġ$ cr n Ġexists Ġand Ġis Ġgood Ġto Ġgo . ĠCurrent Ġname Ġis Ġ${ it . firstName } Ġ${ it . surname }") Ġ} ĊĠĠĠĠĠ Ġ. onError Resume ( Web ClientResponse Exception . NotFound :: class . java ) Ġ{ Ġfail On NotFound () Ġ} ĊĠĠĠĠĠ Ġ. onError Resume (:: fail OnError ) ĊĠ Ġ} ĊĊĠ Ġfun Ġassert TestResult ( nom s Number : ĠString , Ġbooking Number : ĠString , Ġpr ison Code : ĠString ): ĠMono < Test Status > Ġ{ ĊĊĠĠĠ Ġfun Ġfail OnError ( exception : ĠThrowable ): ĠMono < out ĠTest Status > Ġ= ĊĠĠĠĠĠ ĠMono . just ( Test Status (" Check Ġtest Ġresults Ġfor Ġ$ nom s Number Ġfailed Ġdue Ġto Ġ${ exception . message }", ĠFAIL )) ĊĊĠĠĠ Ġreturn ĠgetC ust ody Details ( nom s Number , Ġbooking Number ). map Ġ{ ĊĠĠĠĠĠ Ġit . take If Ġ{ Ġit . matches ( pr ison Code ) Ġ} ĊĠĠĠĠĠĠĠ Ġ? . let Ġ{ ĠTest Status (" Test Ġfor Ġoff ender Ġ$ nom s Number Ġwith Ġbooking Ġ$ booking Number Ġfinished Ġsuccessfully ", ĠSUCCESS ) Ġ} ĊĠĠĠĠĠĠĠ Ġ?: ĠTest Status ( ĊĠĠĠĠĠĠĠĠĠ Ġ" Test Ġfor Ġoff ender Ġ$ nom s Number Ġwith Ġbooking Ġ$ booking Number Ġfailed Ġwith Ġcust ody Details =$ this ", ĊĠĠĠĠĠĠĠĠĠ ĠFAIL ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. onError Resume (:: fail OnError ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġdata Ġclass ĠC ust ody Details ( val Ġbooking Number : ĠString , Ġval Ġinstitution : ĠInst itution , Ġval Ġstatus : ĠStatus ) ĊĠ Ġprivate Ġdata Ġclass ĠInst itution ( val Ġnom s Pr ison Inst itution Code : ĠString ) ĊĠ Ġprivate Ġdata Ġclass ĠStatus ( val Ġcode : ĠString ) ĊĠ Ġprivate Ġdata Ġclass ĠOff ender Details ( val ĠfirstName : ĠString , Ġval Ġs urname : ĠString ) ĊĊĠ Ġprivate Ġfun ĠgetC ust ody Details ( nom s Number : ĠString , Ġbook Number : ĠString ): ĠMono < Cust ody Details > Ġ= ĊĠĠĠ Ġweb Client . get () ĊĠĠĠĠĠ Ġ. uri ("/ secure / off enders / nom s Number /{ nom s Number }/ cust ody / booking Number /{ booking Number }", Ġnom s Number , Ġbook Number ) ĊĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠ Ġ. retrieve () ĊĠĠĠĠĠ Ġ. body To Mono ( Cust ody Details :: class . java ) ĊĊĠ Ġprivate Ġfun ĠC ust ody Details . matches ( pr ison Code : ĠString ) Ġ= ĊĠĠĠ Ġthis . institution . nom s Pr ison Inst itution Code Ġ== Ġpr ison Code Ġ&& ĊĠĠĠĠĠ Ġthis . status . code Ġ== Ġ" D " Ċ } Ċ