package Ġs moke Ċ Ċ import Ġcom . amazonaws . services . s 3 . Amazon S 3 Client Builder Ċ import Ġcom . amazonaws . services . s 3 . model . Delete Objects Request Ċ import Ġcom . amazonaws . services . s 3 . model . S 3 Object Summary Ċ import Ġorg . http 4 k . cloud native . env . Environment Ċ import Ġorg . http 4 k . core . Status . Companion . BAD _ REQUEST Ċ import Ġorg . http 4 k . core . Status . Companion . OK Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġs moke . actors . Mobile App Ċ import Ġs moke . actors . create Handler Ċ import Ġs moke . data . Analytics Events Data . analytics Events Ċ import Ġs moke . env . S moke Tests Ċ import Ġstri kt . api . expect That Ċ import Ġstri kt . assertions . containsKey Ċ import Ġstri kt . assertions . get Ċ import Ġstri kt . assertions . has Size Ċ import Ġstri kt . assertions . isEmpty Ċ import Ġstri kt . assertions . isEqualTo Ċ import Ġuk . n hs . n hs x . core . Json Ċ import Ġuk . n hs . n hs x . test helper . assertions . S 3 Assertions . list Objects Ċ import Ġuk . n hs . n hs x . test helper . assertions . S 3 Assertions . object Sum maries Ċ import Ġuk . n hs . n hs x . test helper . assertions . has Status Ċ import Ġuk . n hs . n hs x . test helper . assertions . isNotNull Or Blank Ċ import Ġuk . n hs . n hs x . test helper . assertions . signature Date Header Ċ import Ġuk . n hs . n hs x . test helper . assertions . signature Header Ċ import Ġjava . util .* Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ class ĠAnalytics Events Submission S moke Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġconfig Ġ= ĠS moke Tests . load Config () ĊĠĠĠ Ġprivate Ġval Ġclient Ġ= Ġcreate Handler ( Environment . ENV ) ĊĊĠĠĠ Ġprivate Ġval Ġmobile App Ġ= ĠMobile App ( client , Ġconfig ) ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġclear Submission Store () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġs 3 Client Ġ= ĠAmazon S 3 Client Builder . default Client () ĊĊĠĠĠĠĠĠĠ Ġval Ġkeys Ġ= Ġs 3 Client . list Objects ( config . analytics _ events _ submission _ store ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. object Sum maries ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map ( S 3 Object Summary :: getKey ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Typed Array () ĊĊĠĠĠĠĠĠĠ Ġif Ġ( keys . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġs 3 Client . delete Objects ( Delete Objects Request ( config . analytics _ events _ submission _ store ). with Keys (* keys )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` submit Ġvalid Ġpayload `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrandom UUID Ġ= ĠUUID . randomUUID () ĊĠĠĠĠĠĠĠ Ġval Ġupload Response Ġ= Ġmobile App . submit An alytic Events ( analytics Events ( randomUUID ). trim Indent ()) ĊĊĠĠĠĠĠĠĠ Ġexpect That ( upload Response ). has Status ( OK ). and Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsignature Header . isNotNull Or Blank () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsignature Date Header . isNotNull Or Blank () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġs 3 Client Ġ= ĠAmazon S 3 Client Builder . default Client () ĊĠĠĠĠĠĠĠ Ġval Ġobject Sum maries Ġ= Ġs 3 Client . list Objects ( config . analytics _ events _ submission _ store ). object Sum maries ĊĊĠĠĠĠĠĠĠ Ġexpect That ( object Sum maries ). has Size ( 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġs 3 Object Ġ= Ġs 3 Client . getObject ( config . analytics _ events _ submission _ store , Ġobject Sum maries [ 0 ]. key ) ĊĠĠĠĠĠĠĠ Ġval Ġstored Payload : ĠMap < String , Ġ*> Ġ= ĠJson . read Json OrThrow ( s 3 Object . object Content ) Ġas ĠMap < String , Ġ*> ĊĊĠĠĠĠĠĠĠ Ġexpect That ( stored Payload ). containsKey (" uuid ") ĊĊĠĠĠĠĠĠĠ Ġval Ġmetadata Ġ= Ġstored Payload [" metadata "] Ġas ĠMap < String , Ġ*> ĊĊĠĠĠĠĠĠĠ Ġexpect That ( metadata )[" operating System Version "]. isEqualTo ( randomUUID . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` submit Ġinvalid Ġpayload `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġupload Response Ġ= Ġmobile App . submit An alytic Events ("{} ") ĊĊĠĠĠĠĠĠĠ Ġexpect That ( upload Response ). has Status ( BAD _ REQUEST ). and Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsignature Header . isNotNull Or Blank () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsignature Date Header . isNotNull Or Blank () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġexpect That ( Amazon S 3 Client Builder . default Client ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. list Objects ( config . analytics _ events _ submission _ store ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. object Sum maries ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠ Ġ} Ċ } Ċ