package Ġbr . com . z up academy . ray ll and erson . pix . delete Ċ Ċ import Ġbr . com . z up academy . ray ll and erson . Pix Key Delete Response Ċ import Ġbr . com . z up academy . ray ll and erson . Pix Key Delete Service Grpc Ċ import Ġbr . com . z up academy . ray ll and erson . core . factory . Grpc Client Factory Ċ 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 . HttpRequest Ċ import Ġio . mic ronaut . http . HttpResponse Ċ 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 Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . Assertions .* Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . junit . jupiter . api . assert DoesNot Throw Ċ import Ġorg . mockito . BDD Mockito Ċ import Ġorg . mockito . Mockito Ċ import Ġjava . util .* Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Mic ronaut Test Ċ internal Ġclass ĠDelete Key Controller Test Ġ{ ĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġ@ field : Client ("/") ĊĠĠĠ Ġlateinit Ġvar Ġrest Client : ĠHttpClient ĊĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġlateinit Ġvar Ġgrpc Client : ĠP ix Key Delete Service Grpc . Pix Key Delete Service Blocking Stub ĊĊĠĠĠ Ġvar ĠclientId Ġ= Ġ"" ĊĠĠĠ Ġvar ĠbaseUrl Ġ= Ġ"" ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup (){ ĊĠĠĠĠĠĠĠ ĠclientId Ġ= ĠUUID . randomUUID (). toString () ĊĠĠĠĠĠĠĠ ĠbaseUrl Ġ= Ġ"/ api / v 1 / clients /$ clientId / pix / keys " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Each ĊĠĠĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito . reset ( grpc Client ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġremove Ġpix Ġkey `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Grpc Response Ġ= ĠP ix Key Delete Response . newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Pix Id ( UUID . randomUUID (). toString ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set ClientId ( clientId ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito .` when `( grpc Client . delete ( Mockito . any ())). thenReturn ( expected Grpc Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= ĠDelete Pix Key Request ( expected Grpc Response . pix Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ( baseUrl , Ġrequest Body ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse : ĠHttpResponse < Any > Ġ= Ġassert DoesNot Throw Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrest Client . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . OK , Ġresponse . status ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should n 't Ġremove Ġpix Ġkey Ġwhen Ġpix Id Ġis Ġempty `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= ĠDelete Pix Key Request ("") ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ( baseUrl , Ġrequest Body ) ĊĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrest Client . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . BAD _ REQUEST , Ġerror . status ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( error . message !!. contains (" Missing Ġrequired Ġcreator Ġproperty Ġ' pix Id ' ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should n 't Ġremove Ġpix Ġkey Ġwhen Ġpix Id Ġnot Ġexists `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Error Ġ= ĠStatus RuntimeException ( Status . NOT _ FOUND . with Description (" Pix Ġid ĠnÃ£o Ġencontr ado ")) ĊĠĠĠĠĠĠĠ ĠB DD Mockito .` when `( grpc Client . delete ( Mockito . any ())). then Throw ( expected Error ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= ĠDelete Pix Key Request ( UUID . randomUUID (). toString ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ( baseUrl , Ġrequest Body ) ĊĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrest Client . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . NOT _ FOUND , Ġerror . status ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Error . status . description , Ġerror . message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should n 't Ġremove Ġpix Ġkey Ġwhen ĠclientId Ġnot Ġexists `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Error Ġ= ĠStatus RuntimeException ( Status . NOT _ FOUND . with Description (" Client Ġid ĠnÃ£o Ġencontr ado ")) ĊĠĠĠĠĠĠĠ ĠB DD Mockito .` when `( grpc Client . delete ( Mockito . any ())). then Throw ( expected Error ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Body Ġ= ĠDelete Pix Key Request ( UUID . randomUUID (). toString ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ( baseUrl , Ġrequest Body ) ĊĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrest Client . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . NOT _ FOUND , Ġerror . status ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Error . status . description , Ġerror . message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Factory ĊĠĠĠ Ġ@ Re places ( factory Ġ= ĠGr pc Client Factory :: class ) ĊĠĠĠ Ġinternal Ġclass ĠMockito Key Rem over Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Singleton ĊĠĠĠĠĠĠĠ Ġinternal Ġfun Ġkey Rem over Mock () Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . mock ( Pix Key Delete Service Grpc . Pix Key Delete Service Blocking Stub :: class . java ) ĊĠĠĠ Ġ} Ċ } Ċ