package Ġgraph _ generator Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api .* Ċ import Ġorg . neo 4 j . graph db . Label Ċ import Ġorg . neo 4 j . graph db . Node Ċ import Ġorg . neo 4 j . graph db . Relationship Ċ import Ġtools . Graph Generator Ċ import Ġutilities . Embedded Server Helper Ċ import Ġutilities . Fake Generator Ċ import Ġutilities . Value F aker Ċ import Ġutilities . Yaml Parser Ċ import Ġjava . util .* Ċ Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ class ĠGraph Generator Tests Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġgraph Generator : ĠGraph Generator ĊĊĠĠĠ Ġprivate Ġval ĠfullName PropertyName Ġ= Ġ" full _ name " ĊĠĠĠ Ġprivate Ġval Ġidentifier PropertyName Ġ= Ġ" Identifier " ĊĊĠĠĠ Ġprivate Ġval Ġidentifies Relationship Ġ= Ġ" IDENT IFI ES " ĊĠĠĠ Ġprivate Ġval Ġfriend Of Relationship Ġ= Ġ" FR I END _ OF " ĊĊĠĠĠ Ġprivate Ġval Ġperson Label String Ġ= Ġ" Person " ĊĊĠĠĠ Ġprivate Ġval Ġhow Many Nodes To Create Ġ= Ġ 1 0 ĊĊĊĠĠĠ Ġ@ Before All ĊĠĠĠ Ġfun Ġbefore All () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġembedded Server Ġ= ĠEmbedded Server Helper . graph Db ĊĠĠĠĠĠĠĠ Ġgraph Generator Ġ= ĠGraph Generator ( embedded Server , ĠYaml Parser (), ĠValue F aker ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠEmbedded Server Helper . clear Graph () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Each ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ ĠEmbedded Server Helper . clear Graph () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate Nodes () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Labels ForEach Node Ġ= ĠlistOf (" M ario ", Ġ" Lu igi ") ĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġgraph Generator . generate Nodes ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠGraph Generator . labels From Strings ( expected Labels ForEach Node ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"{ '$ fullName PropertyName ':' ${ Fake Generator . FULL NAME } '} ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġhow Many Nodes To Create . to Long () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( nodes ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ Ġval Ġtransaction Ġ= Ġgraph Generator . database . begin Tx () ĊĠĠĠĠĠĠĠ Ġnodes . forEach Ġ{ Ġnode Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfor Ġ( expected Label Name Ġin Ġexpected Labels ForEach Node ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( node . has Label ( Label . label ( expected Label Name ))). isTrue () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( node . has Property ( fullName PropertyName )). isTrue () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtransaction . success () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate Z ipped Nodes () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpeople Ġ= Ġgraph Generator . generate Nodes ( Graph Generator . labels From Strings ( listOf ( person Label String )), Ġ"{ '$ fullName PropertyName ':' ${ Fake Generator . FULL NAME } '} ", Ġhow Many Nodes To Create . to Long ()) ĊĠĠĠĠĠĠĠ Ġval Ġidentifiers Ġ= Ġgraph Generator . generate Nodes ( Graph Generator . labels From Strings ( listOf ( identifier PropertyName )), Ġ"{ '$ identifier PropertyName ':' ${ Fake Generator . CRED IT _ CARD _ NUMBER } '} ", Ġhow Many Nodes To Create . to Long ()) ĊĠĠĠĠĠĠĠ Ġval Ġcreated Relationships Ġ= Ġgraph Generator . generate Relationships Zip per ( identifiers , Ġpeople , Ġidentifies Relationship , Ġ"{ ' strength ': Ġ'${ Fake Generator . RANDOM _ NUMBER } '} ") ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( people ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( identifiers ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ ĠassertThat < Relationship >( created Relationships ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ Ġval Ġtransaction Ġ= Ġgraph Generator . database . begin Tx () ĊĠĠĠĠĠĠĠ Ġcreated Relationships . forEach Ġ{ Ġrelationship Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfrom Node Ġ= Ġrelationship . start Node ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġto Node Ġ= Ġrelationship . end Node ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġindex In Identifiers Ġ= Ġidentifiers . indexOf ( from Node ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġindex In People Ġ= Ġpeople . indexOf ( to Node ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( index In Identifiers ). isEqualTo ( index In People ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtransaction . success () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate Relationships From All To All () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpeople Ġ= Ġgraph Generator . generate Nodes ( Graph Generator . labels From Strings ( listOf (" Person ")), Ġ"{ '$ fullName PropertyName ':' ${ Fake Generator . FULL NAME } '} ", Ġhow Many Nodes To Create . to Long ()) ĊĠĠĠĠĠĠĠ Ġval Ġidentifiers Ġ= Ġgraph Generator . generate Nodes ( Graph Generator . labels From Strings ( listOf ( identifier PropertyName )), Ġ"{ '$ identifier PropertyName ':' ${ Fake Generator . CRED IT _ CARD _ NUMBER } '} ", Ġhow Many Nodes To Create . to Long ()) ĊĠĠĠĠĠĠĠ Ġval Ġcreated Relationships Ġ= Ġgraph Generator . generate Relationships From All To All ( identifiers , Ġpeople , Ġidentifies Relationship , Ġ"{ ' strength ': Ġ'${ Fake Generator . RANDOM _ NUMBER } '} ") ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( people ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( identifiers ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ ĠassertThat < Relationship >( created Relationships ). has Size ( how Many Nodes To Create Ġ* Ġhow Many Nodes To Create ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate LinkedList () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpeople Ġ= Ġgraph Generator . generate Nodes ( Graph Generator . labels From Strings ( listOf (" Person ")), Ġ"{ '$ fullName PropertyName ':' ${ Fake Generator . FULL NAME } '} ", Ġhow Many Nodes To Create . to Long ()) ĊĠĠĠĠĠĠĠ Ġval Ġ( nodes , Ġrelationships ) Ġ= Ġgraph Generator . generate LinkedList ( people , Ġfriend Of Relationship ) ĊĠĠĠĠĠĠĠ ĠassertThat < Node >( nodes ). has Size ( how Many Nodes To Create ) ĊĠĠĠĠĠĠĠ ĠassertThat < Relationship >( relationships ). has Size ( how Many Nodes To Create Ġ- Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate Values () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhow Many Properties : ĠInt Ġ= Ġhow Many Nodes To Create ĊĠĠĠĠĠĠĠ Ġval Ġparameters For Generator Ġ= ĠArrayList < Any >() ĊĠĠĠĠĠĠĠ Ġparameters For Generator . add (" 1 ") ĊĠĠĠĠĠĠĠ Ġparameters For Generator . add (" 1 0 ") ĊĠĠĠĠĠĠĠ Ġval Ġnumber Between Ġ= Ġgraph Generator . generate Values ( Fake Generator . NUMBER _ B ETWEEN . name , Ġparameters For Generator , Ġhow Many Properties . to Long ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( number Between ). has Size ( how Many Properties ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( property Ġin Ġnumber Between ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġvalue Ġ= Ġproperty Ġas ĠInt ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( value ). is Between ( Integer . valueOf ( parameters For Generator [ 0 ] Ġas ĠString ), ĠInteger . valueOf ( parameters For Generator [ 1 ] Ġas ĠString )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Generate From Yaml File () Ġ{ ĊĠĠĠĠĠĠĠ Ġgraph Generator . generate From Yaml File (" graph _ samples / sample _ graph . yaml ") ĊĠĠĠ Ġ} Ċ } Ċ