Search in sources :

Example 1 with ConfigurationException

use of com.axway.ats.config.exceptions.ConfigurationException 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);
        // run the actual evaluation
        String evaluationProblem = new SimpleMonitorListener(monitors).evaluateMonitors(pollingTimeout);
        if (!StringUtils.isNullOrEmpty(evaluationProblem)) {
            throw new RbvVerificationException("Verification failed - " + monitor.getLastError());
        }
        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 2 with ConfigurationException

use of com.axway.ats.config.exceptions.ConfigurationException in project ats-framework by Axway.

the class TestHarnessConfigurator method reloadData.

@Override
protected void reloadData() {
    String propertyDataProviderString = getProperty(PROPERTY_DATA_PROVIDER);
    try {
        propertyDataProvider = Enum.valueOf(DataProviderType.class, propertyDataProviderString.toUpperCase());
    } catch (IllegalArgumentException iae) {
        throw new ConfigurationException("Data provider '" + propertyDataProviderString + "' is not supported");
    }
    propertyTestcasesRoot = getProperty(PROPERTY_TEST_CASES_DIRECTORY);
}
Also used : ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) DataProviderType(com.axway.ats.harness.testng.dataproviders.DataProviderType)

Example 3 with ConfigurationException

use of com.axway.ats.config.exceptions.ConfigurationException in project ats-framework by Axway.

the class ConfigurationResource method loadFromXmlFile.

public void loadFromXmlFile(InputStream resourceStream, String resourceIdentifier) {
    try {
        DOMParser parser = new DOMParser();
        // Required settings from the DomParser
        // otherwise
        parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
        parser.parse(new InputSource(resourceStream));
        Document doc = parser.getDocument();
        Element rootElement = doc.getDocumentElement();
        // cleanup the properties
        properties.clear();
        // init the current element path
        LinkedList<String> currentElementPath = new LinkedList<String>();
        // start reading the DOM
        NodeList rootElementChildren = rootElement.getChildNodes();
        for (int i = 0; i < rootElementChildren.getLength(); i++) {
            Node rootElementChild = rootElementChildren.item(i);
            if (rootElementChild.getNodeType() == Node.ELEMENT_NODE) {
                readXmlElement(currentElementPath, (Element) rootElementChild);
            }
        }
    } catch (SAXException e) {
        throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'", e);
    } catch (IOException ioe) {
        throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'", ioe);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) LinkedList(java.util.LinkedList) SAXException(org.xml.sax.SAXException) ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) DOMParser(org.apache.xerces.parsers.DOMParser)

Example 4 with ConfigurationException

use of com.axway.ats.config.exceptions.ConfigurationException in project ats-framework by Axway.

the class ConfigurationRepository method createConfigurationResourceFromStream.

/**
 * Create a new configuration resource based on a given configuration file
 *
 * @param configFile the configuration file
 * @return a config resource based on the file type
 */
private ConfigurationResource createConfigurationResourceFromStream(InputStream resourceStream, String resourceIdentifier) {
    ConfigurationResource configResource;
    if (resourceIdentifier.endsWith(".xml")) {
        configResource = new ConfigurationResource();
        configResource.loadFromXmlFile(resourceStream, resourceIdentifier);
        return configResource;
    } else if (resourceIdentifier.endsWith(".properties")) {
        configResource = new ConfigurationResource();
        configResource.loadFromPropertiesFile(resourceStream, resourceIdentifier);
        return configResource;
    } else {
        throw new ConfigurationException("Not supported file extension. We expect either 'xml' or 'properties': " + resourceIdentifier);
    }
}
Also used : ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException)

Example 5 with ConfigurationException

use of com.axway.ats.config.exceptions.ConfigurationException in project ats-framework by Axway.

the class BoxesMap method setPropertyUsingSetter.

/**
 * Try to find a setter for this property and set it
 *
 * @param box the box instance
 * @param key the property key
 * @param value the property value
 * @return boolean if setter was found and successfully invoked, false if not suitable
 * setter was found
 */
private boolean setPropertyUsingSetter(String boxName, Box box, String key, String value) {
    Method[] boxClassMethods = box.getClass().getDeclaredMethods();
    for (Method boxClassMethod : boxClassMethods) {
        String methodName = boxClassMethod.getName();
        String setterName = "set" + key;
        // user errors in configuration files
        if (!methodName.equalsIgnoreCase(setterName)) {
            continue;
        }
        // check if the setter has the right number of arguments
        Class<?>[] parameterTypes = boxClassMethod.getParameterTypes();
        if (parameterTypes.length != 1 || parameterTypes[0] != String.class) {
            continue;
        }
        String methodDescription = boxName + "." + boxClassMethod.getName() + "( '" + value + "' )";
        try {
            boxClassMethod.invoke(box, new Object[] { value });
            return true;
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException("Could not invoke setter " + methodDescription, e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Could not invoke setter " + methodDescription, e);
        } catch (InvocationTargetException e) {
            throw new ConfigurationException("Could not invoke setter " + methodDescription, e);
        }
    }
    return false;
}
Also used : ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConfigurationException (com.axway.ats.config.exceptions.ConfigurationException)5 DataProviderType (com.axway.ats.harness.testng.dataproviders.DataProviderType)1 Monitor (com.axway.ats.rbv.Monitor)1 PollingParameters (com.axway.ats.rbv.PollingParameters)1 SimpleMonitorListener (com.axway.ats.rbv.SimpleMonitorListener)1 RbvException (com.axway.ats.rbv.model.RbvException)1 RbvVerificationException (com.axway.ats.rbv.model.RbvVerificationException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 DOMParser (org.apache.xerces.parsers.DOMParser)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1