Search in sources :

Example 41 with MetaData

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

the class Test_FileSystemFolder method getAllMetadataNoSuchEntity.

@Test
public void getAllMetadataNoSuchEntity() throws Exception {
    // constructors
    expectNew(SystemOperations.class, "localhost:0000").andReturn(systemOperations);
    expectNew(FileSystemOperations.class, "localhost:0000").andReturn(fileSystemOperations);
    // open()
    expect(systemOperations.getOperatingSystemType()).andReturn(OperatingSystemType.SOLARIS);
    // getAllMetaData()
    expect(fileSystemOperations.findFiles("some.path/", ".*", true, true, false)).andReturn(new String[0]);
    replayAll();
    FileSystemFolder folder = new FileSystemFolder("localhost:0000", "some.path", null, true, false);
    folder.open();
    assertEquals(folder.getAllMetaData(), new ArrayList<MetaData>());
    verifyAll();
}
Also used : FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) SystemOperations(com.axway.ats.action.system.SystemOperations) MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) FileSystemFolder(com.axway.ats.rbv.filesystem.FileSystemFolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 42 with MetaData

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

the class Test_FileSystemFolder method getAllMetadataExceptionExists.

@Test(expected = RbvException.class)
public void getAllMetadataExceptionExists() throws Exception {
    // constructor
    expectNew(FileSystemOperations.class, "localhost:0000").andThrow(new RbvException("Test"));
    replayAll();
    FileSystemFolder folder = new FileSystemFolder("localhost:0000", "some.path", null, true, false);
    folder.open();
    assertEquals(folder.getAllMetaData(), new ArrayList<MetaData>());
    verifyAll();
}
Also used : RbvException(com.axway.ats.rbv.model.RbvException) MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) FileSystemFolder(com.axway.ats.rbv.filesystem.FileSystemFolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 43 with MetaData

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

the class SnapshotExecutor method snapshotMatch.

// locate this piece of MetaData in the snapshot
private boolean snapshotMatch(MetaData newMeta, List<String> excludedKeys) throws RbvException {
    // iterate over all of the entries of the snapshot
    for (Iterator<MetaData> iterator = this.snapshot.iterator(); iterator.hasNext(); ) {
        MetaData metaData = iterator.next();
        boolean isMatch = true;
        if (!checkPropertiesMapping(metaData, newMeta)) {
            // properties then they should not be matched
            continue;
        }
        // compare their values to the ones supplied by the new MetaData
        for (String value : metaData.getKeys()) {
            // check if this key should be evaluated at all
            if (shouldEvaluateKey(value, excludedKeys)) {
                if (!compare(metaData.getProperty(value), newMeta.getProperty(value))) {
                    isMatch = false;
                }
            }
        }
        // if the current snapshot entry matches the new MetaData
        if (isMatch) {
            iterator.remove();
            log.debug("Matched meta data: " + metaData);
            return true;
        }
    }
    log.debug(UNSUCCESSFUL_SNAPSHOT_MATCH);
    log.debug("--- Debug dump --- ");
    log.debug("Metadata contents : " + newMeta);
    return false;
}
Also used : MetaData(com.axway.ats.rbv.MetaData)

Example 44 with MetaData

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

the class FileSystemFolder method getAllMetaData.

public List<MetaData> getAllMetaData() throws RbvException {
    // first check if the folder is already open
    if (!isOpen) {
        throw new MatchableNotOpenException("File system folder is not open");
    }
    newMetaData.clear();
    if (fileName == null) {
        fileName = ".*";
        isRegExp = true;
    }
    HashMap<String, MetaData> tempMetaData = new HashMap<String, MetaData>();
    // fetch dir contents recursively
    String[] fileList;
    try {
        fileList = this.fileSystemOperations.findFiles(path, fileName, isRegExp, true, includeSubDirs);
    } catch (Exception e) {
        final String notExistMessageSuffix = "does not exist or is not a folder";
        if ((e.getMessage() != null && e.getMessage().endsWith(notExistMessageSuffix)) || (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().endsWith(notExistMessageSuffix))) {
            log.warn(getDescription() + " does not exist, skipping to next poll attempt");
            return new ArrayList<MetaData>();
        }
        throw new RbvException("Unable to list the contents of " + path, e);
    }
    if (fileList != null) {
        for (String fileName : fileList) {
            try {
                FilePackage file = new FilePackage(atsAgent, fileName.trim(), osType);
                MetaData metaData = new FileSystemMetaData(file);
                // The way files are compared is by combining their name+path,
                // modification time, user and group ID in a hash string
                String hashKey = file.getUniqueIdentifier();
                if (!allMetaData.containsKey(hashKey)) {
                    newMetaData.add(metaData);
                }
                tempMetaData.put(hashKey, metaData);
            } catch (PackageException e) {
                // the creation of the package somehow failed - a simple explanation would be that
                // the filed was removed during the execution of this method or something similar;
                log.warn("Unable to build up metadata for " + fileName, e);
            // either way we need not throw an exception but only continue iterating
            }
        }
    }
    allMetaData.clear();
    allMetaData.putAll(tempMetaData);
    return new ArrayList<MetaData>(allMetaData.values());
}
Also used : MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) HashMap(java.util.HashMap) RbvException(com.axway.ats.rbv.model.RbvException) ArrayList(java.util.ArrayList) MatchableAlreadyOpenException(com.axway.ats.rbv.model.MatchableAlreadyOpenException) MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) FilePackage(com.axway.ats.action.objects.FilePackage) MetaData(com.axway.ats.rbv.MetaData) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 45 with MetaData

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

the class Test_MetaData method toStringNull.

@Test
public void toStringNull() throws RbvException {
    MetaData metaData = new MetaData();
    metaData.putProperty("test", null);
    assertEquals("{ test : null }", metaData.toString());
}
Also used : MetaData(com.axway.ats.rbv.MetaData) Test(org.junit.Test)

Aggregations

MetaData (com.axway.ats.rbv.MetaData)85 Test (org.junit.Test)74 BaseTest (com.axway.ats.rbv.BaseTest)71 FileSystemMetaData (com.axway.ats.rbv.filesystem.FileSystemMetaData)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)45 DbMetaData (com.axway.ats.rbv.db.DbMetaData)16 DbStringFieldRule (com.axway.ats.rbv.db.rules.DbStringFieldRule)15 SnapshotExecutor (com.axway.ats.rbv.executors.SnapshotExecutor)15 FileMd5Rule (com.axway.ats.rbv.filesystem.rules.FileMd5Rule)10 FilePathRule (com.axway.ats.rbv.filesystem.rules.FilePathRule)10 FileSizeRule (com.axway.ats.rbv.filesystem.rules.FileSizeRule)10 FilePackage (com.axway.ats.action.objects.FilePackage)9 ArrayList (java.util.ArrayList)7 FileModtimeRule (com.axway.ats.rbv.filesystem.rules.FileModtimeRule)6 FilePermRule (com.axway.ats.rbv.filesystem.rules.FilePermRule)6 ImapMetaData (com.axway.ats.rbv.imap.ImapMetaData)5 FileContentRule (com.axway.ats.rbv.filesystem.rules.FileContentRule)4 RbvException (com.axway.ats.rbv.model.RbvException)4 S3ObjectInfo (com.axway.ats.action.s3.S3ObjectInfo)3 FileSystemFolder (com.axway.ats.rbv.filesystem.FileSystemFolder)3