package Ġorg . ab ond ar . experimental . phone . server . service Ċ Ċ import Ġorg . ab ond ar . experimental . phone . server . conf . init Test DB Ċ import Ġorg . ab ond ar . experimental . phone . server . conf . service DI Ċ import Ġorg . ab ond ar . experimental . phone . server . model . Contact Ċ import Ġorg . ab ond ar . experimental . phone . server . model . User Ċ import Ġorg . ab ond ar . experimental . phone . server . org . ab ond ar . experimental . phone . server . service . Contact Service Ċ import Ġorg . ab ond ar . experimental . phone . server . org . ab ond ar . experimental . phone . server . service . UserService Ċ import Ġorg . jetbrains . ex posed . dao . exceptions . Entity NotFoundException Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . kode in . di . instance Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertTrue ĊĊ Ċ class ĠContact Service Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcontact Service Ġby Ġservice DI . instance < Contact Service >() ĊĠĠĠ Ġprivate Ġval ĠuserService Ġby Ġservice DI . instance < UserService >() ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreate Contact Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġcreate User () ĊĊĠĠĠĠĠĠĠ Ġval Ġcontact Ġ= ĠContact ( 0 ," test "," test "," test "," ") ĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġcontact Service . create Contact ( contact , id ). to Contact () ĊĊĠĠĠĠĠĠĠ ĠassertTrue Ġ{ res . id > 0 } ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreate Contact User NotFound Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĊĠĠĠĠĠĠĠ Ġval Ġcontact Ġ= ĠContact ( 0 ," test "," test "," test "," ") ĊĠĠĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ Ġcontact Service . create Contact ( contact , 0 )} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Contact Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġusr Id Ġ= Ġcreate User () ĊĠĠĠĠĠĠĠ Ġval Ġct Id Ġ= Ġcreate Contact ( usr Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġcontact Service . get Contact ById ( ct Id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ct Id , res . id ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete Contact Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġusr Id Ġ= Ġcreate User () ĊĠĠĠĠĠĠĠ Ġval Ġct Id Ġ= Ġcreate Contact ( usr Id ) ĊĊĠĠĠĠĠĠĠ Ġcontact Service . delete Contact ( ct Id ) ĊĊĠĠĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ Ġcontact Service . get Contact ById ( ct Id ) Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Contact Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġusr Id Ġ= Ġcreate User () ĊĠĠĠĠĠĠĠ Ġval Ġct Id Ġ= Ġcreate Contact ( usr Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġup d Ġ= ĠContact ( ct Id ," test "," test "," test "," email ") ĊĠĠĠĠĠĠĠ Ġcontact Service . update Contact ( upd ) ĊĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġcontact Service . get Contact ById ( upd . id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( upd . email , res . email ) ĊĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Merge Contact Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġusr Id Ġ= Ġcreate User () ĊĠĠĠĠĠĠĠ Ġval Ġct Id Ġ= Ġcreate Contact ( usr Id ) ĊĠĠĠĠĠĠĠ Ġval Ġct Id 1 Ġ= Ġcreate Contact ( usr Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġup d Ġ= ĠContact ( ct Id ," test "," test "," test "," email ") ĊĠĠĠĠĠĠĠ Ġcontact Service . update And Merged Contacts ( upd , ĠlistOf ( ct Id 1 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġcontact Service . get Contact ById ( upd . id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( upd . email , res . email ) ĊĊĠĠĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ Ġcontact Service . get Contact ById ( ct Id 1 ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete User Cascade Test (){ ĊĠĠĠĠĠĠĠ Ġinit Test DB () ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠUser ( 0 ," test "," test ") ĊĠĠĠĠĠĠĠ Ġval Ġusr Ġ= ĠuserService . createUser ( user ). to User () ĊĊĠĠĠĠĠĠĠ Ġval Ġcontact Ġ= ĠContact ( 0 ," test "," test "," test "," ") ĊĠĠĠĠĠĠĠ Ġval Ġct Ġ= Ġcontact Service . create Contact ( contact , usr . id ). to Contact () ĊĊĠĠĠĠĠĠĠ ĠuserService . delete User ( usr . id ) ĊĠĠĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ ĠuserService . getUser ById ( usr . id ) Ġ} ĊĠĠĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ Ġcontact Service . get Contact ById ( ct . id ) Ġ} ĊĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġcreate User (): Int Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠUser ( 0 ," test "," test ") ĊĠĠĠĠĠĠĠ Ġval Ġusr Ġ= ĠuserService . createUser ( user ). to User () ĊĊĠĠĠĠĠĠĠ Ġreturn Ġusr . id ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġcreate Contact ( userId : ĠInt ): Int { ĊĊĠĠĠĠĠĠĠ Ġval Ġcontact Ġ= ĠContact ( 0 ," test "," test "," test "," ") ĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġcontact Service . create Contact ( contact , userId ). to Contact () ĊĊĠĠĠĠĠĠĠ Ġreturn Ġres . id ĊĠĠĠ Ġ} Ċ } Ċ