package Ġuk . n hs . n hs x . is olation payment Ċ Ċ import Ġcom . amazonaws . services . dynamodb v 2 . model . Conditional Check FailedException Ċ import Ġio . mock k . Runs Ċ import Ġio . mock k . every Ċ import Ġio . mock k . just Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . slot Ċ import Ġio . mock k . verify Ċ import Ġio . mock k . verify Sequence Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġuk . n hs . n hs x . core . events . Recording Events Ċ import Ġuk . n hs . n hs x . is olation payment . model . Is ol ationToken Ċ import Ġuk . n hs . n hs x . is olation payment . model . Token Generation Request Ċ import Ġuk . n hs . n hs x . is olation payment . model . Token State Internal Ċ import Ġuk . n hs . n hs x . is olation payment . model . Token Update Request Ċ import Ġuk . n hs . n hs x . test helper . data . as Instant Ċ import Ġuk . n hs . n hs x . vi ro logy . Country Ċ import Ġuk . n hs . n hs x . vi ro logy . Country . Companion . Engl and Ċ import Ġuk . n hs . n hs x . vi ro logy . I pc Token Id Ċ import Ġjava . time . Instant Ċ import Ġjava . time . Period Ċ import Ġjava . util .* Ċ import Ġjava . util . function . Supplier Ċ Ċ class ĠI sol ation Payment Mobile Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġnow Ġ= ĠInstant . of Epoch Second ( 0 ) ĊĠĠĠ Ġprivate Ġval Ġclock Ġ= ĠSupplier Ġ{ Ġnow Ġ} ĊĠĠĠ Ġprivate Ġval Ġtoken Generator Ġ= ĠSupplier Ġ{ ĠI pc Token Id . of (" 1 ". repeat ( 6 4 )) Ġ} ĊĠĠĠ Ġprivate Ġval Ġpersistence Ġ= Ġmock k < Isolation Payment Persistence >() ĊĠĠĠ Ġprivate Ġval Ġwebsite Order Url Ġ= Ġ" https :// test / path ? ipc Token =" ĊĠĠĠ Ġprivate Ġval Ġtoken Expiry In Week s Ġ= Ġ 4 ĊĠĠĠ Ġprivate Ġval Ġcountries Wh itelisted Ġ= ĠlistOf (" Engl and ", Ġ" W ales ") ĊĠĠĠ Ġprivate Ġval Ġevents Ġ= ĠRecord ing Events () ĊĊĠĠĠ Ġprivate Ġval Ġservice Ġ= ĠI sol ation Payment Mobile Service ( ĊĠĠĠĠĠĠĠ Ġclock , ĊĠĠĠĠĠĠĠ Ġtoken Generator , ĊĠĠĠĠĠĠĠ Ġpersistence , ĊĠĠĠĠĠĠĠ Ġwebsite Order Url , ĊĠĠĠĠĠĠĠ Ġtoken Expiry In Week s , ĊĠĠĠĠĠĠĠ Ġcountries Wh itelisted , ĊĠĠĠĠĠĠĠ Ġ" audit _ log ", ĊĠĠĠĠĠĠĠ Ġevents ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` orders Ġisolation Ġpayment `() Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . insert Is ol ationToken ( any ()) Ġ} Ġjust ĠRuns ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . handle Isolation Payment Order ( Token Generation Request ( Engl and )) ĊĠĠĠĠĠĠĠ ĠassertThat ( response . ipc Token ). isEqualTo ( I pc Token Id . of (" 1 ". repeat ( 6 4 ))) ĊĠĠĠĠĠĠĠ ĠassertThat ( response . isEnabled ). isEqualTo ( true ) ĊĊĠĠĠĠĠĠĠ Ġval Ġslot Ġ= Ġslot < Is ol ationToken >() ĊĠĠĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpersistence . insert Is ol ationToken ( capture ( slot )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . tokenId ). isEqualTo ( I pc Token Id . of (" 1 ". repeat ( 6 4 ))) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . token Status ). isEqualTo ( Token State Internal . INT _ CREATED . value ) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . created Timestamp ). isEqualTo ( clock . get (). epoch Second ) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . expire At ). isEqualTo ( clock . get (). plus ( Period . of Week s ( token Expiry In Week s )). epoch Second ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` orders Ġisolation Ġpayment Ġand Ġthrows Ġwhen Ġtoken Ġis Ġnot Ġsaved `() Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . insert Is ol ationToken ( any ()) Ġ} Ġthrows ĠRuntimeException () ĊĊĠĠĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġservice . handle Isolation Payment Order ( Token Generation Request ( Engl and )) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isInstanceOf ( RuntimeException :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` orders Ġisolation Ġpayment Ġand Ġreturns Ġempty Ġtoken Ġwhen Ġcountry Ġis Ġnot Ġwh itelisted `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . handle Isolation Payment Order ( Token Generation Request ( Country . of (" Ger many "))) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( response . ipc Token ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( response . isEnabled ). isEqualTo ( false ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` updates Ġtoken Ġsuccessfully Ġfor Ġexisting Ġtoken `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtoken Ġ= ĠI sol ationToken ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠI pc Token Id . of (" 1 ". repeat ( 6 4 )), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠToken State Internal . INT _ CREATED . value , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 5 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 2 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 3 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 4 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . getIs ol ationToken ( any ()) Ġ} Ġreturns ĠOptional . of ( token ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . update Is ol ationToken ( any (), Ġany ()) Ġ} Ġjust ĠRuns ĊĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠToken Update Request ( I pc Token Id . of (" 1 ". repeat ( 6 4 )), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 Z ". as Instant (), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 1 Z ". as Instant ()) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . handle Isolation Payment Update ( request ) ĊĠĠĠĠĠĠĠ ĠassertThat ( response . website Url With Query ). isEqualTo (" https :// test / path ? ipc Token =${ " 1 ". repeat ( 6 4 )} ") ĊĊĠĠĠĠĠĠĠ Ġval Ġslot Ġ= Ġslot < Is ol ationToken >() ĊĠĠĠĠĠĠĠ Ġverify Sequence Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpersistence . getIs ol ationToken ( I pc Token Id . of (" 1 ". repeat ( 6 4 ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpersistence . update Is ol ationToken ( capture ( slot ), ĠToken State Internal . INT _ CREATED ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . tokenId ). isEqualTo ( I pc Token Id . of (" 1 ". repeat ( 6 4 ))) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . token Status ). isEqualTo ( Token State Internal . INT _ UPDATED . value ) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . created Timestamp ). isEqualTo ( 1 0 0 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . updated Timestamp ). isEqualTo ( clock . get (). epoch Second ) ĊĠĠĠĠĠĠĠ ĠassertThat ( slot . captured . expire At ). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` does Ġnot Ġupdate Ġtokens Ġthat Ġare Ġin Ġvalid Ġstate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtoken Ġ= ĠI sol ationToken ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠI pc Token Id . of (" 1 ". repeat ( 6 4 )), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠToken State Internal . INT _ UPDATED . value , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 5 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 2 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 3 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 4 0 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . getIs ol ationToken ( any ()) Ġ} Ġreturns ĠOptional . of ( token ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠToken Update Request ( I pc Token Id . of (" 1 ". repeat ( 6 4 )), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 Z ". as Instant (), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 1 Z ". as Instant ()) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . handle Isolation Payment Update ( request ) ĊĠĠĠĠĠĠĠ ĠassertThat ( response . website Url With Query ). isEqualTo (" https :// test / path ? ipc Token =${ " 1 ". repeat ( 6 4 )} ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` update Ġtoken Ġdoes Ġnot Ġthrow Ġexception Ġon Ġconditional Ġcheck Ġfailure `() Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpersistence . update Is ol ationToken ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠToken State Internal . INT _ CREATED ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} Ġthrows ĠConditional Check FailedException ("") ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpersistence . getIs ol ationToken ( any ()) Ġ} Ġreturns ĠOptional . of ( Is ol ationToken ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠToken Update Request ( I pc Token Id . of (" 1 ". repeat ( 6 4 )), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 Z ". as Instant (), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 1 Z ". as Instant ()) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . handle Isolation Payment Update ( request ) ĊĠĠĠĠĠĠĠ ĠassertThat ( response . website Url With Query ). isEqualTo (" https :// test / path ? ipc Token =${ " 1 ". repeat ( 6 4 )} ") ĊĠĠĠ Ġ} Ċ } Ċ