package Ġbr . com . z up . fab iano . controller Ċ Ċ import Ġbr . com . z up . edu .* Ċ import Ġbr . com . z up . fab iano . dto . Ch ave Pix Delete Request Ċ import Ġbr . com . z up . fab iano . dto . Ch ave Pix Register Request Ċ import Ġio . grpc . Status Ċ import Ġio . grpc . Status RuntimeException Ċ import Ġio . mic ronaut . context . annotation . Re places Ċ 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 Ġorg . junit . jupiter . api .* Ċ import Ġorg . mockito . BDD Mockito Ċ import Ġorg . mockito . Mockito Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Mic ronaut Test ( transaction al Ġ= Ġfalse ) Ċ internal Ġclass ĠCh ave Pix Delete Test Ġ{ ĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar Ġgrpc Client : ĠCh ave Pix Service Grpc . Ch ave Pix Service Blocking Stub ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġ@ field : Client ("/") ĊĠĠĠ Ġlateinit Ġvar ĠhttpClient : ĠHttpClient ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġrest Before () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito . reset ( grpc Client ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Each ĊĠĠĠ Ġfun Ġrest Aff ter () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito . reset ( grpc Client ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test e Ġdeve Ġret orn ar Ġ 2 0 0 Ġpara Ġdelete Ġvalid o ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġgrpc Response Ġ= ĠRem over Ch ave Pix Grpc Response ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setId Ch ave Pix (" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito . given ( grpc Client . remo ver Ch ave Pix ( Mockito . any ())). willReturn ( grpc Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / ch ave - pix ", ĠCh ave Pix Delete Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" c 5 6 d fef 4 - 7 9 0 1 - 4 4 fb - 8 4 e 2 - a 2 ce fb 1 5 7 8 9 0 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠhttpClient . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġwith ( response ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( HttpStatus . OK , Ġresponse . status ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test e Ġdeve Ġret orn ar Ġbad Ġrequest Ġpara Ġid Ġclient Ġnull ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġgrpc Response Ġ= ĠRem over Ch ave Pix Grpc Response ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setId Ch ave Pix (" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito . given ( grpc Client . remo ver Ch ave Pix ( Mockito . any ())). willReturn ( grpc Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / ch ave - pix ", ĠCh ave Pix Delete Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġwith ( exception ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( HttpStatus . BAD _ REQUEST , Ġexception . status ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( exception . message !!. contains (" Missing Ġrequired Ġcreator Ġproperty Ġ' id Client ' ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test e Ġdeve Ġret orn ar Ġbad Ġrequest Ġpara Ġid Ġch ave Ġpix Ġnull ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġgrpc Response Ġ= ĠRem over Ch ave Pix Grpc Response ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setId Ch ave Pix (" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito . given ( grpc Client . remo ver Ch ave Pix ( Mockito . any ())). willReturn ( grpc Response ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / ch ave - pix ", ĠCh ave Pix Delete Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" c 5 6 d fef 4 - 7 9 0 1 - 4 4 fb - 8 4 e 2 - a 2 ce fb 1 5 7 8 9 0 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġwith ( exception ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( HttpStatus . BAD _ REQUEST , Ġexception . status ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( exception . message !!. contains (" Missing Ġrequired Ġcreator Ġproperty Ġ' id Ch ave Pix ' ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test e Ġdeve Ġret orn ar Ġnot Ġfound Ġpara Ġid Ġch ave Ġpix Ġn ao Ġencontr ado ` (){ ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito . given ( grpc Client . remo ver Ch ave Pix ( Mockito . any ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. will Throw ( Status . NOT _ FOUND . with Description (" ch ave ĠnÃ£o Ġencontr ada "). as RuntimeException ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / ch ave - pix ", ĠCh ave Pix Delete Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" c 5 6 d fef 4 - 7 9 0 1 - 4 4 fb - 8 4 e 2 - a 2 ce fb 1 5 7 8 9 0 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġwith ( exception ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( HttpStatus . NOT _ FOUND , Ġexception . status ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test e Ġdeve Ġret orn ar Ġfor bb iden Ġpara Ġid Ġch ave Ġpix Ġn ao Ġpert enc ente Ġa Ġclient Ġid ` (){ ĊĊĠĠĠĠĠĠĠ ĠB DD Mockito . given ( grpc Client . remo ver Ch ave Pix ( Mockito . any ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. will Throw ( Status . PERMISSION _ DEN IED . with Description (" ch ave Ġpix Ġn ao Ġpert ence Ġa Ġesse Ġcliente "). as RuntimeException ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . DELETE ("/ api / ch ave - pix ", ĠCh ave Pix Delete Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" c 5 6 d fef 4 - 7 9 0 1 - 4 4 fb - 8 4 e 2 - a 2 ce fb 1 5 7 8 9 0 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 1 ", ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexception Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( request , ĠAny :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġwith ( exception ){ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( HttpStatus . FOR BID DEN , Ġexception . status ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( exception . message Ġ," ch ave Ġpix Ġn ao Ġpert ence Ġa Ġesse Ġcliente ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Singleton ĊĠĠĠ Ġ@ Re places ( bean Ġ= ĠCh ave Pix Service Grpc . Ch ave Pix Service Blocking Stub :: class ) ĊĠĠĠ Ġfun Ġblocking Stub (): ĠCh ave Pix Service Grpc . Ch ave Pix Service Blocking Stub ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠMockito . mock ( Ch ave Pix Service Grpc . Ch ave Pix Service Blocking Stub :: class . java ) ĊĠĠĠ Ġ} Ċ Ċ }