/* Ċ Ġ* ĠL am bl in Ċ Ġ* ĠCopyright Ġ 2 0 1 8 ĠBor isl av ĠShe ker ov Ċ Ġ* ĠLicensed Ġunder ĠApache Ġ 2 . 0 : Ġhttps :// github . com / Bor isl av She ker ov / lam bl in / blob / master / LICENSE Ċ Ġ*/ Ċ Ċ package Ġcore Ċ Ċ import Ġcom . lam bl in . core . Controller Registry Ċ import Ġcom . lam bl in . core . L am bl in Ċ import Ġcom . lam bl in . core . handler . Handler Method Factory Ċ import Ġcom . lam bl in . core . model . Handler Method Ċ import Ġcom . lam bl in . core . model . HttpMethod Ċ import Ġcom . lam bl in . core . model . HttpResponse Ċ import Ġcom . lam bl in . core . model . annotation . Controller Ċ import Ġcom . lam bl in . core . model . annotation . Endpoint Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġkotlin . reflect . K Callable Ċ Ċ const Ġval ĠPATH _ GET _ 1 Ġ= Ġ" path _ get _ 1 " Ċ const Ġval ĠPATH _ POST _ 1 Ġ= Ġ" path _ post _ 1 " Ċ const Ġval ĠPATH _ GET _ 2 Ġ= Ġ" path _ get _ 2 " Ċ const Ġval ĠPATH _ POST _ 2 Ġ= Ġ" path _ post _ 2 " Ċ Ċ class ĠL am bl in Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġget Handler Method : ĠHandler Method Ġ= Ġmock k () ĊĠĠĠ Ġprivate Ġval Ġpost Handler Method : ĠHandler Method Ġ= Ġmock k () ĊĠĠĠ Ġprivate Ġval Ġget Handler Method 2 : ĠHandler Method Ġ= Ġmock k () ĊĠĠĠ Ġprivate Ġval Ġpost Handler Method 2 : ĠHandler Method Ġ= Ġmock k () ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġget Handler Method . http Method Ġ} Ġreturns ĠHttpMethod . GET ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpost Handler Method . http Method Ġ} Ġreturns ĠHttpMethod . POST ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġget Handler Method 2 . http Method Ġ} Ġreturns ĠHttpMethod . GET ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpost Handler Method 2 . http Method Ġ} Ġreturns ĠHttpMethod . POST ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` comp anion Ġshould Ġcreate Ġa Ġvalid Ġinstance `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinstance Ġ= ĠL am bl in . front Controller ( Test Controller With Endpoints 1 ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( instance ). isNotNull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġcreate Ġhandler Ġmethods Ġfor Ġall Ġendpoints Ġin Ġcontrollers `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Method Factory : ĠHandler Method Factory Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġval Ġcontroller Registry : ĠController Registry Ġ= Ġmock k () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ get " Ġ} !! Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġget Handler Method ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ post " Ġ} Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġpost Handler Method ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġcontroller Registry . controller Classes () Ġ} Ġreturns ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlam bl in Ġ= ĠL am bl in ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontroller Registry , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue )) ĊĊĠĠĠĠĠĠĠ Ġval Ġhttp Method To Method Handlers Ġ= Ġlam bl in . create HttpMethod To Path To Handler Method Map () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers ). has Size ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers [ HttpMethod . GET ]). has Size ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers [ HttpMethod . POST ]). has Size ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġcreate Ġhandler Ġmethods Ġfor Ġall Ġendpoints Ġin Ġmultiple Ġcontroller `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Method Factory : ĠHandler Method Factory Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġval Ġcontroller Registry : ĠController Registry Ġ= Ġmock k () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ get " Ġ} Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġget Handler Method ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ post " Ġ} Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġpost Handler Method ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 2 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ get " Ġ} Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 2 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġget Handler Method 2 ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory . method ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 2 :: class . members . find Ġ{ Ġit . name Ġ== Ġ" endpoint _ post " Ġ} Ġas ĠK Callable < HttpResponse <* >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 2 :: class ) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġpost Handler Method 2 ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġcontroller Registry . controller Classes () Ġ} Ġreturns ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 1 :: class , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller With Endpoints 2 :: class ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlam bl in Ġ= ĠL am bl in ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandler Method Factory , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontroller Registry , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue )) ĊĊĠĠĠĠĠĠĠ Ġval Ġhttp Method To Method Handlers Ġ= Ġlam bl in . create HttpMethod To Path To Handler Method Map () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers ). has Size ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers [ HttpMethod . GET ]). has Size ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers [ HttpMethod . POST ]). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġnot Ġcreate Ġhandler Ġmethods Ġif Ġno Ġendpoints Ġin Ġcontroller `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontroller Registry : ĠController Registry Ġ= Ġmock k () ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġcontroller Registry . controller Classes () Ġ} Ġreturns ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Controller No Endpoints :: class ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlam bl in Ġ= ĠL am bl in ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontroller Registry , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue )) ĊĊĠĠĠĠĠĠĠ Ġval Ġhttp Method To Method Handlers Ġ= Ġlam bl in . create HttpMethod To Path To Handler Method Map () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( http Method To Method Handlers ). has Size ( 0 ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Controller Ċ class ĠTest Controller With Endpoints 1 Ġ{ ĊĊĠĠĠ Ġ@ Endpoint ( PATH _ GET _ 1 , Ġmethod Ġ= ĠHttpMethod . GET ) ĊĠĠĠ Ġfun Ġendpoint _ get () Ġ{ ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Endpoint ( PATH _ POST _ 1 , Ġmethod Ġ= ĠHttpMethod . POST ) ĊĠĠĠ Ġfun Ġendpoint _ post () Ġ{ ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ @ Controller Ċ class ĠTest Controller With Endpoints 2 Ġ{ ĊĊĠĠĠ Ġ@ Endpoint ( PATH _ GET _ 2 , Ġmethod Ġ= ĠHttpMethod . GET ) ĊĠĠĠ Ġfun Ġendpoint _ get () Ġ{ ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Endpoint ( PATH _ POST _ 2 , Ġmethod Ġ= ĠHttpMethod . POST ) ĊĠĠĠ Ġfun Ġendpoint _ post () Ġ{ ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠTest Controller No Endpoints Ċ