package Ġtest . apis Ċ Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġs late kit . apis . Api Server Ċ import Ġs late kit . apis . Verb Ċ import Ġs late kit . apis . routes . Api Ċ import Ġs late kit . apis . Setup Type Ċ import Ġs late kit . context . AppContext Ċ import Ġs late kit . common . data . Vendor Ċ import Ġs late kit . entities . Entity Long Id Ċ import Ġs late kit . entities . Entity Service Ċ import Ġs late kit . entities . Entity Services Ċ import Ġs late kit . integration . apis . Info Api Ċ import Ġs late kit . integration . apis . Version Api Ċ // import Ġs late kit . orm . orm Ċ import Ġs late kit . results . getOrElse Ċ import Ġtest . Test App Ċ import Ġtest . setup .* ĊĊ Ċ class ĠApi _ Setup _ Tests Ġ: ĠApi Tests Base () Ġ{ ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ as _ new () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġap is . get (" app ", Ġ" Sample PO KO ", Ġ" getTime " Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġapi Ref Ġ= Ġresult . getOrElse Ġ{ Ġnull Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success Ġ&& Ġapi Ref ?. instance Ġis ĠSample PO KO Api ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (( api Ref ?. instance Ġas ĠSample PO KO Api ). count Ġ== Ġ 0 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ as _ new _ with _ context () Ġ{ ĊĠĠĠĠĠĠĠ Ġctx . ent . register < Long , ĠMovie >( Entity Long Id () Ġ, Ġvendor Ġ= ĠVendor . Memory ) Ġ{ Ġrepo Ġ-> ĠEntity Service ( repo ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample Entity Api :: class , Ġ" app ", Ġ" Sample Entity "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġap is . get (" app ", Ġ" Sample Entity ", Ġ" patch " Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġapi Ref Ġ= Ġresult . getOrElse Ġ{ Ġnull Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success Ġ&& Ġapi Ref ?. instance Ġis ĠSample Entity Api ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ as _ singleton () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinst Ġ= ĠSample PO KO Api () ĊĠĠĠĠĠĠĠ Ġinst . count Ġ= Ġ 1 0 0 1 ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( inst , Ġ" app ", Ġ" Sample PO KO "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġap is . get (" app ", Ġ" Sample PO KO ", Ġ" getTime " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġapi Ref Ġ= Ġresult . getOrElse Ġ{ Ġnull Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success Ġ&& Ġapi Ref ?. instance Ġis ĠSample PO KO Api ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (( api Ref ?. instance Ġas ĠSample PO KO Api ). count Ġ== Ġ 1 0 0 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ with _ declared _ members _ only () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" getTime " ĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" get Counter " Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" hello " ĠĠĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" request " ĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" response " ĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" getEmail " ĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . get (" app " ĠĠ Ġ, Ġ" Sample PO KO ", Ġ" getS sn " ĠĠĠĠ Ġ). success ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ with _ inheritance () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample Extended Api :: class , Ġ" app ", Ġ" Sample Extended ", Ġdeclared Only Ġ= Ġfalse ))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" get Seconds " Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" getTime " ĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" get Counter " Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" hello " ĠĠĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" request " ĠĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" response " ĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" getEmail " ĠĠ Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . get (" app " ĠĠ Ġ, Ġ" Sample Extended ", Ġ" getS sn " ĠĠĠĠ Ġ). success ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ setup _ instance _ with _ composition al _ apis _ with _ annotations () Ġ{ ĊĠĠĠĠĠĠĠ Ġctx . ent . register < Long , ĠMovie >( Entity Long Id () Ġ, Ġvendor Ġ= ĠVendor . Memory ) Ġ{ Ġrepo Ġ-> ĠEntity Services ( repo ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample Entity 2 Api :: class , Ġdeclared Only Ġ= Ġfalse , Ġsetup Ġ= ĠSetup Type . Annotated ))) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" tests ", Ġ" patch " Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" tests ", Ġ" recent " Ġ). success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġap is . get (" app " ĠĠ Ġ, Ġ" tests ", Ġ" ol dest " Ġ). success ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ check _ action _ does _ NOT _ exist () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Info Api ( ctx ), Ġsetup Ġ= ĠSetup Type . Annotated ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Version Api ( ctx ), Ġsetup Ġ= ĠSetup Type . Annotated ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . routes . contains (" app . Sample PO KO . fake Method ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (! apis . routes . contains (" sys . app . host 2 ")) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ check _ action _ exists () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Info Api ( ctx ), Ġsetup Ġ= ĠSetup Type . Annotated ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApi ( Version Api ( ctx ), Ġsetup Ġ= ĠSetup Type . Annotated ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( apis . routes . check (" app . Sample PO KO . get Counter ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( apis . routes . check (" app . info . about ")) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ call _ action _ without _ area () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrun Blocking Ġ{ Ġ Ġap is . execute Attempt (" app ", Ġ" Sample PO KO ", Ġ" get Counter ", ĠVerb . Get , Ġmap Of (), Ġmap Of ()) Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . getOrElse Ġ{ Ġ 0 Ġ} Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ call _ action _ with _ request () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample PO KO Api :: class , Ġ" app ", Ġ" Sample PO KO "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġap is . execute Attempt (" app ", Ġ" Sample PO KO ", ĠSample PO KO Api :: request . name , ĠVerb . Post , Ġmap Of (), Ġmap Of (" greeting " Ġto Ġ" hi ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ call _ action _ in _ derived _ class () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample Extended Api :: class , Ġ" app ", Ġ" Sample Extended "))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrun Blocking Ġ{ Ġap is . execute Attempt (" app ", Ġ" Sample Extended ", Ġ" get Seconds ", ĠVerb . Get , Ġmap Of (), Ġmap Of ()) Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . getOrElse Ġ{ Ġ- 1 Ġ} Ġin Ġ 0 .. 5 9 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġcan _ call _ action _ in _ base _ class () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( Sample Extended Api :: class , Ġ" app ", Ġ" Sample Extended ", Ġdeclared Only Ġ= Ġfalse ))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrun Blocking Ġ{ Ġap is . execute Attempt (" app ", Ġ" Sample Extended ", Ġ" get Counter ", ĠVerb . Get , Ġmap Of (), Ġmap Of ()) Ġ} ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . success ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( result . getOrElse Ġ{ Ġ 0 Ġ} Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan _ get _ api _ info _ from _ method () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġctx Ġ= ĠApp Context . simple ( Test App :: class . java ," queues ") ĊĠĠĠĠĠĠĠ Ġval Ġapi Ġ= ĠWorker Sample Api ( ctx ) ĊĠĠĠĠĠĠĠ Ġval Ġap is Ġ= ĠApi Server ( ctx , Ġap is Ġ= ĠlistOf ( Api ( api , Ġsetup Ġ= ĠSetup Type . Annotated )) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġapi Ref Ġ= Ġap is . get ( Worker Sample Api :: class , ĠWorker Sample Api :: test 1 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġapi Ref . getOrElse Ġ{ Ġnull Ġ} ?. api ?. area Ġ== Ġ" samples ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġapi Ref . getOrElse Ġ{ Ġnull Ġ} ?. api ?. name Ġ== Ġ" worker queue ") ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( Ġapi Ref . getOrElse Ġ{ Ġnull Ġ} ?. action ?. name Ġ== Ġ" test 1 ") ĊĠĠĠ Ġ} Ċ } Ċ