package Ġnet . cord a . node . services Ċ Ċ import Ġnet . cord a . core . concurrent . C ord a Future Ċ import Ġnet . cord a . core . contracts . Transaction Verification Exception Ċ import Ġnet . cord a . core . crypto . Secure Hash Ċ import Ġnet . cord a . core . flows . Final ity Flow Ċ import Ġnet . cord a . core . flows . StateMachine Run Id Ċ import Ġnet . cord a . core . internal . cord app . C ord app Resolver Ċ import Ġnet . cord a . core . to Future Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . get OrThrow Ċ import Ġnet . cord a . finance . PO UN DS Ċ import Ġnet . cord a . finance . contracts . asset . Cash Ċ import Ġnet . cord a . finance . iss ued By Ċ import Ġnet . cord a . node . services . state machine . Staff ed Flow Ho spital .* Ċ import Ġnet . cord a . testing . core . AL ICE _ NAME Ċ import Ġnet . cord a . testing . core . BO B _ NAME Ċ import Ġnet . cord a . testing . core . single Identity Ċ import Ġnet . cord a . testing . node . internal .* Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Test Ċ import Ġrx . Observable Ċ Ċ class ĠFinal ity Handler Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġmock Net Ġ= ĠInternal Mock Network () ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Net . stop Nodes () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` sent Ġto Ġflow Ġhospital Ġon Ġerror Ġand Ġattempted Ġretry Ġon Ġnode Ġrestart `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠSetup Ġa Ġnetwork Ġwhere Ġonly ĠAlice Ġhas Ġthe Ġfin ance ĠCor D app Ġand Ġit Ġsends Ġa Ġcash Ġtx Ġto ĠBob Ġwho Ġdoesn 't Ġhave Ġthe ĊĠĠĠĠĠĠĠ Ġ// ĠCor D app . ĠBob 's ĠFinal ity Handler Ġwill Ġerror Ġwhen Ġvalidating Ġthe Ġtx . ĊĠĠĠĠĠĠĠ Ġval Ġalice Ġ= Ġmock Net . createNode ( Internal Mock Node Parameters ( legal Name Ġ= ĠA LIC E _ NAME , Ġadditional C ord apps Ġ= ĠFIN ANCE _ C ORD APPS )) ĊĊĠĠĠĠĠĠĠ Ġvar Ġbob Ġ= Ġmock Net . createNode ( Internal Mock Node Parameters ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlegal Name Ġ= ĠB OB _ NAME , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠThe Ġnode Ġdisables Ġthe ĠFinal ity Handler Ġcompletely Ġif Ġthere Ġare Ġno Ġold ĠCor D apps Ġloaded , Ġso Ġwe Ġneed Ġto Ġadd ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġa Ġtoken Ġold ĠCor D app Ġto Ġkeep Ġthe Ġhandler Ġrunning . ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadditional C ord apps Ġ= Ġset Of ( D UMMY _ CONTRACT S _ C ORD APP . copy ( target Platform Version Ġ= Ġ 3 )) ĊĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġalice . issue Cash To ( bob ) ĊĠĠĠĠĠĠĠ Ġval Ġfinal ity Handler Id Ġ= Ġbob . track Final ity Handler Id (). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġalice . final ise With Old Api ( st x ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget OrThrow () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġbob . assert Flow Sent For Observation Due To Constraint Error ( final ity Handler Id ) ĊĠĠĠĠĠĠĠ ĠassertThat ( bob . getTransaction ( st x . id )). isNull () ĊĊĠĠĠĠĠĠĠ Ġbob Ġ= Ġmock Net . restart Node ( bob ) ĊĠĠĠĠĠĠĠ Ġ// ĠSince Ġwe 've Ġnot Ġdone Ġanything Ġto Ġfix Ġthe Ġor ign al Ġerror , Ġwe Ġexpect Ġthe Ġfinal ity Ġhandler Ġto Ġbe Ġsent Ġto Ġthe Ġhospital ĊĠĠĠĠĠĠĠ Ġ// Ġagain Ġon Ġrestart ĊĠĠĠĠĠĠĠ Ġbob . assert Flow Sent For Observation Due To Constraint Error ( final ity Handler Id ) ĊĠĠĠĠĠĠĠ ĠassertThat ( bob . getTransaction ( st x . id )). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` disabled Ġif Ġthere Ġare Ġno Ġold ĠCor D apps Ġloaded `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġalice Ġ= Ġmock Net . createNode ( Internal Mock Node Parameters ( legal Name Ġ= ĠA LIC E _ NAME , Ġadditional C ord apps Ġ= ĠFIN ANCE _ C ORD APPS )) ĊĊĠĠĠĠĠĠĠ Ġval Ġbob Ġ= Ġmock Net . createNode ( Internal Mock Node Parameters ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlegal Name Ġ= ĠB OB _ NAME , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠMake Ġsure Ġthe Ġtarget Ġversion Ġis Ġ 4 , Ġand Ġnot Ġthe Ġcurrent Ġplatform Ġversion Ġwhich Ġmay Ġbe Ġgreater ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadditional C ord apps Ġ= Ġset Of ( cord app With Packages (" net . cord a . finance "). copy ( target Platform Version Ġ= Ġ 4 )) ĊĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġalice . issue Cash To ( bob ) ĊĠĠĠĠĠĠĠ Ġval Ġfinal ity Future Ġ= Ġalice . final ise With Old Api ( st x ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrecord Ġ= Ġbob . medical Records OfType < Medical Record . Session Init >() ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Blocking () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. first () ĊĠĠĠĠĠĠĠ ĠassertThat ( record . outcome ). isEqualTo ( Outcome . OVER N IGHT _ OB SERV ATION ) ĊĠĠĠĠĠĠĠ ĠassertThat ( record . sender ). isEqualTo ( alice . info . single Identity ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( record . init iator Flow ClassName ). isEqualTo ( Final ity Flow :: class . java . name ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( bob . getTransaction ( st x . id )). isNull () ĊĊĠĠĠĠĠĠĠ Ġ// ĠDrop Ġthe Ġsession - init Ġso Ġthat ĠAlice Ġgets Ġthe Ġerror Ġmessage ĊĠĠĠĠĠĠĠ ĠassertThat ( final ity Future ). isNot Done () ĊĠĠĠĠĠĠĠ Ġbob . sm m . flow Ho spital . drop Session Init ( record . id ) ĊĠĠĠĠĠĠĠ Ġmock Net . run Network () ĊĠĠĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfinal ity Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ}. has Message Containing (" Counter party Ġattempting Ġto Ġuse Ġthe Ġold Ġin secure ĠAPI Ġof ĠFinal ity Flow ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠTest Started Node . issue Cash To ( recipient : ĠTest Started Node ): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠTransaction Builder ( mock Net . default Not ary Identity ). let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCash (). generate Issue ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 0 0 . PO UN DS . iss ued By ( info . single Identity (). ref ( 0 )), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrecipient . info . single Identity (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmock Net . default Not ary Identity ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservices . sign Initial Transaction ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠTest Started Node . track Final ity Handler Id (): ĠC ord a Future < StateMachine Run Id > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġs mm ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. track () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. updates ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . logic Ġis ĠFinal ity Handler Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . logic . run Id Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Future () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠTest Started Node . final ise With Old Api ( st x : ĠSigned Transaction ): ĠC ord a Future < Signed Transaction > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠC ord app Resolver . with C ord app ( target Platform Version Ġ= Ġ 3 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservices . start Flow ( Final ity Flow ( st x )). result Future . apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmock Net . run Network () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġinline Ġfun Ġ< re ified ĠR Ġ: ĠMedical Record > ĠTest Started Node . medical Records OfType (): ĠObservable < R > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġs mm ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. flow Ho spital ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. track () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. let Ġ{ Ġit . updates . start With ( it . snapshot ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. of Type ( R :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠTest Started Node . assert Flow Sent For Observation Due To Constraint Error ( run Id : ĠState Machine Run Id ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġobservation Ġ= Ġmedical Records OfType < Medical Record . Flow >() ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . flow Id Ġ== Ġrun Id Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Blocking () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. first () ĊĠĠĠĠĠĠĠ ĠassertThat ( observation . outcome ). isEqualTo ( Outcome . OVER N IGHT _ OB SERV ATION ) ĊĠĠĠĠĠĠĠ ĠassertThat ( observation . by ). contains ( Final ity Doctor ) ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= Ġobservation . errors . single () ĊĠĠĠĠĠĠĠ ĠassertThat ( error ). isInstanceOf ( Transaction Verification Exception . Contract Constraint Rejection :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠTest Started Node . getTransaction ( id : ĠSecure Hash ): ĠSigned Transaction ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġservices . validated Transactions . getTransaction ( id ) ĊĠĠĠ Ġ} Ċ } Ċ