package Ġbr . com . z up . academy . list Ċ Ċ import Ġbr . com . z up . academy . details . create Grpc Response Ċ import Ġbr . com . z up academy .* Ċ import Ġbr . com . z up academy . details . Details Re ponse Ċ import Ġbr . com . z up academy . list . Client Keys Response Ċ import Ġbr . com . z up academy . shared . Grpc Client Factory Ċ import Ġcom . google . protobuf . Timestamp Ċ 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 . 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 . junit . jupiter . api . Assertions . assertEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertFalse Ċ import Ġorg . junit . jupiter . api . Assertions . assertTrue Ċ import Ġorg . mockito . Mockito Ċ import Ġjava . util .* Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Mic ronaut Test Ċ internal Ġclass ĠList Keys Controller Test IT Ġ{ ĊĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġ@ field : Client ("/") ĊĠĠĠ Ġlateinit Ġvar ĠhttpClient : ĠHttpClient ĊĊĠĠĠ Ġ@ field : Inject ĊĠĠĠ Ġlateinit Ġvar Ġgrpc Client : ĠAll Keys Service Grpc . All Keys Service Blocking Stub ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito . reset ( grpc Client ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġlist Ġof Ġkeys Ġwhen Ġclient Ġid Ġis Ġvalid `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠclientId Ġ= ĠUUID . randomUUID (). toString () ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( grpc Client . findAll ( Mockito . any ())). thenReturn ( create Grpc Response ( clientId )) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġassert DoesNot Throw Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( HttpRequest . GET < List < Client Keys Response >> ("/ pix / key manager /${ clientId } "), ĠList :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . OK , Ġstatus ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertFalse ( response . body . isEmpty ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġbody (). size ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġstatus Ġnot Ġfound Ġwhen Ġclient Ġid Ġis Ġinvalid `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠclientId Ġ= ĠUUID . randomUUID (). toString () ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( grpc Client . findAll ( Mockito . any ())). then Throw ( Status RuntimeException ( Status . NOT _ FOUND )) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠassertThrows < HttpClient Response Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( HttpRequest . GET < List < Client Keys Response >> ("/ pix / key manager /${ clientId } "), ĠList :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . NOT _ FOUND , Ġstatus ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġempty Ġlist Ġof Ġkeys Ġwhen Ġthe Ġclient Ġdoesn 't Ġhave Ġone `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠclientId Ġ= ĠUUID . randomUUID (). toString () ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( grpc Client . findAll ( Mockito . any ())). thenReturn ( Find All Keys Response . newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġassert DoesNot Throw Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠhttpClient . to Blocking (). exchange ( HttpRequest . GET < List < Client Keys Response >> ("/ pix / key manager /${ clientId } "), ĠList :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġwith ( response ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( HttpStatus . OK , Ġstatus ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( body (). size Ġ== Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Factory ĊĠĠĠ Ġ@ Re places ( factory Ġ= ĠGr pc Client Factory :: class ) ĊĠĠĠ Ġinternal Ġclass ĠKey Register Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Singleton ĊĠĠĠĠĠĠĠ Ġinternal Ġfun Ġstub Register Mock () Ġ= ĠMockito . mock ( All Keys Service Grpc . All Keys Service Blocking Stub :: class . java ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Factory Ċ fun Ġcreate Grpc Response ( clientId : ĠString ): ĠFind All Keys Response Ġ{ ĊĠĠĠ Ġval Ġkey Ġ= ĠFind All Keys Response . Key . newBuilder () ĊĠĠĠĠĠĠĠ Ġ. set Key (" 1 2 3 4 5 6 7 8 9 1 2 ") ĊĠĠĠĠĠĠĠ Ġ. set Pix Id ( UUID . randomUUID (). toString ()) ĊĠĠĠĠĠĠĠ Ġ. set ClientId ( clientId ) ĊĠĠĠĠĠĠĠ Ġ. set KeyType ( KeyType . CP F ) ĊĠĠĠĠĠĠĠ Ġ. set Account Type ( Account Type . CONT A _ COR REN TE ) ĊĠĠĠĠĠĠĠ Ġ. set CreatedAt ( Timestamp . newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Nan os ( 1 2 4 2 1 3 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Seconds ( 1 6 2 1 3 2 0 1 4 2 )) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġreturn ĠFind All Keys Response . newBuilder () ĊĠĠĠĠĠĠĠ Ġ. add Keys ( key ) ĊĠĠĠĠĠĠĠ Ġ. add Keys ( key ) ĊĠĠĠĠĠĠĠ Ġ. build () Ċ }