package Ġnet . cord a . bn . flows Ċ Ċ import Ġnet . cord a . bn . contracts . Membership Contract Ċ import Ġnet . cord a . bn . states . Membership State Ċ import Ġnet . cord a . bn . states . Membership Status Ċ import Ġnet . cord a . core . flows . Flow Exception Ċ import Ġorg . junit . Test Ċ import Ġjava . lang . IllegalStateException Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assert Fails With Ċ import Ġkotlin . test . assertTrue Ċ Ċ class ĠOn board Membership Flow Test Ġ: ĠMembers hip Management Flow Test ( numberOf Author ised Members Ġ= Ġ 1 , ĠnumberOf Regular Members Ġ= Ġ 2 ) Ġ{ ĊĊĠĠĠ Ġ@ Test ( timeout Ġ= Ġ 3 0 0 _ 0 0 0 ) ĊĠĠĠ Ġfun Ġ` on board Ġmembership Ġflow Ġshould Ġfail Ġif Ġinit iator Ġis Ġnot Ġpart Ġof Ġthe Ġbusiness Ġnetwork , Ġits Ġmembership Ġis Ġnot Ġactive Ġor Ġis Ġnot Ġauthor ised `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor ised Member Ġ= Ġauthor ised Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġregular Member Ġ= Ġregular Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġnon Member Ġ= Ġregular Members [ 1 ] ĊĊĠĠĠĠĠĠĠ Ġval Ġnetwork Id Ġ= Ġ( run Create Business Network Flow ( author ised Member ). tx . output States . single () Ġas ĠMembers hip State ). network Id ĊĠĠĠĠĠĠĠ Ġassert Fails With < Business Network NotFoundException > Ġ{ Ġrun On board Membership Flow ( non Member , Ġnetwork Id , Ġregular Member . identity ()) Ġ} ĊĊĠĠĠĠĠĠĠ Ġrun Request And Suspend Membership Flow ( non Member , Ġauthor ised Member , Ġnetwork Id ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmembership Ġ= Ġtx . output States . single () Ġas ĠMembers hip State ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġassert Fails With < Illegal Membership Status Exception > Ġ{ Ġrun On board Membership Flow ( non Member , Ġnetwork Id , Ġregular Member . identity ()) Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġrun Activate Membership Flow ( author ised Member , Ġmembership . linear Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġassert Fails With < Membership Author isation Exception > Ġ{ Ġrun On board Membership Flow ( non Member , Ġnetwork Id , Ġregular Member . identity ()) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout Ġ= Ġ 3 0 0 _ 0 0 0 ) ĊĠĠĠ Ġfun Ġ` on board Ġmembership Ġflow Ġshould Ġfail Ġif Ġon bo arded Ġparty Ġis Ġalready Ġmember Ġof Ġgiven Ġbusiness Ġnetwork `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor ised Member Ġ= Ġauthor ised Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġregular Member Ġ= Ġregular Members . first () ĊĊĠĠĠĠĠĠĠ Ġval Ġnetwork Id Ġ= Ġ( run Create Business Network Flow ( author ised Member ). tx . output States . single () Ġas ĠMembers hip State ). network Id ĊĠĠĠĠĠĠĠ Ġrun On board Membership Flow ( author ised Member , Ġnetwork Id , Ġregular Member . identity ()) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < Flow Exception >(" is Ġalready Ġmember Ġof ĠBusiness ĠNetwork Ġwith Ġ$ network Id ĠID ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrun On board Membership Flow ( author ised Member , Ġnetwork Id , Ġregular Member . identity ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout Ġ= Ġ 3 0 0 _ 0 0 0 ) ĊĠĠĠ Ġfun Ġ` on board Ġmembership Ġflow Ġshould Ġfail Ġif Ġanother Ġon boarding Ġrequest Ġwith Ġsame Ġdata Ġis Ġin Ġprogress `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor ised Member Ġ= Ġauthor ised Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġregular Member Ġ= Ġregular Members . first () ĊĊĠĠĠĠĠĠĠ Ġval Ġbn Service Ġ= Ġauthor ised Member . services . cord a Service ( BN Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġbn Service . lock Storage . create Lock ( BN RequestType . PENDING _ MEMBER SHIP , Ġregular Member . identity (). toString ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġnetwork Id Ġ= Ġ( run Create Business Network Flow ( author ised Member ). tx . output States . single () Ġas ĠMembers hip State ). network Id ĊĠĠĠĠĠĠĠ Ġassert Fails With < Duplicate Business Network RequestException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrun On board Membership Flow ( author ised Member , Ġnetwork Id , Ġregular Member . identity ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġbn Service . lock Storage . delete Lock ( BN RequestType . PENDING _ MEMBER SHIP , Ġregular Member . identity (). toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout Ġ= Ġ 3 0 0 _ 0 0 0 ) ĊĠĠĠ Ġfun Ġ` on board Ġmembership Ġflow Ġshould Ġfail Ġif Ġinvalid Ġnot ary Ġargument Ġis Ġprovided `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor ised Member Ġ= Ġauthor ised Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġregular Member Ġ= Ġregular Members . first () ĊĊĠĠĠĠĠĠĠ Ġval Ġnetwork Id Ġ= Ġ( run Create Business Network Flow ( author ised Member ). tx . output States . single () Ġas ĠMembers hip State ). network Id ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrun On board Membership Flow ( author ised Member , Ġnetwork Id , Ġregular Member . identity (), Ġnot ary Ġ= Ġauthor ised Member . identity ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout Ġ= Ġ 3 0 0 _ 0 0 0 ) ĊĠĠĠ Ġfun Ġ` on board Ġmembership Ġflow Ġhappy Ġpath `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor ised Member Ġ= Ġauthor ised Members . first () ĊĠĠĠĠĠĠĠ Ġval Ġregular Member Ġ= Ġregular Members . first () ĊĊĠĠĠĠĠĠĠ Ġval Ġnetwork Id Ġ= Ġ( run Create Business Network Flow ( author ised Member ). tx . output States . single () Ġas ĠMembers hip State ). network Id ĊĊĠĠĠĠĠĠĠ Ġval Ġ( membership , Ġcommand ) Ġ= Ġrun On board Membership Flow ( author ised Member , Ġnetwork Id , Ġregular Member . identity (), ĠDummy Identity (" dummy - identity ")). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( tx . inputs . isEmpty ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify Required Signatures () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtx . outputs . single () Ġto Ġtx . commands . single () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġmembership . apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Membership Contract . CONTRACT _ NAME , Ġmembership . contract ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( data Ġis ĠMembers hip State ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġdata Ġ= Ġdata Ġas ĠMembers hip State ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( regular Member . identity (), Ġdata . identity . cord a Identity ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Dummy Identity (" dummy - identity "), Ġdata . identity . business Identity ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( network Id , Ġdata . network Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Membership Status . ACTIVE , Ġdata . status ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertTrue ( command . value Ġis ĠMembers hip Contract . Commands . On board ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġalso Ġcheck Ġled gers ĊĠĠĠĠĠĠĠ ĠlistOf ( author ised Member , Ġregular Member ). forEach Ġ{ Ġmember Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠgetAll Membership s From Vault ( member , Ġnetwork Id ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġsize , Ġ" Vault Ġsize Ġassertion Ġfailed Ġfor Ġ${ member . identity () }") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( any Ġ{ Ġit . identity . cord a Identity Ġ== Ġauthor ised Member . identity () Ġ}, Ġ" Expected Ġto Ġhave Ġ${ author ised Member . identity ()} Ġin Ġ${ member . identity ()} Ġvault ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( any Ġ{ Ġit . identity . cord a Identity Ġ== Ġregular Member . identity () Ġ}, Ġ" Expected Ġto Ġhave Ġ${ regular Member . identity ()} Ġin Ġ${ member . identity ()} Ġvault ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }