package Ġcom . spring data jpa . file data Ċ Ċ import Ġcom . spring data jpa . file data . entities . Image Ċ import Ġcom . spring data jpa . file data . repositories . Image Repository Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . core . io . Resource Loader Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ import Ġjava . io . File Ċ import Ġjava . io . FileInputStream Ċ import Ġjava . io . File OutputStream Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ SpringBootTest Ċ class ĠFile data Application Tests Ġ{ ĊĊ ĉ @ Autowired Ċ ĉ late init Ġvar Ġimage Repository : ĠImage Repository ĊĊ ĉ @ Test Ċ ĉ fun Ġcontext Load s () Ġ{ Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest File Save (){ Ċĉ ĉ var Ġfile Ġ= ĠFile (" C :\\ Users \\ E li as - Work \\ Documents \\ GitHub \\ tutorials \\ file data \\ src \\ main \\ resources \\ mac _ setup . jpg ") Ċĉ ĉ var Ġfile Content Ġ= ĠByteArray ( file . length (). toInt ()) Ċĉ ĉ var ĠinputStream Ġ= ĠFileInputStream ( file ) ĊĊĉ ĉ inputStream . read ( file Content ) ĊĊĉ ĉ image Repository . save ( Image ( name Ġ= Ġ" Mac ĠSetup ", Ġdata Ġ= Ġfile Content )) ĊĊĉ ĉ inputStream . close () Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest File Read (){ Ċĉ ĉ var Ġimage Ġ= Ġimage Repository . findById ( 1 1 ). get () Ċĉ ĉ var Ġfile Ġ= ĠFile (" C :\\ Users \\ E li as - Work \\ Downloads \ \" Ġ+ Ġimage . name ) Ċĉ ĉ var Ġfile OutputStream Ġ= ĠFileOutputStream ( file ) ĊĊĉ ĉ file OutputStream . write ( image . data ) ĊĊĉ ĉ file OutputStream . close () Ċ ĉ } Ċ Ċ } Ċ