package Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . repository Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . jdbc . Auto Configure Test Database Ċ import Ġorg . springframework . boot . test . autoconfigure . jdbc . Auto Configure Test Database . Replace . NONE Ċ import Ġorg . springframework . boot . test . autoconfigure . orm . jpa . Data Jpa Test Ċ import Ġorg . springframework . context . annotation . Import Ċ import Ġorg . springframework . test . context . Active Profiles Ċ import Ġorg . springframework . test . context . transaction . Test Transaction Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . Admin Type Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . Authority Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . config . Auth Db Config Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . maint ain . Auth UserRole Service . Auth UserRole Exception Ċ import Ġjava . util . UUID Ċ Ċ @ Data Jpa Test Ċ @ Active Profiles (" test ") Ċ @ Import ( Auth Db Config :: class ) Ċ @ Auto Configure Test Database ( replace Ġ= ĠNONE ) Ċ @ Transactional Ċ class ĠRole Repository Test Ġ{ ĊĠ Ġ@ Autowired ĊĠ Ġprivate Ġlateinit Ġvar Ġrepository : ĠRole Repository ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġgiven AT rans ient Entity It Can Be Pers isted () Ġ{ ĊĠĠĠ Ġval Ġtransient Entity Ġ= Ġtransient Entity () ĊĠĠĠ Ġval Ġentity Ġ= ĠAuthor ity ( role Code Ġ= Ġtransient Entity . authority , Ġrole Name Ġ= Ġtransient Entity . role Name , Ġadmin Type Ġ= Ġtransient Entity . admin Type ) ĊĠĠĠ Ġval Ġpersisted Entity Ġ= Ġrepository . save ( entity ) ĊĠĠĠ ĠTest Transaction . flag For Commit () ĊĠĠĠ ĠTest Transaction . end () ĊĠĠĠ ĠassertThat ( pers isted Entity . authority ). isNotNull ĊĠĠĠ ĠTest Transaction . start () ĊĠĠĠ Ġval Ġretrieved Entity Ġ= Ġrepository . findBy Role Code ( entity . role Code ) Ġ?: Ġthrow ĊĠĠĠ ĠAuth UserRole Exception (" role ", Ġ" role . not found ") ĊĊĠĠĠ Ġ// Ġequals Ġonly Ġcomp ares Ġthe Ġbusiness Ġkey Ġcolumns ĊĠĠĠ ĠassertThat ( retrie ved Entity ). isEqualTo ( transient Entity ) ĊĠĠĠ ĠassertThat ( retrie ved Entity . authority ). isEqualTo ( transient Entity . authority ) ĊĠĠĠ ĠassertThat ( retrie ved Entity . role Name ). isEqualTo ( transient Entity . role Name ) ĊĠĠĠ ĠassertThat ( retrie ved Entity . admin Type ). isEqualTo ( transient Entity . admin Type ) ĊĊĠĠĠ Ġ// Ġclear Ġup Ġto Ġprevent Ġsubsequent Ġtests Ġfailing ĊĠĠĠ Ġrepository . delete ( retrie ved Entity ) ĊĠĠĠ ĠTest Transaction . flag For Commit () ĊĠĠĠ ĠTest Transaction . end () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġgiven An Existing Role They Can Be Retrie ved () Ġ{ ĊĠĠĠ Ġval Ġretrieved Entity Ġ= Ġrepository . findBy Role Code (" PE CS _ POL ICE ") Ġ?: Ġthrow ĊĠĠĠ ĠAuth UserRole Exception (" role ", Ġ" role . not found ") ĊĠĠĠ ĠassertThat ( retrie ved Entity . authority ). isEqualTo (" ROLE _ PE CS _ POL ICE ") ĊĠĠĠ ĠassertThat ( retrie ved Entity . role Name ). isEqualTo (" PE CS ĠPol ice ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` findAll By OrderBy Role Name Like ĠEXT _ AD M `() Ġ{ ĊĠĠĠ ĠassertThat ( repository . findAll By OrderBy Role Name Like ( Admin Type . EXT _ AD M . admin TypeCode )). extract ing < String > Ġ{ Ġobj : ĠAuthor ity Ġ-> Ġobj . authority Ġ} ĊĠĠĠĠĠ Ġ. contains (" ROLE _ GLOBAL _ SEARCH ", Ġ" ROLE _ PE CS _ POL ICE ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` findAll By OrderBy Role Name Like ĠD PS _ AD M `() Ġ{ ĊĠĠĠ ĠassertThat ( repository . findAll By OrderBy Role Name Like ( Admin Type . D PS _ AD M . admin TypeCode )). extract ing < String > Ġ{ Ġobj : ĠAuthor ity Ġ-> Ġobj . authority Ġ} ĊĠĠĠĠĠ Ġ. contains (" ROLE _ GLOBAL _ SEARCH ", Ġ" ROLE _ UNIT _ TEST _ D PS _ ROLE ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` findAll By OrderBy Role Name Like ĠEXT _ AD M Ġdoes Ġnot Ġcontain ĠD PS ĠRoles `() Ġ{ ĊĠĠĠ ĠassertThat ( repository . findAll By OrderBy Role Name Like ( Admin Type . EXT _ AD M . admin TypeCode )). extract ing < String > Ġ{ Ġobj : ĠAuthor ity Ġ-> Ġobj . authority Ġ} ĊĠĠĠĠĠ Ġ. does Not Contain (" RO LES _ TEST _ D PS ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠfindBy Group Assignable Roles For Username () Ġ{ ĊĠĠĠ ĠassertThat ( repository . findBy Group Assignable Roles For Username (" AUTH _ RO _ V ARY _ USER ")). extract ing < String > Ġ{ Ġobj : ĠAuthor ity Ġ-> Ġobj . role Code Ġ} ĊĠĠĠĠĠ Ġ. contains Exactly (" GLOBAL _ SEARCH ", Ġ" LIC ENCE _ RO ", Ġ" LIC ENCE _ V ARY ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠfindBy Group Assignable Roles For UserId () Ġ{ ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġrepository . findBy Group Assignable Roles For UserId ( ĊĠĠĠĠĠĠĠ ĠUUID . fromString (" 5 E 3 8 5 0 B 9 - 9 D 6 E - 4 9 D 7 - B 8 E 7 - 4 2 8 7 4 D 6 CE EA 8 ") ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ). extract ing < String > Ġ{ Ġobj : ĠAuthor ity Ġ-> Ġobj . role Code Ġ} ĊĠĠĠĠĠ Ġ. contains Exactly (" GLOBAL _ SEARCH ", Ġ" LIC ENCE _ RO ", Ġ" LIC ENCE _ V ARY ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtransient Entity () Ġ= ĠAuthor ity ( role Code Ġ= Ġ" hdc ", Ġrole Name Ġ= Ġ" Lic ences ", Ġadmin Type Ġ= ĠlistOf ( Admin Type . EXT _ AD M )) Ċ } Ċ