Search in sources :

Example 26 with MetaData

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

the class Test_HeaderRule method isMatchWrongMetaData.

@Test(expected = MetaDataIncorrectException.class)
public void isMatchWrongMetaData() throws RbvException {
    HeaderRule rule = new HeaderRule("Sender", "infos1.mercatoloterie@gmail.com", HeaderMatchMode.FIND, "isMatchEmptyMetaData", true);
    metaData = new MetaData();
    assertFalse(rule.isMatch(metaData));
}
Also used : HeaderRule(com.axway.ats.rbv.imap.rules.HeaderRule) ImapMetaData(com.axway.ats.rbv.imap.ImapMetaData) MetaData(com.axway.ats.rbv.MetaData) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 27 with MetaData

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

the class DbFolder method refresh.

private void refresh() throws RbvException {
    newMetaDataMap = new HashMap<String, MetaData>();
    // store the current meta data map and clear the map holding all meta data
    // this way we will be able to detect any changes including added and removed
    // meta data
    HashMap<String, MetaData> oldMetaDataMap = allMetaDataMap;
    allMetaDataMap = new HashMap<String, MetaData>();
    log.debug("Run DB query '" + this.searchQuery.getQuery() + "'");
    DbRecordValuesList[] queryResults;
    try {
        queryResults = dbProvider.select(this.searchQuery);
    } catch (DbException dbe) {
        throw new RbvException(dbe);
    }
    if (queryResults != null) {
        for (DbRecordValuesList queryResult : queryResults) {
            DbMetaData currentData = new DbMetaData();
            StringBuffer metaDataHash = new StringBuffer();
            for (DbRecordValue recordValue : queryResult) {
                DbMetaDataKey key = new DbMetaDataKey(recordValue.getDbColumn());
                Object value = recordValue.getValue();
                currentData.putProperty(key.toString(), value);
                // calculate the hash
                metaDataHash.append(key.toString());
                metaDataHash.append(recordValue.getValueAsString());
            }
            try {
                // compute MD5 so we don't keep the whole StringBuffer in memory
                MessageDigest metaDataHashDigest = MessageDigest.getInstance("MD5");
                String metaDataSum = new String(metaDataHashDigest.digest(metaDataHash.toString().getBytes()));
                if (!oldMetaDataMap.containsKey(metaDataSum)) {
                    newMetaDataMap.put(metaDataSum, currentData);
                }
                // always put the record in the map holding all meta data
                allMetaDataMap.put(metaDataSum, currentData);
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e);
            }
        }
        didPollingOccured = true;
    }
}
Also used : RbvException(com.axway.ats.rbv.model.RbvException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DbException(com.axway.ats.core.dbaccess.exceptions.DbException) DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) DbRecordValue(com.axway.ats.core.dbaccess.DbRecordValue) MetaData(com.axway.ats.rbv.MetaData) MessageDigest(java.security.MessageDigest)

Example 28 with MetaData

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

the class Test_SnapshotExecutor method setUp.

/**
 * Build up {@link MetaData} to use in the test
 * @throws IOException
 * @throws RbvException
 */
@Before
public void setUp() throws IOException, RbvException {
    this.snapshot = new ArrayList<MetaData>();
    this.newData = new ArrayList<MetaData>();
    DbMetaData meta = new DbMetaData();
    meta.putProperty(META_KEY_1, META_VALUE_1 + 1);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 1);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 1);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 1);
    this.snapshot.add(meta);
    this.newData.add(meta);
    meta = new DbMetaData();
    meta.putProperty(META_KEY_1, META_VALUE_1 + 2);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 2);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 2);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 2);
    this.snapshot.add(meta);
    meta = new DbMetaData();
    meta.putProperty(META_KEY_1, META_VALUE_1 + 3);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 3);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 3);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 3);
    this.snapshot.add(meta);
    this.newData.add(meta);
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) DbMetaData(com.axway.ats.rbv.db.DbMetaData) MetaData(com.axway.ats.rbv.MetaData) Before(org.junit.Before)

Example 29 with MetaData

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

the class Test_SnapshotExecutor method matchGlobalRuleAndSnapshotRulesPositive.

/**
 * UnitTest
 * @throws RbvException
 */
@Test
public void matchGlobalRuleAndSnapshotRulesPositive() throws RbvException {
    this.newData = new ArrayList<MetaData>();
    DbMetaData meta;
    meta = new DbMetaData();
    meta.putProperty(META_KEY_1, MOD_META_VALUE_1 + 35);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 1);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 1);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 1);
    this.newData.add(meta);
    meta = new DbMetaData();
    meta.putProperty(META_KEY_1, MOD_META_VALUE_1 + 33);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 2);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 2);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 2);
    this.newData.add(meta);
    meta = new DbMetaData();
    meta.putProperty(META_KEY_1, MOD_META_VALUE_1 + 33);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 3);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 3);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 3);
    this.newData.add(meta);
    DbStringFieldRule globalRule = new DbStringFieldRule(TABLE_NAME, COLUMN_NAME_1, MOD_META_VALUE_1 + 33, DbStringFieldRule.MatchRelation.EQUALS, "global_rule", true);
    DbStringFieldRule keyRule = new DbStringFieldRule(TABLE_NAME, COLUMN_NAME_2, META_VALUE_2 + 1, DbStringFieldRule.MatchRelation.EQUALS, "key_rule", true);
    DbStringFieldRule matchingRule = new DbStringFieldRule(TABLE_NAME, COLUMN_NAME_1, MOD_META_VALUE_1 + 35, DbStringFieldRule.MatchRelation.EQUALS, "match_metakey_1", true);
    SnapshotExecutor executor = new SnapshotExecutor(this.snapshot);
    executor.addRule(keyRule, matchingRule);
    executor.setRootRule(globalRule);
    List<MetaData> result = executor.evaluate(this.newData);
    assertTrue(result != null && !result.isEmpty());
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) DbMetaData(com.axway.ats.rbv.db.DbMetaData) MetaData(com.axway.ats.rbv.MetaData) SnapshotExecutor(com.axway.ats.rbv.executors.SnapshotExecutor) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 30 with MetaData

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

the class Test_SnapshotExecutor method matchDifferentSizeOfPropertiesCount.

/**
 * UnitTest
 * @throws RbvException
 */
@Test
public void matchDifferentSizeOfPropertiesCount() throws RbvException {
    MetaData meta = new DbMetaData();
    meta.putProperty(META_KEY_1, MOD_META_VALUE_1 + 2);
    meta.putProperty(META_KEY_2, META_VALUE_2 + 2);
    meta.putProperty(META_KEY_3, META_VALUE_3 + 2);
    meta.putProperty(META_KEY_4, META_VALUE_4 + 2);
    meta.putProperty(TABLE_NAME + ".columnfive", META_VALUE_4 + 2);
    this.newData.add(meta);
    DbStringFieldRule keyRule = new DbStringFieldRule(TABLE_NAME, COLUMN_NAME_2, META_VALUE_2 + 2, DbStringFieldRule.MatchRelation.EQUALS, "key_rule", true);
    DbStringFieldRule matchingRule = new DbStringFieldRule(TABLE_NAME, COLUMN_NAME_1, MOD_META_VALUE_1 + 2, DbStringFieldRule.MatchRelation.EQUALS, "match_metakey_1", true);
    SnapshotExecutor executor = new SnapshotExecutor(this.snapshot);
    executor.addRule(keyRule, matchingRule);
    List<MetaData> result = executor.evaluate(this.newData);
    assertTrue(result == null || result.isEmpty());
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) DbMetaData(com.axway.ats.rbv.db.DbMetaData) MetaData(com.axway.ats.rbv.MetaData) SnapshotExecutor(com.axway.ats.rbv.executors.SnapshotExecutor) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) BaseTest(com.axway.ats.rbv.BaseTest) 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