package Ġsoftware . amazon . global accel erator . listener Ċ Ċ import Ġcom . amazonaws . services . global accel erator . model . Listener Ċ import Ġcom . amazonaws . services . global accel erator . model . List Listeners Request Ċ import Ġcom . amazonaws . services . global accel erator . model . List Listeners Result Ċ import Ġcom . amazonaws . services . global accel erator . model . Protocol Ċ import Ġio . mock k . Mock K Annotations Ċ import Ġio . mock k . every Ċ import Ġio . mock k . slot Ċ import Ġio . mock k . impl . annotations . Mock K Ċ import Ġio . mock k . junit 5 . Mock K Extension Ċ import Ġorg . junit . jupiter . api . Assertions . assertEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertNotNull Ċ import Ġorg . junit . jupiter . api . Assertions . assertNull Ċ import Ġorg . junit . jupiter . api . Assertions . assertTrue Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġsoftware . amazon . cloudformation . proxy . Amazon Web Services Client Proxy Ċ import Ġsoftware . amazon . cloudformation . proxy . Handler ErrorCode Ċ import Ġsoftware . amazon . cloudformation . proxy . Logger Ċ import Ġsoftware . amazon . cloudformation . proxy . Operation Status Ċ import Ġsoftware . amazon . cloudformation . proxy . Resource Handler Request Ċ Ċ @ Extend With ( Mock K Extension :: class ) Ċ class ĠList Handler Test Ġ{ ĊĠĠĠ Ġ@ Mock K ĊĠĠĠ Ġlateinit Ġvar Ġproxy : ĠAmazon Web Services Client Proxy ĊĊĠĠĠ Ġ@ Mock K ( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġlateinit Ġvar Ġlogger : ĠLogger ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ= ĠMock K Annotations . init ( this ) ĊĊĠĠĠ Ġprivate Ġval Ġaccel erator Arn Ġ= Ġ" arn : aws : global accel erator :: 4 4 4 6 0 7 8 7 2 1 8 4 : accel erator / 8 8 1 2 7 aa 5 - 0 1 d 8 - 4 8 4 c - 8 0 a 0 - 3 4 9 daa ef ce 1 d " ĊĠĠĠ Ġprivate Ġval Ġlistener Arn 1 Ġ= Ġ" arn : aws : global accel erator :: 4 4 4 6 0 7 8 7 2 1 8 4 : accel erator / 8 8 1 2 7 aa 5 - 0 1 d 8 - 4 8 4 c - 8 0 a 0 - 3 4 9 daa ef ce 1 d / listener / ee 7 3 5 8 c 2 " ĊĠĠĠ Ġprivate Ġval Ġfrom Port 1 Ġ= Ġ 9 0 9 0 ĊĠĠĠ Ġprivate Ġval Ġto Port 1 Ġ= Ġ 9 0 9 9 ĊĠĠĠ Ġprivate Ġval Ġprotocol 1 Ġ= Ġ" TCP " ĊĠĠĠ Ġprivate Ġval Ġclient Affinity 1 Ġ= Ġ" NONE " ĊĠĠĠ Ġprivate Ġval Ġlistener Arn 2 Ġ= Ġ" arn : aws : global accel erator :: 4 4 4 6 0 7 8 7 2 1 8 4 : accel erator / 8 8 1 2 7 aa 5 - 0 1 d 8 - 4 8 4 c - 8 0 a 0 - 3 4 9 daa ef ce 1 d / listener / ee 8 6 7 5 c 2 " ĊĠĠĠ Ġprivate Ġval Ġfrom Port 2 Ġ= Ġ 4 2 4 2 ĊĠĠĠ Ġprivate Ġval Ġto Port 2 Ġ= Ġ 4 2 4 3 ĊĠĠĠ Ġprivate Ġval Ġprotocol 2 Ġ= Ġ" UDP " ĊĠĠĠ Ġprivate Ġval Ġclient Affinity 2 Ġ= Ġ" SOURCE _ IP " ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Test Resource Model ( arn : ĠString , Ġfrom Port : ĠInt , Ġto Port : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprotocol : ĠString , Ġclient Affinity : ĠString ): ĠResource Model Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠResource Model . builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. listener Arn ( arn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. accel erator Arn ( accel erator Arn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. port Ranges ( listOf ( Port Range ( from Port , Ġto Port ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. protocol ( protocol ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. client Affinity ( client Affinity ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġhandle Request _ returns Mapped Listeners () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel 1 Ġ= Ġcreate Test Resource Model ( listener Arn 1 , Ġfrom Port 1 , Ġto Port 1 , Ġprotocol 1 , Ġclient Affinity 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġmodel 2 Ġ= Ġcreate Test Resource Model ( listener Arn 2 , Ġfrom Port 2 , Ġto Port 2 , Ġprotocol 2 , Ġclient Affinity 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlisteners Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠListener () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Listener Arn ( listener Arn 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Port Ranges ( listOf ( com . amazonaws . services . global accel erator . model . Port Range (). with From Port ( from Port 1 ). with To Port ( to Port 1 ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Protocol ( protocol 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Client Affinity ( client Affinity 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠListener () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Listener Arn ( listener Arn 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Port Ranges ( listOf ( com . amazonaws . services . global accel erator . model . Port Range (). with From Port ( from Port 2 ). with To Port ( to Port 2 ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Protocol ( protocol 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Client Affinity ( client Affinity 2 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlist Listeners Result Ġ= ĠList Listeners Result (). with Listeners ( listeners ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġproxy . inject Credentials And Invoke ( of Type (), Ġof Type < Proxy List Listeners >()) Ġ} Ġreturns Ġlist Listeners Result ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠResource Handler Request . builder < Resource Model >(). desired Resource State ( model 1 ). build () ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠList Handler (). handle Request ( proxy , Ġrequest , Ġnull , Ġlogger ) ĊĊĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Operation Status . SUCCESS , Ġresponse . status ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . callback Context ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . resource Model ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . message ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( response . resource Models ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . nextToken ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġresponse . resource Models . size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( accel erator Arn , Ġresponse . resource Models [ 0 ]. accel erator Arn ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 1 . listener Arn , Ġresponse . resource Models [ 0 ]. listener Arn ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġresponse . resource Models [ 0 ]. port Ranges . size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 1 . port Ranges [ 0 ]. from Port , Ġresponse . resource Models [ 0 ]. port Ranges [ 0 ]. from Port ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 1 . port Ranges [ 0 ]. to Port , Ġresponse . resource Models [ 0 ]. port Ranges [ 0 ]. to Port ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 1 . protocol , Ġresponse . resource Models [ 0 ]. protocol ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 1 . client Affinity , Ġresponse . resource Models [ 0 ]. client Affinity ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( accel erator Arn , Ġresponse . resource Models [ 1 ]. accel erator Arn ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 2 . listener Arn , Ġresponse . resource Models [ 1 ]. listener Arn ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġresponse . resource Models [ 1 ]. port Ranges . size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 2 . port Ranges [ 0 ]. from Port , Ġresponse . resource Models [ 1 ]. port Ranges [ 0 ]. from Port ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 2 . port Ranges [ 0 ]. to Port , Ġresponse . resource Models [ 1 ]. port Ranges [ 0 ]. to Port ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 2 . protocol , Ġresponse . resource Models [ 1 ]. protocol ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( model 2 . client Affinity , Ġresponse . resource Models [ 1 ]. client Affinity ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġhandle Request _ no Listeners () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Test Resource Model ( listener Arn 1 , Ġfrom Port 1 , Ġto Port 1 , Ġprotocol 1 , Ġclient Affinity 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlist Listeners Result Ġ= ĠList Listeners Result (). with Listeners ( emptyList ()) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġproxy . inject Credentials And Invoke ( of Type (), Ġof Type < Proxy List Listeners >()) Ġ} Ġreturns Ġlist Listeners Result ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠResource Handler Request . builder < Resource Model >(). desired Resource State ( model ). build () ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠList Handler (). handle Request ( proxy , Ġrequest , Ġnull , Ġlogger ) ĊĊĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Operation Status . SUCCESS , Ġresponse . status ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( response . resource Models ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġresponse . resource Models . size ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . nextToken ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġhandle Request _ returns Mapped Listeners With Token () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsent NextToken Ġ= Ġ" next _ token " ĊĠĠĠĠĠĠĠ Ġval Ġexpected NextToken Ġ= Ġ" This _ token _ is _ expected " ĊĊĠĠĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Test Resource Model ( listener Arn 1 , Ġfrom Port 1 , Ġto Port 1 , Ġprotocol 1 , Ġclient Affinity 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġlisteners Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠListener () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Listener Arn ( listener Arn 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Port Ranges ( listOf ( com . amazonaws . services . global accel erator . model . Port Range (). with From Port ( from Port 1 ). with To Port ( to Port 1 ))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Protocol ( protocol 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Client Affinity ( client Affinity 1 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlist Listeners Request Slot Ġ= Ġslot < List Listeners Request >() ĊĠĠĠĠĠĠĠ Ġval Ġlist Listeners Result Ġ= ĠList Listeners Result () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Listeners ( listeners ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with NextToken ( expected NextToken ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġproxy . inject Credentials And Invoke ( capture ( list Listeners Request Slot ), Ġof Type < Proxy List Listeners >()) Ġ} Ġreturns Ġlist Listeners Result ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠResource Handler Request . builder < Resource Model >(). desired Resource State ( model ). nextToken ( sent NextToken ). build () ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠList Handler (). handle Request ( proxy , Ġrequest , Ġnull , Ġlogger ) ĊĊĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Operation Status . SUCCESS , Ġresponse . status ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( sent NextToken , Ġlist Listeners Request Slot . captured . nextToken ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . callback Context ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . resource Model ) ĊĠĠĠĠĠĠĠ ĠassertNull ( response . message ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( response . resource Models ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( response . nextToken ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected NextToken , Ġresponse . nextToken ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġresponse . resource Models . size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listener Arn 1 , Ġresponse . resource Models [ 0 ]. listener Arn ) ĊĠĠĠ Ġ} Ċ } Ċ