// ĠCopyright Ġ 2 0 1 9 ĠAmazon . com , ĠInc . Ġor Ġits Ġaffiliates . ĠAll ĠRights ĠReserved . Ċ // ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ċ package Ġsoftware . aws . tool k its . jetbrains . services . lambda . upload Ċ Ċ import Ġcom . intellij . openapi . application . run Write Action Ċ import Ġcom . intellij . openapi . project Roots . Project J dk Table Ċ import Ġcom . intellij . openapi . roots . Project Root Manager Ċ import Ġcom . intellij . test Framework . Ide a TestUtil Ċ import Ġcom . intellij . test Framework . run In Ed t AndGet Ċ import Ġcom . intellij . test Framework . run In Ed t And Wait Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġsoftware . amazon . aw ssdk . services . iam . Iam Client Ċ import Ġsoftware . amazon . aw ssdk . services . iam . model . List Roles Request Ċ import Ġsoftware . amazon . aw ssdk . services . iam . model . List Roles Response Ċ import Ġsoftware . amazon . aw ssdk . services . iam . model . Role Ċ import Ġsoftware . amazon . aw ssdk . services . iam . pag in ators . List Roles Iterable Ċ import Ġsoftware . amazon . aw ssdk . services . lambda . model . Runtime Ċ import Ġsoftware . amazon . aw ssdk . services . s 3 . S 3 Client Ċ import Ġsoftware . amazon . aw ssdk . services . s 3 . model . Bucket Ċ import Ġsoftware . aws . tool k its . core . region . Aws Region Ċ import Ġsoftware . aws . tool k its . core . utils . Rule Utils Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Mock Client Manager Rule Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Mock Resource Cache Rule Ċ import Ġsoftware . aws . tool k its . jetbrains . core . credentials . Aws ConnectionManager Ċ import Ġsoftware . aws . tool k its . jetbrains . core . credentials . Mock Aws ConnectionManager Ċ import Ġsoftware . aws . tool k its . jetbrains . services . lambda . Lambda Handler Resolver Ċ import Ġsoftware . aws . tool k its . jetbrains . services . s 3 . resources . S 3 Resources Ċ import Ġsoftware . aws . tool k its . jetbrains . settings . Update Lambda Settings Ċ import Ġsoftware . aws . tool k its . jetbrains . ui . Resource Selector Ċ import Ġsoftware . aws . tool k its . jetbrains . utils . rules . Java Code Insight TestFixture Rule Ċ import Ġsoftware . aws . tool k its . jetbrains . utils . waitFor False Ċ Ċ class ĠEdit Function Dialog Test Ġ{ ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġval Ġproject Rule Ġ= ĠJava Code Insight TestFixture Rule () ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġval Ġmock Client Manager Ġ= ĠMock Client Manager Rule () ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġval Ġmock Resource Cache Ġ= ĠMock Resource Cache Rule () ĊĊĠĠĠ Ġprivate Ġval Ġmock Settings Manager Ġby Ġlazy Ġ{ ĠAws ConnectionManager . getInstance ( project Rule . project ) Ġas ĠMock Aws ConnectionManager Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġs 3 Client : ĠS 3 Client ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġiam Client : ĠI am Client ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġs 3 Client Ġ= Ġmock Client Manager . create () ĊĠĠĠĠĠĠĠ Ġiam Client Ġ= Ġmock Client Manager . create () ĊĠĠĠĠĠĠĠ Ġmock Settings Manager . change Region ( Aws Region (" us - west - 1 ", Ġ" US ĠWest Ġ 1 ", Ġ" aws ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġsdk Ġ= ĠIde a TestUtil . getMock J dk 1 8 () ĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrun Write Action Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠProject J dk Table . getInstance (). add J dk ( sdk , Ġproject Rule . fixture . project Disposable ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠProject Root Manager . getInstance ( project Rule . project ). project Sdk Ġ= Ġsdk ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` On Ġnew Ġand Ġupdate Ġcode , Ġdialog Ġonly Ġshows Ġruntime s Ġwe Ġcan Ġbuild `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . NEW ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). runtime . model . size ). isEqualTo ( Lambda Handler Resolver . supported Runtime Groups (). flatMap Ġ{ Ġit . runtime s Ġ}. size ) ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). runtime . model . size ). isNot EqualTo ( Runtime . known Values (). size ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog 2 Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CODE ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog 2 . getView For Test Assertions (). runtime . model . size ). isEqualTo ( Lambda Handler Resolver . supported Runtime Groups (). flatMap Ġ{ Ġit . runtime s Ġ}. size ) ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog 2 . getView For Test Assertions (). runtime . model . size ). isNot EqualTo ( Runtime . known Values (). size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Load s Ġsaved Ġsettings Ġif Ġfunction Ġname Ġmatches `() Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Buckets () ĊĊĠĠĠĠĠĠĠ Ġval Ġar n Ġ= ĠRule Utils . random Name () ĊĠĠĠĠĠĠĠ Ġval Ġsettings Ġ= ĠUpdate Lambda Settings . getInstance ( arn ) ĊĊĠĠĠĠĠĠĠ Ġsettings . bucketName Ġ= Ġ" hello 2 " ĊĠĠĠĠĠĠĠ Ġsettings . use Container Ġ= Ġtrue ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CODE , Ġar n Ġ= Ġar n ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġdialog . getView For Test Assertions (). source Bucket . wait To Load () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build In Container . isSelected ). isEqualTo ( true ) ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). source Bucket . selected Item ?. toString ()). isEqualTo (" hello 2 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Does Ġnot Ġload Ġsaved Ġsettings Ġif Ġfunction Ġname Ġdoes Ġnot Ġmatch `() Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Buckets () ĊĊĠĠĠĠĠĠĠ Ġval Ġar n Ġ= ĠRule Utils . random Name () ĊĠĠĠĠĠĠĠ Ġval Ġsettings Ġ= ĠUpdate Lambda Settings . getInstance ( arn ) ĊĊĠĠĠĠĠĠĠ Ġsettings . bucketName Ġ= Ġ" hello 2 " ĊĠĠĠĠĠĠĠ Ġsettings . use Container Ġ= Ġtrue ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CODE , Ġar n Ġ= Ġ" not $ arn ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġdialog . getView For Test Assertions (). source Bucket . wait To Load () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build In Container . isSelected ). isEqualTo ( false ) ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). source Bucket . selected Item ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` On Ġupdate Ġconfiguration , Ġdialog Ġshows Ġall Ġruntime s `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CONFIGURATION ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). runtime . model . size ). isNot EqualTo ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLambda Handler Resolver . supported Runtime Groups (). flatMap Ġ{ Ġit . runtime s Ġ}. size ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). runtime . model . size ). isEqualTo ( Runtime . known Values (). size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnew Shows Configuration Deployment And Build Settings () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Roles () ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . NEW ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). configuration Settings . isVisible ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). deploy Settings . isVisible ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build Settings . isVisible ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Configuration Shows Only Configuration Settings () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Roles () ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CONFIGURATION ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). configuration Settings . isVisible ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). deploy Settings . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build Settings . isVisible ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Code Shows Only Deployment Settings Handler And Build () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Roles () ĊĊĠĠĠĠĠĠĠ Ġval Ġdialog Ġ= Ġrun In Ed t AndGet Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEdit Function Dialog ( project Ġ= Ġproject Rule . project , Ġmode Ġ= ĠEdit Function Mode . UPDATE _ CODE ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). deploy Settings . isVisible ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build Settings . isVisible ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). handler Panel . handler . isVisible ). isTrue () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). build In Container . isVisible ). isTrue () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). name . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). description . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). iam Role . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). create Role . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). runtime . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). env Vars . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). timeout Slider . isVisible ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( dialog . getView For Test Assertions (). memory Slider . isVisible ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmock Buckets () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Resource Cache . add Entry ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġproject Rule . project , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS 3 Resources . LIST _ REGION AL IZED _ BUCKET S , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠS 3 Resources . Region al ized Bucket ( Bucket . builder (). name (" hello "). build (), Ġmock Settings Manager . active Region ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠS 3 Resources . Region al ized Bucket ( Bucket . builder (). name (" hello 2 "). build (), Ġmock Settings Manager . active Region ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmock Roles () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( iam Client . list Roles Paginator ( any < List Roles Request >() )). then Answer Ġ{ Ġa Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠList Roles Iterable ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġiam Client , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġa . arguments . first () Ġas ĠList Roles Request ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġwhenever ( iam Client . list Roles ( any < List Roles Request >() )). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠList Roles Response . builder (). roles ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠRole . builder (). arn (" abc 1 2 3 "). assume Role Policy Document ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠL AMBDA _ PR INC IP AL ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ). build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ). is Truncated ( false ). build () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠResource Selector <* >. wait To Load () Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠwaitFor False Ġ{ ĠisLoading Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ