Search in sources :

Example 26 with FileSystemMetaData

use of com.axway.ats.rbv.filesystem.FileSystemMetaData in project ats-framework by Axway.

the class Test_AndRuleOperation method isMatchPriority.

@Test
public void isMatchPriority() throws RbvException, PackageException {
    FileSystemMetaData meta = createMock(FileSystemMetaData.class);
    FilePackage pack = createMock(FilePackage.class);
    expect(meta.getFilePackage()).andReturn(pack);
    expect(pack.isFile()).andReturn(true);
    // at this point the evaluation should stop since this is the first rule to
    // evaluate and it fails thus the second should not be evaluated at all
    // if the priority does not work then the second rule would fail the unit test
    // because we are not expecting any calls it would do to the mock objects
    replayAll();
    FilePathRule rule = new FilePathRule("some/path/some.file", "pathRule1", true, 2);
    FileFolderRule anotherRule = new FileFolderRule(false, "folderRule", true, 1);
    AndRuleOperation andRule = new AndRuleOperation();
    andRule.addRule(rule);
    andRule.addRule(anotherRule);
    assertFalse(andRule.isMatch(meta));
    verifyAll();
}
Also used : FilePackage(com.axway.ats.action.objects.FilePackage) FileFolderRule(com.axway.ats.rbv.filesystem.rules.FileFolderRule) FilePathRule(com.axway.ats.rbv.filesystem.rules.FilePathRule) AndRuleOperation(com.axway.ats.rbv.rules.AndRuleOperation) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 27 with FileSystemMetaData

use of com.axway.ats.rbv.filesystem.FileSystemMetaData in project ats-framework by Axway.

the class Test_FileSystemFolder method getNewMetadataChangeLastModified.

@Test
public void getNewMetadataChangeLastModified() throws Exception {
    expectNew(SystemOperations.class, "localhost:0000").andReturn(systemOperations).times(7);
    expect(systemOperations.getOperatingSystemType()).andReturn(OperatingSystemType.LINUX);
    // now we call getNewMetaData() 3 times
    expect(fileSystemOperations.findFiles(path, ".*", true, true, false)).andReturn(fileList).times(3);
    // 3 times x 2 files
    expectNew(FileSystemOperations.class, "localhost:0000").andReturn(fileSystemOperations).times(7);
    expect(fileSystemOperations.getFileUniqueId(file1)).andReturn(file1_hash).times(2);
    expect(fileSystemOperations.getFileUniqueId(file2)).andReturn(file2_hash).times(3);
    // modify the modification timestamp of file1 for the last getNewMetaData() call
    expect(fileSystemOperations.getFileUniqueId(file1)).andReturn(file1_hash_changed);
    replayAll();
    FileSystemFolder folder = (FileSystemFolder) storage.getFolder(new FileSystemFolderSearchTerm(path, null, true, false));
    folder.open();
    List<MetaData> list = folder.getNewMetaData();
    assertEquals(2, list.size());
    for (MetaData metaData : list) {
        ((FileSystemMetaData) metaData).getFilePackage();
    }
    assertEquals(0, folder.getNewMetaData().size());
    assertEquals(1, folder.getNewMetaData().size());
    verifyAll();
}
Also used : MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) FileSystemFolder(com.axway.ats.rbv.filesystem.FileSystemFolder) FileSystemFolderSearchTerm(com.axway.ats.rbv.filesystem.FileSystemFolderSearchTerm) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 28 with FileSystemMetaData

use of com.axway.ats.rbv.filesystem.FileSystemMetaData in project ats-framework by Axway.

the class Test_FileContentRule method isMatchNegative.

@Test
public void isMatchNegative() throws Exception {
    expect(testFilePackage.grep(EXPRESSION, false)).andReturn(new String[0]);
    replayAll();
    FileContentRule rule = new FileContentRule(EXPRESSION, RULE_NAME, false, true);
    MetaData metaData = new FileSystemMetaData(testFilePackage);
    assertFalse(rule.isMatch(metaData));
    verifyAll();
}
Also used : FileContentRule(com.axway.ats.rbv.filesystem.rules.FileContentRule) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 29 with FileSystemMetaData

use of com.axway.ats.rbv.filesystem.FileSystemMetaData in project ats-framework by Axway.

the class Test_FileContentRule method isMatch.

@Test
public void isMatch() throws Exception {
    expect(testFilePackage.grep(EXPRESSION, false)).andReturn(new String[] { EXPRESSION });
    replayAll();
    FileContentRule rule = new FileContentRule(EXPRESSION, RULE_NAME, false, true);
    MetaData metaData = new FileSystemMetaData(testFilePackage);
    assertTrue(rule.isMatch(metaData));
    verifyAll();
}
Also used : FileContentRule(com.axway.ats.rbv.filesystem.rules.FileContentRule) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 30 with FileSystemMetaData

use of com.axway.ats.rbv.filesystem.FileSystemMetaData in project ats-framework by Axway.

the class FileModtimeRule method performMatch.

@Override
public boolean performMatch(MetaData metaData) throws RbvException {
    boolean actualResult = false;
    if (metaData instanceof FileSystemMetaData) {
        //get the file from the meta data
        FilePackage file = ((FileSystemMetaData) metaData).getFilePackage();
        try {
            //get destination file's size
            long destModtime = file.getModTime();
            actualResult = destModtime == this.srcModtime;
        } catch (PackageException pe) {
            throw new RbvStorageException(pe);
        }
    }
    return actualResult;
}
Also used : FilePackage(com.axway.ats.action.objects.FilePackage) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData)

Aggregations

FileSystemMetaData (com.axway.ats.rbv.filesystem.FileSystemMetaData)47 BaseTest (com.axway.ats.rbv.BaseTest)43 Test (org.junit.Test)43 MetaData (com.axway.ats.rbv.MetaData)42 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 FilePackage (com.axway.ats.action.objects.FilePackage)13 FilePathRule (com.axway.ats.rbv.filesystem.rules.FilePathRule)10 FileMd5Rule (com.axway.ats.rbv.filesystem.rules.FileMd5Rule)9 FileSizeRule (com.axway.ats.rbv.filesystem.rules.FileSizeRule)9 FileModtimeRule (com.axway.ats.rbv.filesystem.rules.FileModtimeRule)5 FilePermRule (com.axway.ats.rbv.filesystem.rules.FilePermRule)5 PackageException (com.axway.ats.action.objects.model.PackageException)4 FileContentRule (com.axway.ats.rbv.filesystem.rules.FileContentRule)4 RbvStorageException (com.axway.ats.rbv.model.RbvStorageException)3 FileSystemFolder (com.axway.ats.rbv.filesystem.FileSystemFolder)1 FileSystemFolderSearchTerm (com.axway.ats.rbv.filesystem.FileSystemFolderSearchTerm)1 FileFolderRule (com.axway.ats.rbv.filesystem.rules.FileFolderRule)1 AndRuleOperation (com.axway.ats.rbv.rules.AndRuleOperation)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1