/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 0 . ĠT ol gee Ċ Ġ*/ Ċ Ċ package Ġio . tol gee . initial _ user _ creation Ċ Ċ import Ġio . tol gee . Application Ċ import Ġio . tol gee . Clean Db BeforeClass Ċ import Ġio . tol gee . command Line Run ners . Initial User Creator CommandLine Runner Ċ import Ġio . tol gee . configuration . tol gee . T ol gee Properties Ċ import Ġio . tol gee . service . User Account Service Ċ import Ġio . tol gee . testing . Abstract Transactional Test Ċ import Ġio . tol gee . testing . Context Re creating Test Ċ import Ġio . tol gee . testing . assertions . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . After All Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . Test Instance Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . security . crypto . bcrypt . BC rypt Password Encoder Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ import Ġjava . io . File Ċ Ċ @ Context Re creating Test Ċ @ SpringBootTest ( ĊĠ Ġclasses Ġ= Ġ[ Application :: class ], ĊĠ Ġproperties Ġ= Ġ[ ĊĠĠĠ Ġ" tol gee . file - storage . fs - data - path = ./ build / create - enabled - test - data /", ĊĠĠĠ Ġ" tol gee . authentication . create - initial - user = true ", ĊĠĠĠ Ġ" tol gee . authentication . initial Username = jo h ny " ĊĠ Ġ] Ċ ) Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ @ Transactional Ċ @ Clean Db BeforeClass Ċ class ĠCreate Enabled Test Ġ: ĠAbstract Transactional Test () Ġ{ ĊĠ Ġ@ set : Autowired ĊĠ Ġlateinit Ġvar Ġtol gee Properties : ĠT ol gee Properties ĊĊĠ Ġ@ set : Autowired ĊĠ Ġlateinit Ġvar Ġuser Account Service : ĠUser Account Service ĊĊĠ Ġprivate Ġval Ġpassword File Ġ= ĠFile ("./ build / create - enabled - test - data / initial . pwd ") ĊĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġinitial User Creator CommandLine Runner : ĠInitial User Creator CommandLine Runner ĊĊĠ Ġ@ Before All ĊĠ Ġfun Ġcall The Runner () Ġ{ ĊĠĠĠ Ġinitial User Creator CommandLine Runner . run () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġstores Password () Ġ{ ĊĠĠĠ ĠassertThat ( password File ). exists () ĊĠĠĠ ĠassertThat ( password File . read Text ()). isNotBlank ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġpassword Stored In Db () Ġ{ ĊĠĠĠ Ġval Ġj oh ny Ġ= Ġuser Account Service . find Optional (" jo h ny "). orElse Get ( null ) ĊĠĠĠ Ġval Ġb Crypt Password Encoder Ġ= ĠBC rypt Password Encoder () ĊĠĠĠ ĠassertThat ( b Crypt Password Encoder . matches ( password File . read Text (), Ġj oh ny . password )). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ After All ĊĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠ Ġpassword File . delete () ĊĠ Ġ} Ċ } Ċ