package Ġorg . http 4 k . routing Ċ Ċ import Ġcom . nat pr y ce . ham k rest . assertion . assertThat Ċ import Ġcom . nat pr y ce . ham k rest . is A Ċ import Ġorg . http 4 k . core . Body Ċ import Ġorg . http 4 k . core . Method . GET Ċ import Ġorg . http 4 k . core . Method . POST Ċ import Ġorg . http 4 k . core . Request Ċ import Ġorg . http 4 k . core . Response Ċ import Ġorg . http 4 k . core . Status Ċ import Ġorg . http 4 k . core . Status . Companion . OK Ċ import Ġorg . http 4 k . lens . Query Ċ import Ġorg . http 4 k . lens . int Ċ import Ġorg . http 4 k . lens . matches Ċ import Ġorg . http 4 k . routing . Router Match . Matched Without Handler Ċ import Ġorg . http 4 k . routing . Router Match . Matching Handler Ċ import Ġorg . http 4 k . routing . Router Match . Method Not Matched Ċ import Ġorg . http 4 k . routing . Router Match . Un matched Ċ import Ġorg . junit . jupiter . api . Disabled Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ class ĠRouter Matching Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` lens Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= ĠQuery . int (). required (" foo "). matches Ġ{ Ġit Ġ> Ġ 5 Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 6 ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 5 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" bar ")), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` headers Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġheaders (" foo ", Ġ" bar ") ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 "). header (" bar ", Ġ" 2 ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" bar ", Ġ" 2 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo 2 ", Ġ" 5 ")), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` header Ġpredicate Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġheader (" foo ") Ġ{ Ġit Ġ== Ġ" bar " Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 "). header (" foo ", Ġ" bar ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` header Ġvalue Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġheader (" foo ", Ġ" bar ") ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 "). header (" foo ", Ġ" bar ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` query Ġpredicate Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġquery (" foo ") Ġ{ Ġit Ġ== Ġ" bar " Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 "). query (" foo ", Ġ" bar ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` query Ġvalue Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġquery (" foo ", Ġ" bar ") ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 "). query (" foo ", Ġ" bar ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` queries Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter : ĠRouter Ġ= Ġqueries (" foo ", Ġ" bar ") ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 "). query (" bar ", Ġ" 2 ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo ", Ġ" 1 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" bar ", Ġ" 2 ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" foo 2 ", Ġ" 5 ")), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` generic Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= Ġ{ Ġr : ĠRequest Ġ-> Ġr . method Ġ== ĠGET Ġ}. as Router () ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` method Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= ĠGET . as Router () ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ"") ), Ġis A < Method Not Matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fallback Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( Fallback . match ( Request ( GET , Ġ"") ), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( Fallback . match ( Request ( POST , Ġ"") ), Ġis A < Matched Without Handler >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` body Ġstring Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= Ġbody Ġ{ Ġit : ĠString Ġ-> Ġit Ġ== Ġ" hello " Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). body (" anything ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). body (" hello ")), Ġis A < Matched Without Handler >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` body Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= Ġbody Ġ{ Ġit : ĠBody Ġ-> Ġit . length ?. toInt () Ġ== Ġ 3 Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). body (" anything ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). body (" foo ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). body (" bar ")), Ġis A < Matched Without Handler >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` composite Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= ĠGET . and ( header (" foo ", Ġ" bar "). and ( query (" bar ", Ġ" foo "))) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" bar "). query (" bar ", Ġ" foo ")), Ġis A < Matched Without Handler >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( POST , Ġ""). header (" foo ", Ġ" bar "). query (" bar ", Ġ" foo ")), Ġis A < Method Not Matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" bar ")), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). query (" bar ", Ġ" foo ")), Ġis A < Un matched >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` composite Ġrouter Ġwith Ġa Ġbound Ġrouter `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrouter Ġ= ĠGET . bind Ġ{ ĠResponse ( OK ) Ġ}. and ( header (" foo ", Ġ" bar ")) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ"") ), Ġis A < Un matched >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( router . match ( Request ( GET , Ġ""). header (" foo ", Ġ" bar ")), Ġis A < Matching Handler >()) ĊĠĠĠ Ġ} Ċ } Ċ