/** Ċ < s late _ header > Ċ url : Ġwww . s late kit . com Ċ git : Ġwww . github . com / code - helix / s late kit Ċ org : Ġwww . code helix . co Ċ author : ĠK ish ore ĠRed dy Ċ copyright : Ġ 2 0 1 6 ĠCode Hel ix ĠSolutions ĠInc . Ċ license : Ġrefer Ġto Ġwebsite Ġand / or Ġgithub Ċ about : ĠA ĠKotlin Ġutility Ġlibrary , Ġtool - kit Ġand Ġserver Ġbackend . Ċ man tra : ĠSimp licity Ġabove Ġall Ġelse Ċ </ s late _ header > Ċ Ġ*/ Ċ package Ġtest . apis Ċ Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġs late kit . apis .* Ċ import Ġs late kit . apis . routes . Api Ċ import Ġs late kit . apis . core . Sources Ċ import Ġs late kit . apis . routes . Routes Ċ import Ġs late kit . apis . setup . Annotations Ċ import Ġs late kit . apis . setup . Methods Ċ import Ġs late kit . apis . setup . load All Ċ import Ġs late kit . apis . setup . to Api Ċ import Ġs late kit . common . Source Ċ import Ġs late kit . common . auth . Roles Ċ import Ġtest . setup .* Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġk ish orer ed dy Ġon Ġ 6 / 1 2 / 1 7 . Ċ Ġ*/ ĊĊ Ċ class ĠApi _ 0 0 1 _ Loader _ Tests Ġ: ĠApi Tests Base () Ġ{ ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ api _ from _ annotations () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠAn notations ( Sample Anno Api :: class ). api ( null ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . size Ġ== Ġ 1 3 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . area Ġ== Ġ" app ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . name Ġ== Ġ" tests ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . desc Ġ== Ġ" sample Ġto Ġtest Ġfeatures Ġof ĠS late ĠKit ĠAPIs ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . roles . contains (" admin ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . verb Ġ== ĠVerb . Auto ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . protocol Ġ== ĠSource . All ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . items [ 0 ]. name Ġ== Ġ" input Basic Types ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . items [ 0 ]. params . size Ġ== Ġ 8 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . items [ 0 ]. params User . size Ġ== Ġ 8 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ api _ from _ annotations _ with _ defaults () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠAn notations ( Sample Api :: class ). api ( null ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . size Ġ== Ġ 3 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . area Ġ== Ġ" app ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . name Ġ== Ġ" tests ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . desc Ġ== Ġ" sample Ġto Ġtest Ġfeatures Ġof ĠS late ĠKit ĠAPIs ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . roles . contains (" admin ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . verb Ġ== ĠVerb . Auto ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . sources Ġ== ĠS ources ( listOf ( Source . All ))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . access Ġ== ĠAccess . Public ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . protocol Ġ== ĠSource . All ) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Ġ= Ġapi . actions . items . first Ġ{ Ġit . name Ġ== ĠSample Api :: default Annotation Values . name Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . name Ġ== ĠSample Api :: default Annotation Values . name Ġ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . protocol Ġ== Ġapi . protocol ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . verb Ġ== ĠVerb . Post ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . roles Ġ== Ġapi . roles ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params . size Ġ== Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params User . size Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ action _ from _ annotations _ with _ overrides _ partial () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠAn notations ( Sample Api :: class ). api ( null ) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Ġ= Ġapi . actions . items . first Ġ{ Ġit . name Ġ== ĠSample Api :: override Partial . name Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . name Ġ== ĠSample Api :: override Partial . name ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . protocol Ġ== Ġapi . protocol ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . verb Ġ== ĠVerb . Post ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . auth Ġ== ĠAuth Mode . Key ed ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . roles Ġ== Ġs late kit . apis . core . Roles ( listOf (" user "))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . sources Ġ== Ġapi . sources ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . access Ġ== Ġapi . access ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params . size Ġ== Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params User . size Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ action _ from _ annotations _ with _ overrides _ full () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠAn notations ( Sample Api :: class ). api ( null ) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Ġ= Ġapi . actions . items . first Ġ{ Ġit . name Ġ== ĠSample Api :: override Full . name Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . name Ġ== ĠSample Api :: override Full . name ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . protocol Ġ== ĠSource . CLI ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . verb Ġ== ĠVerb . Post ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . auth Ġ== ĠAuth Mode . Key ed ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . roles Ġ== Ġs late kit . apis . core . Roles ( listOf (" user "))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . sources Ġ== ĠS ources ( listOf ( Source . CLI ))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . access Ġ== ĠAccess . Internal ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params . size Ġ== Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( action . params User . size Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ api _ from _ annotations _ verb _ mode _ auto () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠAn notations ( Sample REST Verb Mode Auto Api :: class ). api ( null ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . size Ġ== Ġ 8 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . area Ġ== Ġ" samples ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . name Ġ== Ġ" rest Verb Auto ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . desc Ġ== Ġ" sample Ġapi Ġfor Ġtesting Ġverb Ġmode Ġwith Ġauto ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . roles . contains ( Roles . ALL )) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . verb Ġ== ĠVerb . Auto ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . protocol Ġ== ĠSource . All ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactions Ġ= Ġapi . actions . items . map Ġ{ ĠPair ( it . name , Ġit ) Ġ}. toMap () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Get Ġ Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: getAll . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Get Ġ Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: getById . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Post Ġ Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: create . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Put ĠĠ Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: update . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Patch Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: patch . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Delete , Ġactions [ Sample REST Verb Mode Auto Api :: delete . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Delete , Ġactions [ Sample REST Verb Mode Auto Api :: delete ById . name ] !!. verb ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Verb . Post Ġ Ġ, Ġactions [ Sample REST Verb Mode Auto Api :: activate ById . name ] !!. verb ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠP OK O Ġ: ĠPlain ĠOld ĠKotlin ĠObject ĊĠĠĠĠ Ġ* ĠNo Ġannotations ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ api _ from _ public _ methods () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠMethods ( to Api ( Sample Extended Api :: class , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" app ", Ġ" sample Extended ", Ġ" sample Ġusing Ġplain Ġkotlin Ġclass ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġroles Ġ= Ġs late kit . apis . core . Roles ( listOf (" users ")), Ġlocal Ġ= Ġtrue , Ġauth Ġ= ĠAuth Mode . Token , Ġprotocol Ġ= ĠS ources ( listOf ( Source . All )) )). api ( null ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . size Ġ== Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . area Ġ== Ġ" app ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . name Ġ== Ġ" sample Extended ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . desc Ġ== Ġ" sample Ġusing Ġplain Ġkotlin Ġclass ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . roles . contains (" users ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . verb Ġ== ĠVerb . Auto ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . protocol Ġ== Ġ ĠSource . All ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠP OK O Ġ: ĠPlain ĠOld ĠKotlin ĠObject ĊĠĠĠĠ Ġ* ĠNo Ġannotations ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ api _ from _ public _ methods _ inherited () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠMethods ( to Api ( Sample Extended Api :: class , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" app ", Ġ" sample Extended ", Ġ" sample Ġusing Ġplain Ġkotlin Ġclass ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġroles Ġ= Ġs late kit . apis . core . Roles ( listOf (" users ")), Ġlocal Ġ= Ġfalse , Ġauth Ġ= ĠAuth Mode . Token , Ġprotocol Ġ= ĠS ources ( listOf ( Source . All )) )). api ( null ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . actions . size Ġ== Ġ 8 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . area Ġ== Ġ" app ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . name Ġ== Ġ" sample Extended ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . desc Ġ== Ġ" sample Ġusing Ġplain Ġkotlin Ġclass ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . roles . contains (" users ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . auth Ġ== ĠAuth Mode . Token ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . verb Ġ== ĠVerb . Auto ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( api . protocol Ġ== Ġ ĠSource . All ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠLoad Ġareas ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Test Ġfun Ġcan _ load _ areas () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġareas Ġ= Ġload All ( listOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Sample Roles By App :: class , Ġ" app ", Ġ" sample Roles By App ", Ġ" sample Ġroles Ġby Ġapplication Ġauth ", Ġroles Ġ= Ġs late kit . apis . core . Roles ( listOf (" users ")), Ġauth Ġ= ĠAuth Mode . Token , Ġsources Ġ= ĠS ources ( listOf ( Source . CLI )), Ġdeclared Only Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Sample Roles ByKey :: class , Ġ" app ", Ġ" sample Roles ByKey ", Ġ" sample Ġroles Ġby Ġapi - key ", Ġroles Ġ= Ġs late kit . apis . core . Roles ( listOf (" users ")), Ġauth Ġ= ĠAuth Mode . Key ed , Ġsources Ġ= ĠS ources ( listOf ( Source . CLI )), Ġdeclared Only Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Sample Extended Api :: class , Ġ" tests ", Ġ" sample Extended ", Ġ" sample Ġplain Ġkotlin Ġclass ", Ġroles Ġ= Ġs late kit . apis . core . Roles ( listOf (" users ")), Ġauth Ġ= ĠAuth Mode . Token , Ġsources Ġ= ĠS ources ( listOf ( Source . CLI )), Ġdeclared Only Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( areas . size Ġ== Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( areas . contains (" app ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( areas . contains (" tests ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( areas . get (" app ") ?. apis ?. size Ġ== Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( areas . get (" tests ") ?. apis ?. size Ġ== Ġ 1 ) ĊĠĠĠ Ġ} Ċ } Ċ