package Ġcom . github . sp art us ch . r ater et rie ver . infrastructure . provider . extensions Ċ Ċ import Ġcom . github . jen sp ie g sa . wire mock extension . Inject Server Ċ import Ġcom . github . jen sp ie g sa . wire mock extension . Wire Mock Extension Ċ import Ġcom . github . sp art us ch . r ater et rie ver . infrastructure . provider . exception . RequestException Ċ import Ġcom . github . sp art us ch . r ater et rie ver . utils . Wire Mock Utils . stub Response Ċ import Ġcom . github . tom ake hur st . wire mock . Wire Mock Server Ċ import Ġcom . github . tom ake hur st . wire mock . client . Wire Mock Ċ import Ġio . micro meter . core . instrument . simple . Simple Meter Registry Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Throwable Assert Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . junit . jupiter . params . Parameterized Test Ċ import Ġorg . junit . jupiter . params . provider . Value Source Ċ import Ġjava . net . URI Ċ import Ġjava . net . http . HttpClient Ċ Ċ @ Extend With ( Wire Mock Extension :: class ) Ċ class ĠHttpClient Extensions IT Ġ{ ĊĊĠĠĠ Ġ@ Inject Server ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġserver Mock : ĠWire Mock Server ĊĊĠĠĠ Ġprivate Ġval Ġtimer Ġ= ĠSimple Meter Registry (). timer (" test Timer ") ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuri : ĠURI ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuri Path : ĠString ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcut : ĠHttpClient ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġuri Path Ġ= Ġ"/ api / header / search ? q =" ĊĠĠĠĠĠĠĠ Ġuri Ġ= ĠURI ("${ server Mock . baseUrl ()} $ uri Path ") ĊĠĠĠĠĠĠĠ Ġcut Ġ= ĠHttpClient . new HttpClient () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Parameterized Test ĊĠĠĠ Ġ@ Value Source ( ints Ġ= Ġ[ 2 0 0 , Ġ 2 0 1 , Ġ 3 0 1 , Ġ 3 0 2 , Ġ 3 9 9 ]) ĊĠĠĠ Ġfun ĠgetUrl _ returns Content For Successful Requests ( ĊĠĠĠĠĠĠĠ ĠstatusCode : ĠInt ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Response ( uri Path , Ġ" test Ġresponse ", ĠstatusCode ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcut . getUrl ( timer , Ġuri , Ġ"") ĊĠĠĠĠĠĠĠ ĠassertThat ( response ). isEqualTo (" test Ġresponse ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Parameterized Test ĊĠĠĠ Ġ@ Value Source ( ints Ġ= Ġ[ 4 0 0 , Ġ 4 0 1 , Ġ 4 0 3 , Ġ 4 0 4 , Ġ 4 1 0 , Ġ 5 0 0 , Ġ 5 0 3 ]) ĊĠĠĠ Ġfun ĠgetUrl _ throws Exception If Getting Error StatusCode ( ĊĠĠĠĠĠĠĠ ĠstatusCode : ĠInt ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Response ( uri Path , Ġ"", ĠstatusCode ) ĊĠĠĠĠĠĠĠ Ġval Ġe Ġ= ĠThrowable Assert . catch Throwable OfType ({ Ġcut . getUrl ( timer , Ġuri , Ġ"") Ġ}, ĠRequest Exception :: class . java ) ĊĠĠĠĠĠĠĠ ĠassertThat ( e ). has Message Containing ( uri Path ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetUrl _ sets Default Headers () Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Response ( uri Path , Ġ"", Ġ 2 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġcut . getUrl ( timer , Ġuri ) ĊĊĠĠĠĠĠĠĠ ĠWire Mock . verify ( Wire Mock . get Requested For ( Wire Mock . url EqualTo ( uri Path )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Header (" Accept ", ĠWire Mock . equalTo (" application / json ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Header (" User - Agent ", ĠWire Mock . matching (". + "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetUrl _ sets Custom Accept Header () Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Response ( uri Path , Ġ"", Ġ 2 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġcut . getUrl ( timer , Ġuri , Ġ" some / accept ") ĊĊĠĠĠĠĠĠĠ ĠWire Mock . verify ( Wire Mock . get Requested For ( Wire Mock . url EqualTo ( uri Path )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Header (" Accept ", ĠWire Mock . equalTo (" some / accept "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetUrl _ sets Additional Headers () Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Response ( uri Path , Ġ"", Ġ 2 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġcut . getUrl ( timer , Ġuri , Ġadditional Headers Ġ= ĠlistOf (" A ", Ġ" a ", Ġ" B ", Ġ" b ")) ĊĊĠĠĠĠĠĠĠ ĠWire Mock . verify ( Wire Mock . get Requested For ( Wire Mock . url EqualTo ( uri Path )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Header (" A ", ĠWire Mock . equalTo (" a ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Header (" B ", ĠWire Mock . equalTo (" b "))) ĊĠĠĠ Ġ} Ċ } Ċ