/* Ċ Ġ* ĠCopyright Ġ 2 0 2 1 Ġthe Ġoriginal Ġauthor Ġor Ġauthors . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttps :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . springframework . integration . kotlin . file . ag gregator Ċ Ċ import Ġassert k . all Ċ import Ġassert k . assertThat Ċ import Ġassert k . assertions .* Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . io . TempDir Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . beans . factory . annotation . Qualifier Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . core . task . Task Executor Ċ import Ġorg . springframework . integration . Integration Message Header Accessor Ċ import Ġorg . springframework . integration . config . Enable Integration Ċ import Ġorg . springframework . integration . dsl . integration Flow Ċ import Ġorg . springframework . integration . file . File Headers Ċ import Ġorg . springframework . integration . file . ag gregator . File Aggregator Ċ import Ġorg . springframework . integration . file . dsl . Files Ċ import Ġorg . springframework . integration . file . splitter . File Splitter . File Marker Ċ import Ġorg . springframework . messaging . Message Channel Ċ import Ġorg . springframework . messaging . Poll able Channel Ċ import Ġorg . springframework . messaging . support . Generic Message Ċ import Ġorg . springframework . test . annotation . Dir ties Context Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring JUnit Config Ċ import Ġorg . springframework . util . File Copy Utils Ċ import Ġjava . io . File Ċ import Ġjava . io . File OutputStream Ċ Ċ /** Ċ Ġ* Ġ@ author ĠArt em ĠB il an Ċ Ġ* Ċ Ġ* Ġ@ since Ġ 5 . 5 Ċ Ġ*/ Ċ @ Spring JUnit Config Ċ @ Dir ties Context Ċ class ĠKotlin File Aggregator Tests Ġ{ ĊĊ ĉ comp anion Ġobject Ġ{ ĊĊĉ ĉ late init Ġvar Ġfile : ĠFile ĊĊĉ ĉ @ Before All Ċĉ ĉ @ Jvm Static Ċĉ ĉ fun Ġsetup (@ TempDir Ġtmp Dir : ĠFile ) Ġ{ Ċĉĉ ĉ file Ġ= ĠFile ( tmp Dir , Ġ" foo . txt ") Ċĉĉ ĉ val Ġcontent Ġ= Ġ""" Ċĉĉ ĉ file Ġheader Ċĉĉ ĉ first Ġline Ċĉĉ ĉ second Ġline Ċĉĉ ĉ last Ġline Ċĉĉ ĉ """. trim Indent () Ċĉĉ ĉ File Copy Utils . copy ( content . toByteArray (), ĠFileOutputStream ( file , Ġfalse )) Ċĉ ĉ } ĊĊ ĉ } ĊĊ ĉ @ Autowired Ċ ĉ @ Qualifier (" file Splitter Aggregator Flow . input ") Ċ ĉ private Ġlateinit Ġvar Ġfile Splitter Aggregator Flow : ĠMessage Channel ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġresult Channel : ĠPoll able Channel ĊĊ ĉ @ Test Ċ ĉ fun Ġtest File Aggregator () Ġ{ Ċĉ ĉ this . file Splitter Aggregator Flow . send ( Generic Message ( file )) Ċĉ ĉ val Ġreceive Ġ= Ġthis . result Channel . receive ( 1 0 0 0 0 ) Ċĉ ĉ assertThat ( receive ). isNotNull () Ċĉ ĉ assertThat ( receive . headers ) Ċĉĉ ĉ . all Ġ{ Ċĉĉĉ ĉ contains ( File Headers . FILENAME , Ġ" foo . txt ") Ċĉĉĉ ĉ contains ( File Headers . LINE _ COUNT , Ġ 3 L ) Ċĉĉĉ ĉ contains (" first Line ", Ġ" file Ġheader ") Ċĉĉĉ ĉ does Not Contain ( Integration Message Header Accessor . COR REL ATION _ ID , Ġnull ) Ċĉĉ ĉ } ĊĊĉ ĉ assertThat ( receive . payload ) Ċĉĉ ĉ . isInstanceOf ( Mutable List :: class . java ) Ċĉĉ ĉ . contains All (" SECOND ĠLINE ", Ġ" LAST ĠLINE ", Ġ" FIRST ĠLINE ") Ċ ĉ } ĊĊ ĉ @ Configuration Ċ ĉ @ Enable Integration Ċ ĉ class ĠConfig Ġ{ ĊĊĉ ĉ @ Bean Ċĉ ĉ fun Ġfile Splitter Aggregator Flow ( task Executor : ĠTask Executor ?) Ġ= Ċĉĉ ĉ integration Flow Ġ{ Ċĉĉĉ ĉ split ( Files . splitter (). markers (). first Line As Header (" first Line ")) Ċĉĉĉ ĉ channel Ġ{ Ġexecutor ( task Executor ) Ġ} Ċĉĉĉ ĉ filter < Any >({ Ġit Ġ! is ĠFile Marker Ġ}) Ġ{ Ġdiscard Channel (" ag gregator Channel ") Ġ} Ċĉĉĉ ĉ transform ( String :: toUpperCase ) Ċĉĉĉ ĉ channel (" ag gregator Channel ") Ċĉĉĉ ĉ aggregate ( File Aggregator ()) Ċĉĉĉ ĉ channel Ġ{ Ġqueue (" result Channel ") Ġ} Ċĉĉ ĉ } ĊĊ ĉ } Ċ Ċ }