package Ġbr . com . pix . ed um att 3 . pix . remove čĊč Ċ import Ġbr . com . ed um att 3 . Delete Pix Key Service Grpc č Ċ import Ġbr . com . pix . ed um att 3 . grpc . Grpc Client Factory č Ċ import Ġcom . google . protobuf . Empty č Ċ import Ġio . grpc . Status č Ċ import Ġio . grpc . Status RuntimeException č Ċ import Ġio . mic ronaut . context . annotation . Factory č Ċ import Ġio . mic ronaut . context . annotation . Re places č Ċ import Ġio . mic ronaut . http . HttpHeaders č Ċ import Ġio . mic ronaut . http . HttpRequest č Ċ import Ġio . mic ronaut . http . HttpStatus č Ċ import Ġio . mic ronaut . http . client . HttpClient č Ċ import Ġio . mic ronaut . http . client . annotation . Client č Ċ import Ġio . mic ronaut . http . client . exceptions . HttpClient Response Exception č Ċ import Ġio . mic ronaut . test . extensions . junit 5 . annotation . Mic ronaut Test č Ċ import Ġjak arta . inject . Inject č Ċ import Ġjak arta . inject . Singleton č Ċ import Ġorg . junit . jupiter . api . After Each č Ċ import Ġorg . junit . jupiter . api . Assertions . assertEquals č Ċ import Ġorg . junit . jupiter . api . Assertions . assertFalse č Ċ import Ġorg . junit . jupiter . api . Test č Ċ import Ġorg . junit . jupiter . api . assert Throws č Ċ import Ġorg . mockito . BDD Mockito . given č Ċ import Ġorg . mockito . Mockito č Ċ import Ġjava . util .* čĊč Ċ @ Mic ronaut Test č Ċ internal Ġclass ĠRemove Pix Key Controller Test Ġ{ čĊčĊĠĠĠ Ġ@ Inject čĊĠĠĠ Ġlateinit Ġvar Ġgrpc Client : ĠDelete Pix Key Service Grpc . Delete Pix Key Service Blocking Stub čĊčĊĠĠĠ Ġ@ Inject čĊĠĠĠ Ġ@ field : Client ("/") čĊĠĠĠ Ġlateinit Ġvar Ġclient : ĠHttpClient čĊčĊĠĠĠ Ġ@ After Each čĊĠĠĠ Ġfun Ġclean Up () Ġ{ čĊĠĠĠĠĠĠĠ ĠMockito . reset ( grpc Client ) čĊĠĠĠ Ġ} čĊčĊĠĠĠ Ġ@ Test čĊĠĠĠ Ġinternal Ġfun Ġ` should Ġdelete Ġa Ġpix Ġkey `() Ġ{ čĊčĊĠĠĠĠĠĠĠ Ġgiven ( grpc Client . delete ( Mockito . any ())). willReturn ( Empty . newBuilder (). build ()) čĊčĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / pix / keys /${ UUID . randomUUID (). toString () }", ĠRemove Pix Key Request ( UUID . randomUUID ())) čĊčĊĠĠĠĠĠĠĠ Ġval Ġstatus Ġ= Ġclient . to Blocking (). exchange ( request , ĠAny :: class . java ). status čĊčĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . OK , Ġstatus ) čĊĠĠĠ Ġ} čĊčĊĠĠĠ Ġ@ Test čĊĠĠĠ Ġinternal Ġfun Ġ` should Ġreturn Ġ 5 0 2 Ġwhen Ġpix Ġkey Ġdont Ġbelongs Ġto Ġthe Ġuser `() Ġ{ čĊčĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠStatus . PERMISSION _ DEN IED . with Description (" pix Ġkey Ġdoesn 't Ġbelong Ġto Ġthe Ġcustomer ") čĊĠĠĠĠĠĠĠ Ġgiven ( grpc Client . delete ( Mockito . any ())). will Throw ( Status RuntimeException ( exception )) čĊčĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / pix / keys /${ UUID . randomUUID (). toString () }", ĠRemove Pix Key Request ( UUID . randomUUID ())) čĊčĊĠĠĠĠĠĠĠ Ġval Ġthrown Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ čĊĠĠĠĠĠĠĠĠĠĠĠ Ġclient . to Blocking (). exchange ( request , ĠAny :: class . java ) čĊĠĠĠĠĠĠĠ Ġ} čĊčĊĠĠĠĠĠĠĠ Ġwith ( throw n ){ čĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . FOR BID DEN , Ġstatus ) čĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertFalse ( response . headers . contains ( HttpHeaders . LOCATION )) čĊĠĠĠĠĠĠĠ Ġ} čĊĠĠĠ Ġ} čĊčĊĠĠĠ Ġ@ Test čĊĠĠĠ Ġinternal Ġfun Ġ` should Ġreturn Ġ 5 0 3 Ġwhen Ġpix Ġkey Ġcant Ġbe Ġdeleted Ġon Ġb cb Ġsystem `() Ġ{ čĊčĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠStatus . FAILED _ PRE CONDITION . with Description (" pix Ġkey Ġdoesn 't Ġbelong Ġto Ġthe Ġcustomer ") čĊĠĠĠĠĠĠĠ Ġgiven ( grpc Client . delete ( Mockito . any ())). will Throw ( Status RuntimeException ( exception )) čĊčĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / pix / keys /${ UUID . randomUUID (). toString () }", ĠRemove Pix Key Request ( UUID . randomUUID ())) čĊčĊĠĠĠĠĠĠĠ Ġval Ġthrown Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ čĊĠĠĠĠĠĠĠĠĠĠĠ Ġclient . to Blocking (). exchange ( request , ĠAny :: class . java ) čĊĠĠĠĠĠĠĠ Ġ} čĊčĊĠĠĠĠĠĠĠ Ġwith ( throw n ){ čĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . BAD _ GATE WAY , Ġstatus ) čĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertFalse ( response . headers . contains ( HttpHeaders . LOCATION )) čĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals (" pix Ġkey Ġdoesn 't Ġbelong Ġto Ġthe Ġcustomer ", Ġthis . message ) čĊĠĠĠĠĠĠĠ Ġ} čĊĠĠĠ Ġ} čĊčĊčĊĠĠĠ Ġ@ Factory čĊĠĠĠ Ġ@ Re places ( factory Ġ= ĠGr pc Client Factory :: class ) čĊĠĠĠ Ġinternal Ġclass ĠRemove Key Grpc Stub () Ġ{ čĊčĊĠĠĠĠĠĠĠ Ġ@ Singleton čĊĠĠĠĠĠĠĠ Ġinternal Ġfun Ġget Remove Service () Ġ= ĠMockito . mock ( Delete Pix Key Service Grpc . Delete Pix Key Service Blocking Stub :: class . java ) čĊĠĠĠ Ġ} č Ċ }