package Ġapp . batch Ċ Ċ import Ġapp . domain . Encrypted Stream Ċ import Ġapp . domain . Encryption Metadata Ċ import Ġcom . amazonaws . services . s 3 . Amazon S 3 Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . given Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNull Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . slf 4 j . Logger Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ SpringBootTest ( classes Ġ= Ġ[ Finished Filter Processor :: class , ĠS 3 Utils :: class ]) Ċ class ĠFinished Filter Processor Test Ġ{ ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġamazon S 3 : ĠAmazon S 3 ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfinished Filter Processor : ĠFinished Filter Processor ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġs 3 utils : ĠS 3 Utils ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Un processed File Is Processed () Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" hello ") ĊĠĠĠĠĠĠĠ Ġval Ġinitialization Vector Ġ= Ġ" initialization Vector " ĊĠĠĠĠĠĠĠ Ġval Ġdata key Encryption KeyId Ġ= Ġ" data key Encryption KeyId " ĊĠĠĠĠĠĠĠ Ġval Ġcipher Text Ġ= Ġ" cipher Text " ĊĠĠĠĠĠĠĠ Ġval Ġplaintext Ġ= Ġ" plaintext " ĊĠĠĠĠĠĠĠ Ġval Ġencryption Metadata Ġ= ĠEncryption Metadata ( initialization Vector , Ġdata key Encryption KeyId , Ġcipher Text , Ġplaintext ) ĊĠĠĠĠĠĠĠ Ġval ĠfileName Ġ= Ġ" db . core . address Declaration - 0 0 0 0 0 1 . txt . bz 2 . enc " ĊĠĠĠĠĠĠĠ Ġval Ġfull path Ġ= Ġ"${ s 3 utils . s 3 Prefix Folder }$ fileName " ĊĠĠĠĠĠĠĠ Ġval Ġencrypted Stream Ġ= ĠEn crypted Stream (" input stream ". toByteArray (), ĠfileName , Ġfull path , Ġencryption Metadata ) ĊĠĠĠĠĠĠĠ Ġval Ġfinished Flag Ġ= Ġs 3 utils . get Finished Status KeyName ( full path ) ĊĠĠĠĠĠĠĠ Ġlogger . info (" finished Flag : Ġ'$ finished Flag '. ") ĊĠĠĠĠĠĠĠ Ġgiven ( amazon S 3 . does Object Exist ( s 3 bucket , Ġfinished Flag )). willReturn ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfinished Filter Processor . process ( encrypted Stream ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( encrypted Stream , Ġresult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Processed File IsNot Processed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinitialization Vector Ġ= Ġ" initialization Vector " ĊĠĠĠĠĠĠĠ Ġval Ġdata key Encryption KeyId Ġ= Ġ" data key Encryption KeyId " ĊĠĠĠĠĠĠĠ Ġval Ġcipher Text Ġ= Ġ" cipher Text " ĊĠĠĠĠĠĠĠ Ġval Ġplaintext Ġ= Ġ" plaintext " ĊĠĠĠĠĠĠĠ Ġval Ġencryption Metadata Ġ= ĠEncryption Metadata ( initialization Vector , Ġdata key Encryption KeyId , Ġcipher Text , Ġplaintext ) ĊĠĠĠĠĠĠĠ Ġval ĠfileName Ġ= Ġ" db . core . address Declaration - 0 0 0 0 0 1 . txt . bz 2 . enc " ĊĠĠĠĠĠĠĠ Ġval Ġfull path Ġ= Ġ"${ s 3 utils . s 3 Prefix Folder }$ fileName " ĊĠĠĠĠĠĠĠ Ġval Ġencrypted Stream Ġ= ĠEn crypted Stream (" input stream ". toByteArray (), ĠfileName , Ġfull path , Ġencryption Metadata ) ĊĠĠĠĠĠĠĠ Ġval Ġfinished Flag Ġ= Ġs 3 utils . get Finished Status KeyName ( full path ) ĊĠĠĠĠĠĠĠ Ġlogger . info (" finished Flag : Ġ'$ finished Flag '. ") ĊĠĠĠĠĠĠĠ Ġgiven ( amazon S 3 . does Object Exist ( s 3 bucket , Ġfinished Flag )). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfinished Filter Processor . process ( encrypted Stream ) ĊĠĠĠĠĠĠĠ ĠassertNull ( result ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlogger : ĠLogger Ġ= ĠLoggerFactory . getLogger ( Finished Filter Processor :: class . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Value ("\ ${ s 3 . bucket }") Ġ// where Ġthe ĠHT ME Ġexports Ġand Ġthe ĠSender Ġp icks Ġup Ġfrom ĊĠĠĠ Ġlateinit Ġvar Ġs 3 bucket : ĠString Ċ Ċ } Ċ