package Ġbr . com . z up . luc asm igu ins . pix . regist ra Ċ Ċ import Ġbr . com . z up . luc asm igu ins . grpc . Key manager Regist ra Grpc Service Grpc Ċ import Ġbr . com . z up . luc asm igu ins . grpc . Regist ra Ch ave Pix Response Ċ import Ġbr . com . z up . luc asm igu ins . pix . enums . Tipo De Ch ave Request . EMAIL Ċ import Ġbr . com . z up . luc asm igu ins . pix . enums . Tipo De Cont a Request . CONT A _ COR REN TE Ċ import Ġbr . com . z up . luc asm igu ins . shared . grpc . Key Manager Grpc Factory Ċ 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 . 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 . Assertions .* Ċ 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 .* Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Mic ronaut Test Ċ internal Ġclass ĠRegist ra Pix Ch ave Pix Controller Test Ġ{ ĊĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġlateinit Ġvar Ġregist ra Stub : ĠKey manager Regist ra Grpc Service Grpc . Key manager Regist ra Grpc Service Blocking Stub ĊĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġ@ field : Client ("/") ĊĠĠĠ Ġlateinit Ġvar Ġclient : ĠHttpClient ĊĊĊĠĠĠ Ġ// Ġhappy Ġpath ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` de ve Ġregist rar Ġuma Ġnova Ġch ave Ġpix `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġcliente Id Ġ= ĠUUID . randomUUID (). toString () ĊĠĠĠĠĠĠĠ Ġval Ġpix Id Ġ= ĠUUID . randomUUID (). toString () ĊĊĠĠĠĠĠĠĠ Ġval Ġresp osta Grpc Ġ= ĠRegist ra Ch ave Pix Response . newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Cliente Id ( cliente Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Pix Id ( pix Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ Ġgiven ( regist ra Stub . regist ra ( Mockito . any ())). willReturn ( resp osta Grpc ) ĊĊĊĠĠĠĠĠĠĠ Ġval Ġnova Ch ave Pix Ġ= ĠN ova Ch ave Pix Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtipo De Cont a Ġ= ĠCON TA _ COR REN TE , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġch ave Ġ= Ġ" p ont e @ email 2 . com ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtipo De Ch ave Ġ= ĠE MAIL ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . POST ("/ api / v 1 / client es /$ cliente Id / pix ", Ġnova Ch ave Pix ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġclient . to Blocking (). exchange ( request , ĠN ova Ch ave Pix Request :: class . java ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . CREATED , Ġresponse . status ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( response . headers . contains (" Location ")) ĊĠĠĠĠĠĠĠ ĠassertTrue ( response . header (" Location ") !!. contains ( pix Id )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġinternal Ġfun Ġ` de ve Ġret orn ar Ġum Ġerro Ġquando Ġdados Ġinvalid os `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcliente Id Ġ= ĠUUID . randomUUID (). toString () ĊĊĠĠĠĠĠĠĠ Ġval Ġnova Ch ave Pix Ġ= ĠN ova Ch ave Pix Request ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtipo De Cont a Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġch ave Ġ= Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtipo De Ch ave Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠHttpRequest . POST ("/ api / v 1 / client es /$ cliente Id / pix ", Ġnova Ch ave Pix ) ĊĊĠĠĠĠĠĠĠ Ġval Ġthrown Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠ Ġclient . to Blocking (). exchange ( request , ĠN ova Ch ave Pix Request :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . BAD _ REQUEST . code , Ġthrown . status . code ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Factory ĊĠĠĠ Ġ@ Re places ( factory Ġ= ĠKey Manager Grpc Factory :: class ) ĊĠĠĠ Ġinternal Ġclass ĠMockito Stub Factory Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ@ Singleton ĊĠĠĠĠĠĠĠ Ġfun Ġstub Mock () Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . mock ( Key manager Regist ra Grpc Service Grpc . Key manager Regist ra Grpc Service Blocking Stub :: class . java ) ĊĠĠĠ Ġ} Ċ }