Search in sources :

Example 16 with Monitor

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

the class Test_SimpleMonitorListener method verifyNoMatch_ButHasAMatch.

@Test
public void verifyNoMatch_ButHasAMatch() throws RbvException {
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value00", MatchRelation.EQUALS, "verifyNoMatch_ButHasAMatch", true);
    Monitor monitor = new Monitor("monitor1", matchable, dbRule, pollingParams, false, true, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor);
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    long before = System.currentTimeMillis();
    assertFalse(listener.evaluateMonitors(TIME_END_POLL));
    long after = System.currentTimeMillis();
    assertTrue(after - before >= TIME_BEFORE_END_POLL);
}
Also used : Monitor(com.axway.ats.rbv.Monitor) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Test(org.junit.Test)

Example 17 with Monitor

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

the class Test_SimpleMonitorListener method evaluateMonitorsOneMonitorPositiveRunTwice.

@Test
public void evaluateMonitorsOneMonitorPositiveRunTwice() throws RbvException {
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value10", MatchRelation.EQUALS, "evaluateMonitorsOneMonitorPositiveRunTwice", true);
    Monitor monitor = new Monitor("monitor1", matchable, dbRule, pollingParams, true, false, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor);
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    assertTrue(listener.evaluateMonitors(TIME_END_POLL));
    assertTrue(listener.evaluateMonitors(TIME_END_POLL));
}
Also used : Monitor(com.axway.ats.rbv.Monitor) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Test(org.junit.Test)

Example 18 with Monitor

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

the class VerificationSkeleton method verify.

/**
     * Verify that all rules match using the given expected result
     * 
     * @param expectedResult the expected result
     * @param endOnFirstMatch end on first match or keep testing until all polling attempts are exhausted
     * @param endOnFirstFailure end or first failure or keep testing until all polling attempts are exhausted
     * 
     * @return the matched meta data
     * @throws RbvException on error doing the verifications
     */
protected List<MetaData> verify(boolean expectedResult, boolean endOnFirstMatch, boolean endOnFirstFailure) throws RbvException {
    try {
        this.executor.setRootRule(this.rootRule);
        applyConfigurationSettings();
        Monitor monitor = new Monitor(getMonitorName(), this.folder, this.executor, new PollingParameters(pollingInitialDelay, pollingInterval, pollingAttempts), expectedResult, endOnFirstMatch, endOnFirstFailure);
        ArrayList<Monitor> monitors = new ArrayList<Monitor>();
        monitors.add(monitor);
        SimpleMonitorListener monitorListener = new SimpleMonitorListener(monitors);
        boolean evaluationPassed = monitorListener.evaluateMonitors(pollingTimeout);
        String lastRuleName = monitor.getLastRuleName();
        String classSimpleName = getClass().getSimpleName();
        if ("FileSystemVerification".equals(classSimpleName) && !expectedResult) {
            lastRuleName = "File do exist!";
        } else if (lastRuleName != null) {
            lastRuleName = "Rule failed '" + lastRuleName + "'!";
        } else {
            if ("DbVerification".equals(classSimpleName)) {
                lastRuleName = "Database connection problem!";
            } else if ("FileSystemVerification".equals(classSimpleName) && expectedResult) {
                lastRuleName = "File does not exist!";
            } else {
                lastRuleName = "Server connection problem!";
            }
        }
        if (evaluationPassed == false) {
            throw new RbvVerificationException("Verification failed. " + lastRuleName);
        }
        return monitor.getAllMatchedMetaData();
    } catch (ConfigurationException ce) {
        throw new RbvException("RBV configuration error", ce);
    }
}
Also used : Monitor(com.axway.ats.rbv.Monitor) RbvVerificationException(com.axway.ats.rbv.model.RbvVerificationException) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) RbvException(com.axway.ats.rbv.model.RbvException) ArrayList(java.util.ArrayList) PollingParameters(com.axway.ats.rbv.PollingParameters)

Example 19 with Monitor

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

the class Test_SimpleMonitorListener method evaluateMonitorsMultipleMonitorsEndOnFirstMatchPositive.

@Test
public void evaluateMonitorsMultipleMonitorsEndOnFirstMatchPositive() throws RbvException {
    DbStorage storage = new DbStorage(new MockDbProvider());
    Matchable matchable1 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable2 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable3 = storage.getFolder(new DbSearchTerm(""));
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value10", MatchRelation.EQUALS, "evaluateMonitorsMultipleMonitorsEndOnFirstMatchPositive", true);
    Monitor monitor1 = new Monitor("monitor1", matchable1, dbRule, pollingParams, true, true, false);
    Monitor monitor2 = new Monitor("monitor2", matchable2, dbRule, pollingParams, true, true, false);
    Monitor monitor3 = new Monitor("monitor3", matchable3, dbRule, pollingParams, true, true, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor1);
    monitors.add(monitor2);
    monitors.add(monitor3);
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    assertTrue(listener.evaluateMonitors(TIME_END_POLL));
}
Also used : Monitor(com.axway.ats.rbv.Monitor) DbStorage(com.axway.ats.rbv.db.DbStorage) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) DbSearchTerm(com.axway.ats.rbv.db.DbSearchTerm) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) MockDbProvider(com.axway.ats.rbv.db.MockDbProvider) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Matchable(com.axway.ats.rbv.storage.Matchable) Test(org.junit.Test)

Example 20 with Monitor

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

the class Test_SimpleMonitorListener method monitorGetFirstMachingMetaData.

@Test
public void monitorGetFirstMachingMetaData() throws RbvException {
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value10", MatchRelation.EQUALS, "monitorGetFirstMachingMetaData", true);
    Monitor monitor = new Monitor("monitor1", matchable, dbRule, pollingParams, true, true, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor);
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    listener.evaluateMonitors(TIME_END_POLL);
    assertEquals("value10", monitor.getFirstMatchedMetaData().getProperty("key1"));
}
Also used : Monitor(com.axway.ats.rbv.Monitor) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Test(org.junit.Test)

Aggregations

Monitor (com.axway.ats.rbv.Monitor)34 SimpleMonitorListener (com.axway.ats.rbv.SimpleMonitorListener)33 DbFieldsRule (com.axway.ats.rbv.db.rules.DbFieldsRule)33 DbStringFieldRule (com.axway.ats.rbv.db.rules.DbStringFieldRule)33 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)33 DbSearchTerm (com.axway.ats.rbv.db.DbSearchTerm)8 DbStorage (com.axway.ats.rbv.db.DbStorage)8 MockDbProvider (com.axway.ats.rbv.db.MockDbProvider)8 Matchable (com.axway.ats.rbv.storage.Matchable)8 PollingParameters (com.axway.ats.rbv.PollingParameters)4 MetaData (com.axway.ats.rbv.MetaData)2 ConfigurationException (com.axway.ats.config.exceptions.ConfigurationException)1 RbvException (com.axway.ats.rbv.model.RbvException)1 RbvVerificationException (com.axway.ats.rbv.model.RbvVerificationException)1