package Ġk lite Ċ Ċ import Ġch . tut tel i . at rium . api . fluent . en _ GB . toEqual Ċ import Ġch . tut tel i . at rium . api . ver bs . expect Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . verify Ċ import Ġk lite . Cookie . Same Site . Strict Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġjava . net . URI Ċ Ċ class ĠHttp Exchange Test Ġ{ ĊĠ Ġabstract Ġclass ĠMock able Http Exchange : ĠOriginal Http Exchange () ĊĠ Ġval Ġoriginal Ġ= Ġmock k < Mock able Http Exchange >( relax ed Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġrequest Method Ġ} Ġreturns Ġ" GET " ĊĠĠĠ Ġevery Ġ{ Ġrequest URI Ġ} Ġreturns ĠURI ("/ hello ? hello = world ") ĊĠĠĠ Ġevery Ġ{ Ġresponse Code Ġ} Ġreturns Ġ- 1 ĊĠ Ġ} ĊĠ Ġval Ġbody Renderer Ġ= Ġmock k < Body Renderer >() ĊĠ Ġval Ġcustom Parser Ġ= Ġmock k < Body Parser > Ġ{ ĊĠĠĠ Ġevery Ġ{ ĠcontentType Ġ} Ġreturns Ġ" application / specific " ĊĠ Ġ} ĊĠ Ġval Ġrouter Config Ġ= Ġmock k < Router Config > Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġparsers Ġ} Ġreturns Ġmutable ListOf ( Text Body Parser (), Ġcustom Parser ) ĊĠĠĠ Ġevery Ġ{ Ġrender ers Ġ} Ġreturns Ġmutable ListOf ( body Renderer ) ĊĠ Ġ} ĊĠ Ġval Ġexchange Ġ= ĠHttp Exchange ( original , Ġrouter Config , Ġnull , Ġ" req - id ") ĊĊĠ Ġ@ Test Ġfun Ġpath () Ġ{ ĊĠĠĠ Ġexpect ( exchange . method ). toEqual ( Request Method . GET ) ĊĠĠĠ Ġexpect ( exchange . path ). toEqual ("/ hello ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun ĠqueryParams () Ġ{ ĊĠĠĠ Ġexpect ( exchange . query ). toEqual (" ? hello = world ") ĊĠĠĠ Ġexpect ( exchange . queryParams ). toEqual ( map Of (" hello " Ġto Ġ" world ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġfull Url () Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġexchange . host Ġ} Ġreturns Ġ" localhost : 8 0 8 0 " ĊĠĠĠ Ġexpect ( exchange . full Url ). toEqual ( URI (" http :// localhost : 8 0 8 0 / hello ? hello = world ")) ĊĊĠĠĠ Ġevery Ġ{ Ġexchange . host Ġ} Ġreturns Ġ" host . domain " ĊĠĠĠ Ġexpect ( exchange . full Url ("/ some / page ")). toEqual ( URI (" http :// host . domain / some / page ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` request Ġcookies `() Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġexchange . header (" Cookie ") Ġ} Ġreturns Ġ" Hello = World ; ĠSecond = 1 2 3 % 2 0 4 5 6 " ĊĠĠĠ Ġexpect ( exchange . cookies ). toEqual ( map Of (" Hello " Ġto Ġ" World ", Ġ" Second " Ġto Ġ" 1 2 3 Ġ 4 5 6 ")) ĊĠĠĠ Ġexpect ( exchange . cookie (" Hello ")). toEqual (" World ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` response Ġcookies `() Ġ{ ĊĠĠĠ Ġexchange . cookie (" Hello ", Ġ" World ") ĊĠĠĠ Ġverify Ġ{ Ġoriginal . response Headers . add (" Set - Cookie ", Ġ" Hello = World ") Ġ} ĊĊĠĠĠ Ġexchange Ġ+= ĠCookie (" LANG ", Ġ" et ", Ġsame Site Ġ= ĠStrict , Ġdomain Ġ= Ġ" ang ry ip . org ") ĊĠĠĠ Ġverify Ġ{ Ġoriginal . response Headers . add (" Set - Cookie ", Ġ" LANG = et ; ĠDomain = ang ry ip . org ; ĠSame Site = Strict ") Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` body Ġas Ġtext `() Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġexchange . request Type Ġ} Ġreturns Ġnull ĊĠĠĠ Ġevery Ġ{ Ġoriginal . request Body Ġ} Ġanswers Ġ{ Ġ" 1 2 3 ". byte InputStream () Ġ} ĊĠĠĠ Ġexpect ( exchange . body < String > ()). toEqual (" 1 2 3 ") ĊĠĠĠ Ġexpect ( exchange . body < Int > ()). toEqual ( 1 2 3 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` body Ġwith Ġspecific Ġcontent - type `() Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġexchange . request Type Ġ} Ġreturns Ġcustom Parser . contentType ĊĠĠĠ Ġval Ġinput Ġ= Ġ"{ PI }". byte InputStream () ĊĠĠĠ Ġevery Ġ{ Ġoriginal . request Body Ġ} Ġanswers Ġ{ Ġinput Ġ} ĊĠĠĠ Ġevery Ġ{ Ġcustom Parser . parse ( input , ĠDouble :: class ) Ġ} Ġreturns ĠMath . PI ĊĠĠĠ Ġexpect ( exchange . body < Double > ()). toEqual ( Math . PI ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` body Ġwith Ġunsupported Ġcontent - type `() Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġexchange . request Type Ġ} Ġreturns Ġ" unsupported " ĊĠĠĠ Ġevery Ġ{ Ġoriginal . request Body Ġ} Ġreturns Ġ"". byte InputStream () ĊĠĠĠ ĠassertThrows < Unsupported MediaType Exception > Ġ{ Ġexchange . body < String >() Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` send Ġtext `() Ġ{ ĊĠĠĠ Ġexchange . send ( StatusCode . OK , Ġ" Hello ", Ġ" text / custom ") ĊĠĠĠ Ġverify Ġ{ ĊĠĠĠĠĠ Ġoriginal . response Headers [" Content - Type "] Ġ= Ġ" text / custom ; Ġcharset = UTF - 8 " ĊĠĠĠĠĠ Ġoriginal . send Response Headers ( 2 0 0 , Ġ 5 ) ĊĠĠĠĠĠ Ġoriginal . response Body . write (" Hello ". toByteArray ()) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` send Ġbinary `() Ġ{ ĊĠĠĠ Ġexchange . send ( StatusCode . Created , Ġ" XXX ". toByteArray (), Ġ" image / custom ") ĊĠĠĠ Ġverify Ġ{ ĊĠĠĠĠĠ Ġoriginal . response Headers [" Content - Type "] Ġ= Ġ" image / custom " ĊĠĠĠĠĠ Ġoriginal . send Response Headers ( 2 0 1 , Ġ 3 ) ĊĠĠĠĠĠ Ġoriginal . response Body . write (" XXX ". toByteArray ()) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun ĠonComplete () Ġ{ ĊĠĠĠ Ġval Ġhandler 1 Ġ= Ġmock k < Runnable >( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġval Ġhandler 2 Ġ= Ġmock k < Runnable >( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġexchange . onComplete ( handler 1 ) ĊĠĠĠ Ġexchange . onComplete ( handler 2 ) ĊĊĠĠĠ Ġexchange . close () ĊĊĠĠĠ Ġverify Ġ{ ĊĠĠĠĠĠ Ġoriginal . close () ĊĠĠĠĠĠ Ġhandler 1 . run () ĊĠĠĠĠĠ Ġhandler 2 . run () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ