Introduction

This page shows how you can verify whether some File or Folder is present or not  at some local or remote host



Constructing the verification object

import com.axway.ats.rbv.clients.FileSystemVerification;

// Make an instance of the verification object.
// The first input argument points to the remote ATS Agent, skip this argument if working on the local host
FileSystemVerification fsVerification = new FileSystemVerification( SERVER_IP, FILE_LOCATION );

If you want to work locally, use the constructor which does not specify a remote host IP

When working remotely, the ATS Agent must be running on the remote host



Add verification rules

Using the different check... methods you can add as many checks as you need

Following is an example as complex as you will never need in practice (smile)

// check the size of the files
fsVerification.checkSize( 62 );

// the file must contain some static text
fsVerification.checkContents( "line 3", false, true );

// at least one line of the file end with the number 3
// we are using a regular expression here
fsVerification.checkContents( ".*3", true, true );

// verify the file MD5 sum by providing the exact sum
fsVerification.checkMd5( "560bba529205da4d92bebb026b2e6e8b" );

// Verify the file MD5 sum, but this time do not give the sum itself, instead we provide a sample file.
// The usual case is if you upload a local file, then you want to make sure the remote file has
// same MD5 sum as the original local file
fsVerification.checkMd5( null, LOCAL_FILE );

// verify the GID and UID
fsVerification.checkGID( 1001 );
fsVerification.checkUID( 1001 );

// verify the file permission attributes
fsVerification.checkPermissions( 644 );

So far we have just specified what kind of file we are interested in.

But the actual verification starts at the moment you call one of the verify... methods



Verify a file exists

Keep polling until there is verification that the searched file is present.

Fail if the searched file is not found for all polling attempts.

fsVerification.verifyFileExists();



Successful verification output

RBV is verbose enough so from the logs you can understand if each of these checks was successful. It takes a little time until get used with these log messages, but they look the same for all kind of checks.

For example, a part of the output in this example would be:

INFO  17:29:13 rules.FileSizeRule: Starting evaluation of rule 'checkSize' which expects file with size '62'
INFO  17:29:13 rules.FileSizeRule: Processing meta data { FILE_PACKAGE : /tmp/file.txt }
INFO  17:29:13 rules.FileSizeRule: Found a match!
INFO  17:29:13 rules.FileSizeRule: Finished evaluation of rule 'checkSize' which expects file with size '62'



Unsuccessful verification output

Upon failure, you will get output like the following:

INFO  17:39:49 rules.FileSizeRule: Starting evaluation of rule 'checkSize' which expects file with size '602'
INFO  17:39:49 rules.FileSizeRule: Processing meta data { FILE_PACKAGE : /tmp/file.txt }
INFO  17:39:49 rules.FileSizeRule: Did not find a match!
INFO  17:39:49 rules.FileSizeRule: Finished evaluation of rule 'checkSize' which expects file with size '602'

And another try is made until all the allowed tries are exhausted and a final failure results in throwing an exception which fails the test case.



Verify a file does not exist

Keep polling until there is verification that the searched file is NOT present.

Fail if the searched file is present for all polling attempts.

fsVerification.verifyFileDoesNotExist();



Verify a file always exists

The next code will succeed if the searched file is present for all polling attempts otherwise, it will fail.

fsVerification.verifyFileAlwaysExists();



Verify a file never exists

The next code will succeed if the searched file is NOT present for all polling attempts otherwise, it will fail.

fsVerification.verifyFileNeverExist();



Verify a folder exists

Here is how you can verify the existence of a folder

FileSystemVerification fsVerification = new FileSystemVerification( SERVER_IP, "/tmp" );

// verify the GID and UID
fsVerification.checkGID( 1001 );
fsVerification.checkUID( 1001 );

// verify the folder permission attributes
fsVerification.checkPermissions( 1777 );

fsVerification.verifyFolderExists();

The logic is basically the same as with the files. But of course all those check... methods are not applicable to folders.



Verify a folder does not exist

Keep polling until there is verification that the searched folder is NOT present.

Fail if the searched folder is present for all polling attempts.

fsVerification.verifyFolderDoesNotExist();



Verify a folder always exists

The next code will succeed if the searched folder is present for all polling attempts otherwise, it will fail.

fsVerification.verifyFolderAlwaysExists();



Verify a folder never exists

The next code will succeed if the searched folder is NOT present for all polling attempts otherwise, it will fail.

fsVerification.verifyFolderNeverExist();



Back to parent page

Go to Table of Contents