/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 0 . ĠT ol gee Ċ Ġ*/ Ċ Ċ package Ġio . tol gee . component . file Storage Ċ Ċ import Ġcom . amazonaws . services . s 3 . Amazon S 3 Ċ import Ġcom . amazonaws . services . s 3 . model . Amazon S 3 Exception Ċ import Ġio . find ify . s 3 mock . S 3 Mock Ċ import Ġio . tol gee . component . file Storage . File Storage S 3 Test . Companion . BUCKET _ NAME Ċ import Ġio . tol gee . testing . Context Re creating Test Ċ import Ġio . tol gee . testing . assertions . Assertions . assertThat Ċ import Ġio . tol gee . testing . assertions . Assertions . assertThat Exception OfType Ċ import Ġorg . junit . jupiter . api . After All Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . Test Instance Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ Ċ @ Context Re creating Test Ċ @ SpringBootTest ( ĊĠ Ġproperties Ġ= Ġ[ ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . enabled = true ", ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . access - key = dummy _ access _ key ", ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . secret - key = dummy _ secret _ key ", ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . endpoint = http :// localhost : 2 9 0 9 0 ", ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . signing - region = dummy _ signing _ region ", ĊĠĠĠ Ġ" tol gee . file - storage . s 3 . bucket - name =$ BUCKET _ NAME ", ĊĠ Ġ] Ċ ) Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ class ĠFile Storage S 3 Test Ġ: ĠAbstract File Storage Service Test () Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġconst Ġval ĠBU CKET _ NAME Ġ= Ġ" test bucket " ĊĠ Ġ} ĊĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġs 3 : ĠAmazon S 3 ĊĊĠ Ġlateinit Ġvar Ġs 3 Mock : ĠS 3 Mock ĊĊĠ Ġ@ Before All ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġs 3 Mock Ġ= ĠS 3 Mock . Builder (). with Port ( 2 9 0 9 0 ). with InMemory Backend (). build () ĊĠĠĠ Ġs 3 Mock . start () ĊĠĠĠ Ġs 3 . create Bucket ( BUCKET _ NAME ) ĊĠ Ġ} ĊĊĠ Ġ@ After All ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ Ġs 3 Mock . stop () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File () Ġ{ ĊĠĠĠ Ġs 3 . put Object ( BUCKET _ NAME , Ġtest FilePath , Ġtest FileContent ) ĊĠĠĠ Ġval Ġfile Byte Content Ġ= Ġtest FileContent . toByteArray ( charset (" UTF - 8 ")) ĊĠĠĠ ĠassertThat ( file Storage . readFile ( test FilePath )). isEqualTo ( file Byte Content ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Delete File () Ġ{ ĊĠĠĠ Ġs 3 . put Object ( BUCKET _ NAME , Ġtest FilePath , Ġtest FileContent ) ĊĠĠĠ Ġfile Storage . delete File ( test FilePath ) ĊĠĠĠ ĠassertThat Exception OfType ( Amazon S 3 Exception :: class . java ). is Thrown By Ġ{ Ġs 3 . getObject ( BUCKET _ NAME , Ġtest FilePath ) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Store File () Ġ{ ĊĠĠĠ Ġfile Storage . store File ( test FilePath , Ġtest FileContent . toByteArray ( charset (" UTF - 8 "))) ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġs 3 . getObject ( BUCKET _ NAME , Ġtest FilePath ). object Content . read All Bytes () ĊĠĠĠ Ġ). isEqualTo ( test FileContent . toByteArray ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest File Exists () Ġ{ ĊĠĠĠ Ġs 3 . put Object ( BUCKET _ NAME , Ġtest FilePath , Ġtest FileContent ) ĊĠĠĠ ĠassertThat ( file Storage . file Exists ( test FilePath )). isTrue ĊĠ Ġ} Ċ } Ċ