/* Ċ Ġ* ĠCopyright Ġ 2 0 1 1 - 2 0 2 1 Ġthe Ġoriginal Ġauthor Ġor Ġauthors . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttps :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . springframework . data . neo 4 j . integration . imp er ative Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . neo 4 j . driver . Driver Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . data . neo 4 j . config . Abstract Neo 4 j Config Ċ import Ġorg . springframework . data . neo 4 j . core . Database Selection Provider Ċ import Ġorg . springframework . data . neo 4 j . core . Neo 4 j Template Ċ import Ġorg . springframework . data . neo 4 j . core . transaction . Neo 4 j Bookmark Manager Ċ import Ġorg . springframework . data . neo 4 j . core . transaction . Neo 4 j Transaction Manager Ċ import Ġorg . springframework . data . neo 4 j . integration . shared . common . Department Entity Ċ import Ġorg . springframework . data . neo 4 j . integration . shared . common . Person Department QueryResult Ċ import Ġorg . springframework . data . neo 4 j . integration . shared . common . Person Entity Ċ import Ġorg . springframework . data . neo 4 j . repository . Neo 4 j Repository Ċ import Ġorg . springframework . data . neo 4 j . repository . config . Enable Neo 4 j Repositories Ċ import Ġorg . springframework . data . neo 4 j . repository . query . Query Ċ import Ġorg . springframework . data . neo 4 j . test . Bookmark Capture Ċ import Ġorg . springframework . data . neo 4 j . test . Neo 4 j Extension . Neo 4 j Connection Support Ċ import Ġorg . springframework . data . neo 4 j . test . Neo 4 j IntegrationTest Ċ import Ġorg . springframework . transaction . Platform Transaction Manager Ċ import Ġorg . springframework . transaction . annotation . Enable Transaction Management Ċ Ċ /** Ċ Ġ* Ġ@ author ĠMichael ĠJ . ĠSim ons Ċ Ġ*/ Ċ @ Neo 4 j IntegrationTest Ċ internal Ġclass ĠKotlin Projection IT Ġ{ ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ @ Jvm Static Ċĉ ĉ private Ġlateinit Ġvar Ġne o 4 j Connection Support : ĠNeo 4 j Connection Support ĊĊĉ ĉ @ Before All Ċĉ ĉ @ Jvm Static Ċĉ ĉ fun Ġclear Database (@ Autowired Ġdriver : ĠDriver , Ġ@ Autowired Ġbookmark Capture : ĠBook mark Capture ) Ġ{ Ċĉĉ ĉ driver . session ( bookmark Capture . create Session Config ()). use Ġ{ Ġsession Ġ-> Ċĉĉĉ ĉ session . run (" MATCH Ġ( n ) ĠDET ACH ĠDELETE Ġn ") Ċĉĉĉ ĉ session . run (""" ĉĉĉĉĉ Ċĉĉĉĉ ĉ CREATE Ġ( p : Person Entity Ġ{ id : Ġ' p 1 ', Ġemail : Ġ' p 1 @ dep 1 . org '}) Ġ- [: MEMBER _ OF ]-> ( department : Department Entity Ġ{ id : Ġ' d 1 ', Ġname : Ġ' Dep 1 '}) Ċĉĉĉĉ ĉ RETURN Ġp ĉĉĉĉĉ Ċĉĉĉ ĉ """. trim Indent ()). consume (); Ċĉĉĉ ĉ bookmark Capture . seed With ( session . last Bookmark ()) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ġ// ĠGH - 2 3 4 9 Ċ ĉ fun Ġprojection s Containing Known Entities Should Work From Repository (@ Autowired Ġperson Repository : ĠPerson Repository ) Ġ{ ĊĊĉ ĉ val Ġresults Ġ= Ġperson Repository . find Person With Department () Ċĉ ĉ assertThat ( results ) Ċĉĉĉ ĉ . has Size ( 1 ) Ċĉĉĉ ĉ . first () Ċĉĉĉ ĉ . satisf ies Ġ{ Ġperson And Department Ġ-> Ġprojected Entities ( person And Department ) Ġ} Ċ ĉ } ĊĊ ĉ @ Test Ġ// ĠGH - 2 3 4 9 Ċ ĉ fun Ġprojection s Containing Known Entities Should Work From Template (@ Autowired Ġtemplate : ĠNeo 4 j Template ) Ġ{ ĊĊĉ ĉ val Ġresults Ġ= Ġtemplate . find ( Person Entity :: class . java ). ` as `( Person Department QueryResult :: class . java ) Ċĉĉĉ ĉ . matching (" MATCH Ġ( person : Person Entity )- [: MEMBER _ OF ]-> ( department : Department Entity ) ĠRETURN Ġperson , Ġdepartment ") Ċĉĉĉ ĉ . all () Ċĉ ĉ assertThat ( results ) Ċĉĉĉ ĉ . has Size ( 1 ) Ċĉĉĉ ĉ . first () Ċĉĉĉ ĉ . satisf ies Ġ{ Ġperson And Department Ġ-> Ġprojected Entities ( person And Department ) Ġ} Ċ ĉ } ĊĊ ĉ private Ġfun Ġprojected Entities ( person And Department : ĠPerson Department QueryResult ) Ġ{ Ċĉ ĉ assertThat ( person And Department . person ). extract ing Ġ{ Ġobj : ĠPerson Entity Ġ-> Ġobj . id Ġ}. isEqualTo (" p 1 ") Ċĉ ĉ assertThat ( person And Department . person ). extract ing Ġ{ Ġobj : ĠPerson Entity Ġ-> Ġobj . email Ġ}. isEqualTo (" p 1 @ dep 1 . org ") Ċĉ ĉ assertThat ( person And Department . department ). extract ing Ġ{ Ġobj : ĠDepartment Entity Ġ-> Ġobj . id Ġ}. isEqualTo (" d 1 ") Ċĉ ĉ assertThat ( person And Department . department ). extract ing Ġ{ Ġobj : ĠDepartment Entity Ġ-> Ġobj . name Ġ}. isEqualTo (" Dep 1 ") Ċ ĉ } ĊĊ ĉ internal Ġinterface ĠPerson Repository Ġ: ĠNeo 4 j Repository < Person Entity , ĠString > Ġ{ Ċĉ ĉ @ Query ( Ċĉĉĉ ĉ """ ĊĠĠĠĠĠĠĠ ĠMATCH Ġ( person : Person Entity )- [: MEMBER _ OF ]-> ( department : Department Entity ) ĊĠĠĠĠĠĠĠ ĠRETURN Ġperson , Ġdepartment ĊĠĠĠ Ġ""" Ċĉ ĉ ) Ċĉ ĉ fun Ġfind Person With Department (): ĠList < Person Department QueryResult > Ċ ĉ } ĊĊ ĉ @ Configuration Ċ ĉ @ Enable Transaction Management Ċ ĉ @ Enable Neo 4 j Repositories ( consider Nested Repositories Ġ= Ġtrue ) Ċ ĉ open Ġclass ĠConfig Ġ: ĠAbstract Neo 4 j Config () Ġ{ ĊĊĉ ĉ @ Bean Ċĉ ĉ open Ġfun Ġbookmark Capture (): ĠBook mark Capture Ġ{ Ċĉĉ ĉ return ĠBook mark Capture () Ċĉ ĉ } ĊĊĉ ĉ @ Bean Ċĉ ĉ override Ġfun Ġtransaction Manager ( driver : ĠDriver , Ġdatabase Name Provider : ĠDatabase Selection Provider ): ĠPlatform Transaction Manager Ġ{ Ċĉĉ ĉ val Ġbookmark Capture Ġ= Ġbookmark Capture () Ċĉĉ ĉ return ĠNeo 4 j Transaction Manager ( driver , Ġdatabase Name Provider , ĠNeo 4 j Bookmark Manager . create ( bookmark Capture )) Ċĉ ĉ } ĊĊĉ ĉ /** Ċĉĉ Ġ* ĠMake Ġsure Ġthat Ġparticular Ġentity Ġis Ġknow . ĠThis Ġis Ġessential Ġto Ġall Ġtests ĠGH - 2 3 4 9 Ċĉĉ Ġ*/ Ċĉ ĉ override Ġfun Ġget Mapping Base Packages (): ĠCollection < String ?> ? Ġ{ Ċĉĉ ĉ return ĠlistOf ( Department Entity :: class . java . get Package (). name ) Ċĉ ĉ } ĊĊĉ ĉ @ Bean Ċĉ ĉ override Ġfun Ġdriver (): ĠDriver Ġ{ Ċĉĉ ĉ return Ġne o 4 j Connection Support . driver Ċĉ ĉ } Ċ ĉ } Ċ }