HsacExamples.SlimTests.UtilityFixtures.FileFixture


The FileFixture allows file manipulation, either in the wiki's files section[?], or on the file system.
Files can be generated using Freemarker templates, directly from strings or by copying files.
File's content and size may be retrieved.
Filenames may be manipulated.

variable defined: DIR=.

variable defined: LIST_CONTENT=!-001 002 last one!-!

script file fixture
note default directory used by the fixture is inside the files section
$def_dir<-[/home/travis/build/fhoeben/hsac-fitnesse-fixtures/target/fitnesse-results/files/fileFixture/] get directory
$created<-[bye1.txt] create bye1.txt containing Bye Bye 1
repeat at most 50 times
Do not forget to set 'repeat at most times', or else the loop may run endlessly!
poll until $created->[bye1.txt] exists
poll until size of $created->[bye1.txt] exceeds 0
check text in $created->[bye1.txt] Bye Bye 1
check filename of $created->[bye1.txt] bye1.txt
check base name of $created->[bye1.txt] bye1
check extension of $created->[bye1.txt] txt
ensure exists $created->[bye1.txt]
delete $created->[bye1.txt]
reject exists $created->[bye1.txt]
deleting non-existing file does not work: throws exception
but ensuring non-existing file does not exist is no problem, returns false
reject delete $created->[bye1.txt] if exists
poll until $created->[bye1.txt] does not exist
note directory to be used by the fixture can be set to inside the files section
set directory http://files/test
$created2<-[bye2.txt] create bye2.txt containing Bye Bye 2
check text in $created2->[bye2.txt] Bye Bye 2
delete $created2->[bye2.txt] if exists
note directory to be used by the fixture can be set to system path
set directory .
$created3<-[bye.txt] create bye.txt containing Bye Bye 3
check filename of $created3->[bye.txt] bye.txt
check size of bye.txt 9
check text in bye.txt Bye Bye 3
set value John for name
show create greeting.txt using greeting.ftl greeting.txt
check text in greeting.txt Hello John
set value John for name
show create greeting.html using greeting.ftl.html greeting.html
show text in greeting.html <html> <body> Hello<br/> <h1>John</h1> </body> </html>
show content of greeting.html
<html>
    <body>
        Hello<br/>
        <h1>John</h1>
    </body>
</html>
note filename's containing either / or \ will point to sub-directories
show copy ./greeting.txt to copy/greetingCopy.txt greetingCopy.txt
check text in .\copy\greetingCopy.txt Hello John
check filename of .\copy\greetingCopy.txt greetingCopy.txt
check base name of .\copy\greetingCopy.txt greetingCopy
check extension of .\copy\greetingCopy.txt txt
note you can create a new file by "appending" one line into it
set directory http://files/test
$appended<-[appended.txt] append first to appended.txt
check text in $appended->[appended.txt] first
note you can append content to an existing file
append line to $appended->[appended.txt]
check text in $appended->[appended.txt] first line
note you can append content as a new line to an existing file
append second line to $appended->[appended.txt] on new line
convert line endings of $appended->[appended.txt] to unix
check text in $appended->[appended.txt] first line second line
convert line endings of $appended->[appended.txt] to windows
check size of $appended->[appended.txt] 23
convert line endings of $appended->[appended.txt] to unix
check size of $appended->[appended.txt] 22
delete $appended->[appended.txt]

Table below shows how we can work with zip files

We ensure lists are rendered between brackets, and not numbered
script list fixture
display lists standard

script file fixture
$created<-[bye1.txt] create bye1.txt containing Bye Bye 5
$zip<-[bye_1.zip] zip $created->[bye1.txt] as bye.zip
check number of files in zip $zip->[bye_1.zip] 1
check names of files in zip $zip->[bye_1.zip] [bye1.txt]
$unzipped<-[unzipped_1] unzip $zip->[bye_1.zip] as unzipped
check text in $unzipped->[unzipped_1]/bye1.txt Bye Bye 5
$zip2<-[zip2_1.zip] zip $unzipped->[unzipped_1] as zip2.zip
check names of files in zip $zip2->[zip2_1.zip] [bye1.txt]


Table below shows how we can use a list of non-reusable data from a file:

script
set directory http://files/fileFixture
create list.txt containing 001 002 last one!
show text in list.txt 001 002 last one!
check take first line from list.txt 001
show text in list.txt 002 last one!
check take first line from list.txt 002
check take first line from list.txt last one!
show text in list.txt