package Ġcom . kar umi . spring boot kotlin . controllers Ċ Ċ import Ġarrow . core . getOrElse Ċ import Ġcom . kar umi . spring boot kotlin . authentication . api . New Developer Request Ċ import Ġcom . kar umi . spring boot kotlin . developers . api . Developer Body Ċ import Ġcom . kar umi . spring boot kotlin . developers . domain . Developer Ċ import Ġcom . kar umi . spring boot kotlin . developers . storage . Developer Dao Ċ import Ġcom . kar umi . spring boot kotlin . developers . storage . Developer Repository Ċ import Ġcom . kar umi . spring boot kotlin . get Authorized Ċ import Ġcom . kar umi . spring boot kotlin . given . Given Developer Ċ import Ġcom . kar umi . spring boot kotlin . post Authorized Ċ import Ġcom . kar umi . spring boot kotlin . uuid Ċ import Ġio . kot lint est . provided . Clean Database Listener Ċ import Ġio . kot lint est . shouldBe Ċ import Ġio . kot lint est . specs . String Spec Ċ import Ġio . kot lint est . spring . Spring Listener Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . web . client . Test Rest Template Ċ import Ġorg . springframework . boot . web . server . Local Server Port Ċ import Ġorg . springframework . http . HttpStatus . BAD _ REQUEST Ċ import Ġorg . springframework . http . HttpStatus . CREATED Ċ import Ġorg . springframework . http . HttpStatus . NOT _ FOUND Ċ import Ġorg . springframework . http . HttpStatus . OK Ċ import Ġorg . springframework . http . HttpStatus . UN AUTHORIZ ED Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġjava . util . UUID Ċ Ċ @ SpringBootTest ( web Environment Ġ= ĠSpring Boot Test . Web Environment . RANDOM _ PORT ) Ċ class ĠDeveloper Controller Test Ġ@ Autowired Ġconstructor ( ĊĠ Ġprivate Ġval Ġdao : ĠDeveloper Dao , ĊĠ Ġprivate Ġval Ġrest Template : ĠTest Rest Template , ĊĠ Ġprivate Ġval Ġrepository : ĠDeveloper Repository Ċ ) Ġ: ĠString Spec (), ĠGiven Developer Ġ{ ĊĊĠ Ġ@ Local Server Port ĊĠ Ġvar ĠPORT : ĠInt Ġ= Ġ 0 ĊĊĠ Ġval ĠURL ĊĠĠĠ Ġget () Ġ= Ġ" http :// localhost :$ PORT " ĊĊĠ Ġoverride Ġfun Ġlisteners () Ġ= ĠlistOf ( Spring Listener , ĠClean Database Listener ( repository )) ĊĊĠ Ġinit Ġ{ ĊĊĠĠĠ Ġ" developer ĠPOST Ġshould Ġcreate Ġa Ġdeveloper Ġif Ġit 's Ġa Ġkar umi Ġdeveloper " Ġ{ ĊĠĠĠĠĠ Ġval Ġnew Developer Ġ= ĠNEW _ K AR UM I _ DE VELO PER ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġwith Session (). post Developer ( new Developer ) ĊĠĠĠĠĠ Ġval Ġcreated Developer Ġ= Ġresult . body !! ĊĠĠĠĠĠ Ġval Ġobtained Developer Ġ= Ġget ById ( created Developer . id . uuid ()) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠCRE ATED ĊĠĠĠĠĠ Ġcreated Developer . username ĠshouldBe Ġnew Developer . username ĊĠĠĠĠĠ Ġcreated Developer . email ĠshouldBe Ġnew Developer . email ĊĠĠĠĠĠ Ġobtained Developer . username ĠshouldBe Ġnew Developer . username ĊĠĠĠĠĠ Ġobtained Developer . email ĠshouldBe Ġnew Developer . email ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠPOST Ġshould Ġreturns Ġ 4 0 0 Ġif Ġit Ġisn 't Ġa Ġkar umi Ġdeveloper " Ġ{ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġwith Session (). post ( ANY _ NEW _ DE VELO PER ) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠBAD _ REQUEST ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠPOST Ġshould Ġreturns Ġ 4 0 0 Ġif Ġthe Ġjson Ġbody Ġisn 't Ġexpected " Ġ{ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġwith Session (). post ( Invalid Model ()) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠBAD _ REQUEST ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠPOST Ġshould Ġreturns Ġ 4 0 1 Ġif Ġdoesn 't Ġhave Ġauthentication Ġtoken " Ġ{ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġrest Template . post ( ANY _ NEW _ DE VELO PER ) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠU NA UTH ORIZ ED ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠGET Ġshould Ġretrieve Ġby Ġid " Ġ{ ĊĠĠĠĠĠ Ġval Ġdeveloper Ġ= Ġcreate ( K AR UM I _ DE VELO PER ) ĊĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġwith Session (). get Developer ( developer ) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠOK ĊĠĠĠĠĠ Ġresult . body ?. username ĠshouldBe Ġdeveloper . username ĊĠĠĠĠĠ Ġresult . body ?. email ĠshouldBe Ġdeveloper . email ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠGET Ġshould Ġreturns Ġ 4 0 4 Ġif Ġthere Ġisn 't Ġthe Ġdeveloper Ġin Ġthe Ġdatabase " Ġ{ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġwith Session (). get ( DE VELO PER _ ID ) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠNOT _ FOUND ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ" developer ĠGET Ġshould Ġreturns Ġ 4 0 1 Ġif Ġdoesn 't Ġhave Ġauthentication Ġtoken " Ġ{ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġrest Template . get ( DE VELO PER _ ID ) ĊĊĠĠĠĠĠ Ġresult . statusCode ĠshouldBe ĠU NA UTH ORIZ ED ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠTest Rest Template . post Developer ( ĊĠĠĠ Ġdeveloper : ĠNew Developer Request ĊĠ Ġ): ĠResponseEntity < Developer Body > Ġ= Ġpost Authorized ("$ URL / developer ", Ġdeveloper ) ĊĊĠ Ġprivate Ġfun Ġ< A > ĠTest Rest Template . post ( value : ĠA ): ĠResponseEntity < String > Ġ= ĊĠĠĠ Ġpost Authorized ("$ URL / developer ", Ġvalue ) ĊĊĠ Ġprivate Ġfun ĠTest Rest Template . get Developer ( developer : ĠDeveloper ): ĠResponseEntity < Developer Body > Ġ= ĊĠĠĠ Ġget Authorized ("$ URL / developer /${ developer . id }") ĊĊĠ Ġprivate Ġfun ĠTest Rest Template . get ( id : ĠUUID ): ĠResponseEntity < String > Ġ= ĊĠĠĠ Ġget Authorized ("$ URL / developer /$ id ") ĊĊĠ Ġprivate Ġdata Ġclass ĠInvalid Model ( val Ġinvalid : ĠString Ġ= Ġ"") ĊĊĠ Ġprivate Ġfun Ġwith Session (): ĠTest Rest Template Ġ{ ĊĠĠĠ Ġcreate ( SESSION _ DE VELO PER ) ĊĠĠĠ Ġreturn Ġrest Template ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget ById ( id : ĠUUID ) Ġ= Ġdao . getById ( id ). getOrElse Ġ{ Ġnull Ġ} ?. getOrElse Ġ{ Ġnull Ġ} !! ĊĠ Ġprivate Ġfun Ġcreate ( developer : ĠDeveloper ) Ġ= Ġdao . create ( developer ). getOrElse Ġ{ Ġnull Ġ} !! Ċ } Ċ