package Ġnet . cord a . node . services . vault Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . do Return Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġnet . cord a . core . identity . Abstract Party Ċ import Ġnet . cord a . core . identity . Anonymous Party Ċ import Ġnet . cord a . core . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria Ċ import Ġnet . cord a . core . node . services . vault . builder Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . node . services . api . Identity Service Internal Ċ import Ġnet . cord a . node . services . keys . Persistent Key Management Service Ċ import Ġnet . cord a . node api . internal . persistence . C ord a Persistence Ċ import Ġnet . cord a . testing . common . internal . test Network Parameters Ċ import Ġnet . cord a . testing . contracts . Dummy Contract Ċ import Ġnet . cord a . testing . contracts . Dummy State Ċ import Ġnet . cord a . testing . core . Serialization Environment Rule Ċ import Ġnet . cord a . testing . core . Test Identity Ċ import Ġnet . cord a . testing . internal . rig or ous Mock Ċ import Ġnet . cord a . testing . node . Mock Services Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . util .* Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠExternal Id Mapping Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġtest Serialization Ġ= ĠSerialization Environment Rule () ĊĊĠĠĠ Ġprivate Ġval Ġc ord apps Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" net . cord a . node . services . persistence ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" net . cord a . testing . contracts " ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġval Ġmyself Ġ= ĠTest Identity ( C ord a X 5 0 0 Name (" Me ", Ġ" L ondon ", Ġ" GB ")) ĊĠĠĠ Ġprivate Ġval Ġnot ary Ġ= ĠTest Identity ( C ord a X 5 0 0 Name (" Not ary Service ", Ġ" L ondon ", Ġ" GB "), Ġ 1 3 3 7 L ) ĊĊĠĠĠ Ġlateinit Ġvar Ġservices : ĠMock Services ĊĠĠĠ Ġlateinit Ġvar Ġdatabase : ĠC ord a Persistence ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ( db , Ġmock Services ) Ġ= ĠMock Services . make Test Database And Mock Services ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġc ord app Packages Ġ= Ġc ord apps , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġidentity Service Ġ= Ġrig or ous Mock < Identity Service Internal >(). also Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdo Return ( not ary . party ). wh enever ( it ). party From Key ( not ary . publicKey ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdo Return ( not ary . party ). wh enever ( it ). well Known Party From Anonymous ( not ary . party ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdo Return ( not ary . party ). wh enever ( it ). well Known Party From X 5 0 0 Name ( not ary . name ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġinitial Identity Ġ= Ġmyself , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnetwork Parameters Ġ= Ġtest Network Parameters ( minimum Platform Version Ġ= Ġ 4 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġservices Ġ= Ġmock Services ĊĠĠĠĠĠĠĠ Ġdatabase Ġ= Ġdb ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfresh Key For External Id ( external Id : ĠUUID ): ĠAn onymous Party Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanonymous Party Ġ= Ġfresh Key () ĊĠĠĠĠĠĠĠ Ġdatabase . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservices . with EntityManager Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmapping Ġ= ĠPersistent Key Management Service . PublicKey Hash To External Id ( external Id , Ġanonymous Party . own ing Key ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpersist ( mapping ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġflush () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġanonymous Party ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfresh Key (): ĠAn onymous Party Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= Ġservices . key Management Service . fresh Key () ĊĠĠĠĠĠĠĠ Ġval Ġanonymous Party Ġ= ĠAn onymous Party ( key ) ĊĠĠĠĠĠĠĠ Ġ// ĠAdd Ġbehaviour Ġto Ġthe Ġmock Ġidentity Ġmanagement Ġservice Ġfor Ġdealing Ġwith Ġthe Ġnew Ġkey . ĊĠĠĠĠĠĠĠ Ġ// ĠIt Ġwon 't Ġbe Ġable Ġto Ġresolve Ġit Ġas Ġit 's Ġjust Ġan Ġanonymous Ġkey Ġthat Ġis Ġnot Ġlinked Ġto Ġan Ġidentity . ĊĠĠĠĠĠĠĠ Ġservices . identity Service . also Ġ{ Ġdo Return ( null ). wh enever ( it ). well Known Party From Anonymous ( anonymous Party ) Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġanonymous Party ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Dummy State ( participants : ĠList < Abstract Party >): ĠDummy State Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtx Ġ= ĠTransaction Builder ( not ary Ġ= Ġnot ary . party ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Output State ( Dummy State ( 1 , Ġparticipants ), ĠDummy Contract . PROGRAM _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Command ( Dummy Contract . Commands . Create (), Ġparticipants . map Ġ{ Ġit . own ing Key Ġ}) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġservices . sign Initial Transaction ( tx ) ĊĠĠĠĠĠĠĠ Ġdatabase . transaction Ġ{ Ġservices . record Transactions ( st x ) Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġst x . tx . outputs OfType < Dummy State >(). single () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Two Ġstates Ġcan Ġbe Ġmapped Ġto Ġa Ġsingle Ġexternal Id `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvault Service Ġ= Ġservices . vault Service ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġnew Ġexternal ĠID Ġand Ġtwo Ġkeys Ġmapped Ġto Ġit . ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= ĠUUID . randomUUID () ĊĠĠĠĠĠĠĠ Ġval Ġkey One Ġ= Ġfresh Key For External Id ( id ) ĊĠĠĠĠĠĠĠ Ġval Ġkey Two Ġ= Ġfresh Key For External Id ( id ) ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġstates Ġwith Ġa Ġpublic Ġkey Ġassigned Ġto Ġthe Ġnew Ġexternal ĠID . ĊĠĠĠĠĠĠĠ Ġval Ġdummy State One Ġ= Ġcreate Dummy State ( listOf ( key One )) ĊĠĠĠĠĠĠĠ Ġval Ġdummy State Two Ġ= Ġcreate Dummy State ( listOf ( key Two )) ĊĠĠĠĠĠĠĠ Ġ// ĠThis Ġquery Ġshould Ġreturn Ġtwo Ġstates ! ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdatabase . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexternal Id Ġ= Ġbuilder Ġ{ ĠVault Schema V 1 . State To External Id :: external Id .` in `( listOf ( id )) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġquery Criteria Ġ= ĠQuery Criteria . Vault Custom Query Criteria ( external Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvault Service . query By < Dummy State >( query Criteria ). states ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( set Of ( dummy State One , Ġdummy State Two ), Ġresult . map Ġ{ Ġit . state . data Ġ}. toSet ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThis Ġquery Ġshould Ġreturn Ġtwo Ġstates ! ĊĠĠĠĠĠĠĠ Ġval Ġresult Two Ġ= Ġdatabase . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexternal Id Ġ= Ġbuilder Ġ{ ĠVault Schema V 1 . State To External Id :: external Id . equal ( id ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġquery Criteria Ġ= ĠQuery Criteria . Vault Custom Query Criteria ( external Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvault Service . query By < Dummy State >( query Criteria ). states ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( set Of ( dummy State One , Ġdummy State Two ), Ġresult Two . map Ġ{ Ġit . state . data Ġ}. toSet ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` One Ġstate Ġcan Ġbe Ġmapped Ġto Ġmultiple Ġexternal Ids `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvault Service Ġ= Ġservices . vault Service ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġnew Ġexternal ĠID . ĊĠĠĠĠĠĠĠ Ġval Ġid One Ġ= ĠUUID . randomUUID () ĊĠĠĠĠĠĠĠ Ġval Ġkey One Ġ= Ġfresh Key For External Id ( id One ) ĊĠĠĠĠĠĠĠ Ġval Ġid Two Ġ= ĠUUID . randomUUID () ĊĠĠĠĠĠĠĠ Ġval Ġkey Two Ġ= Ġfresh Key For External Id ( id Two ) ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġstate Ġwith Ġa Ġpublic Ġkey Ġassigned Ġto Ġthe Ġnew Ġexternal ĠID . ĊĠĠĠĠĠĠĠ Ġval Ġdummy State Ġ= Ġcreate Dummy State ( listOf ( key One , Ġkey Two )) ĊĠĠĠĠĠĠĠ Ġ// ĠThis Ġquery Ġshould Ġreturn Ġone Ġstate ! ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdatabase . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexternal Id Ġ= Ġbuilder Ġ{ ĠVault Schema V 1 . State To External Id :: external Id .` in `( listOf ( id One , Ġid Two )) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġquery Criteria Ġ= ĠQuery Criteria . Vault Custom Query Criteria ( external Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvault Service . query By < Dummy State >( query Criteria ). states ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( dummy State , Ġresult . single (). state . data ) ĊĠĠĠ Ġ} Ċ Ċ }