package Ġcom . nim bus framework . nim bus aws . cloudformation . generation . resources . file storage bucket Ċ Ċ import Ġcom . nim bus framework . nim bus aws . Compile State Service Ċ import Ġcom . nim bus framework . nim bus aws . annotation . processor . Processing Data Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . generation . ab stractions . Function Environment Service Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . generation . ab stractions . Resource Finder Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . generation . resources . apigateway . Http Function Resource Creator Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . generation . resources . file storage bucket . Uses File Storage Client Processor Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . model . Cloud Formation Files Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . model . resource . Iam Role Resource Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . model . resource . file . File Bucket Resource Ċ import Ġcom . nim bus framework . nim bus aws . cloudformation . model . resource . function . Function Resource Ċ import Ġcom . nim bus framework . nim bus core . pers isted . Nim bus State Ċ import Ġio . kot est . core . spec . style . Annotation Spec Ċ import Ġio . kot est . matchers . shouldBe Ċ import Ġio . mock k . Called Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . verify Ċ import Ġjavax . annotation . processing . Mess ager Ċ import Ġjavax . annotation . processing . Processing Environment Ċ import Ġjavax . annotation . processing . Round Environment Ċ import Ġjavax . tools . Diagnostic Ċ Ċ class ĠUses File Storage Bucket Client Processor Test : ĠAnnotation Spec () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuses File Storage Client Processor : ĠUses File Storage Client Processor ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġround Environment : ĠRound Environment ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcf Documents : ĠMutable Map < String , ĠCloudFormation Files > ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġprocessing Data : ĠProcessing Data ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfunction Resource : ĠFunction Resource ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcompile State Service : ĠCompile State Service ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmess ager : ĠMess ager ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġresource Finder : ĠResource Finder ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġprocessing Data Ġ= ĠProcessing Data ( Nim bus State ()) ĊĠĠĠĠĠĠĠ Ġcf Documents Ġ= Ġmutable Map Of () ĊĠĠĠĠĠĠĠ Ġround Environment Ġ= Ġmock k () ĊĠĠĠĠĠĠĠ Ġmess ager Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġresource Finder Ġ= Ġmock k () ĊĊĠĠĠĠĠĠĠ Ġcompile State Service Ġ= ĠCompile State Service (" models / File Storage . java ", Ġ" handlers / Uses File Storage Client Handler . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup ( processing Environment : ĠProcessing Environment , Ġto Run : Ġ() Ġ-> ĠUnit Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġelements Ġ= Ġprocessing Environment . element Utils ĊĊĠĠĠĠĠĠĠ ĠHttp Function Resource Creator ( cf Documents , Ġprocessing Data , Ġmock k ( relax ed Ġ= Ġtrue ), Ġprocessing Environment , Ġset Of (), Ġmock k ( relax ed Ġ= Ġtrue )). handle Element ( elements . getType Element (" handlers . Uses File Storage Client Handler "). enc losed Elements [ 1 ], ĠFunction Environment Service ( cf Documents , Ġprocessing Data )) ĊĊĠĠĠĠĠĠĠ Ġfunction Resource Ġ= Ġcf Documents [" dev "] !!. update Template . resources . get (" Uses File Storage Client Handler func Function ") Ġas ĠFunction Resource ĊĠĠĠĠĠĠĠ Ġuses File Storage Client Processor Ġ= ĠUses File Storage Client Processor ( mess ager , Ġresource Finder , Ġprocessing Data . nim bus State ) ĊĊĠĠĠĠĠĠĠ Ġto Run () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcorrectly Sets Permissions () Ġ{ ĊĠĠĠĠĠĠĠ Ġcompile State Service . compile Objects Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsetup ( it ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbucket Resource Ġ= ĠFile Bucket Resource ( processing Data . nim bus State , Ġ" Image Bucket ", ĠarrayOf (), Ġ" dev " Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġevery Ġ{ Ġresource Finder . getFile Storage Bucket Resource ( any (), Ġany (), Ġany ()) Ġ} Ġreturns Ġbucket Resource ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġuses File Storage Client Processor . handle Use Resources ( it . element Utils . getType Element (" handlers . Uses File Storage Client Handler "). enc losed Elements [ 1 ], Ġfunction Resource ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . get Str Env Value (" NIM BUS _ STAGE ") ĠshouldBe Ġ" dev " ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : GetObject ", Ġbucket Resource , Ġ"") ĠshouldBe Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : Delete Object ", Ġbucket Resource , Ġ"") ĠshouldBe Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : Put Object ", Ġbucket Resource , Ġ"") ĠshouldBe Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : GetObject ", Ġbucket Resource , Ġ" /* ") ĠshouldBe Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : Delete Object ", Ġbucket Resource , Ġ" /* ") ĠshouldBe Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfunction Resource . iam Role Resource . allows (" s 3 : Put Object ", Ġbucket Resource , Ġ" /* ") ĠshouldBe Ġtrue ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmess ager Ġwas Not ĠCalled Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlogs Error If Cannot Find File Storage Bucket () Ġ{ ĊĠĠĠĠĠĠĠ Ġcompile State Service . compile Objects Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsetup ( it ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġevery Ġ{ Ġresource Finder . getFile Storage Bucket Resource ( any (), Ġany (), Ġany ()) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġuses File Storage Client Processor . handle Use Resources ( it . element Utils . getType Element (" handlers . Uses File Storage Client Handler "). enc losed Elements [ 1 ], Ġfunction Resource ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmess ager . print Message ( Diagnostic . Kind . ERROR , Ġany (), Ġany ()) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ } Ċ