Search in sources :

Example 1 with SystemException

use of de.simpleworks.staf.commons.exceptions.SystemException in project staf by simpleworks-gmbh.

the class Mapper method getJsonString.

public static final String getJsonString(final String element) throws SystemException {
    if (Convert.isEmpty(element)) {
        throw new IllegalArgumentException("element can't be null or empty.");
    }
    final LinkedHashMap<String, String> map = JsonPath.read(element, Mapper.PATH_INSTANCE_FIRST);
    if (map == null) {
        throw new SystemException(String.format("can't find element(s) for path '%s' in json: '%s'.", Mapper.PATH_INSTANCE_FIRST, element));
    }
    final JSONObject json = new JSONObject();
    map.keySet().forEach(key -> json.appendField(key, map.get(key)));
    return json.toJSONString();
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) JSONObject(net.minidev.json.JSONObject)

Example 2 with SystemException

use of de.simpleworks.staf.commons.exceptions.SystemException in project staf by simpleworks-gmbh.

the class STAFElement method pressAnyKey.

/**
 * @throws SystemException
 * @brief actions on the WebElement itself
 */
private boolean pressAnyKey(final Keys key) {
    if (key == null) {
        throw new IllegalArgumentException("key can't be null.");
    }
    boolean result = false;
    try {
        final WebElement webElement = getWebElement();
        webElement.sendKeys(key);
        result = true;
    } catch (final Exception ex) {
        logger.error(String.format("can't press key: '%s'.", key), ex);
    // FIXME throw an exception.
    }
    return result;
}
Also used : WebElement(org.openqa.selenium.WebElement) SystemException(de.simpleworks.staf.commons.exceptions.SystemException)

Example 3 with SystemException

use of de.simpleworks.staf.commons.exceptions.SystemException in project staf by simpleworks-gmbh.

the class PropertiesReader method loadProperties.

private static Properties loadProperties(final File file) throws SystemException {
    if (file == null) {
        throw new IllegalArgumentException("file can't be null.");
    }
    if (!file.exists()) {
        throw new IllegalArgumentException(String.format("file at '%s' does not exist.", file.getAbsolutePath()));
    }
    final Properties result = UtilsIO.readProperties(file);
    try {
        result.keySet().stream().forEach(k -> {
            final String key = (String) k;
            final String value = (String) result.get(key);
            if (Convert.isEmpty(System.getProperty(key, null))) {
                if (PropertiesReader.logger.isDebugEnabled()) {
                    PropertiesReader.logger.debug(String.format("Set Property '%s' with value '%s'.", key, value));
                }
                System.setProperty(key, value);
            }
        });
    } catch (final Exception ex) {
        final String msg = String.format("can't set system properties from file '%s'.", file);
        PropertiesReader.logger.error(msg, ex);
        throw new SystemException(msg);
    }
    return result;
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) Properties(java.util.Properties) SystemException(de.simpleworks.staf.commons.exceptions.SystemException)

Example 4 with SystemException

use of de.simpleworks.staf.commons.exceptions.SystemException in project staf by simpleworks-gmbh.

the class PropertiesReader method setField.

private void setField(final Object ob, final Field field, final String value) throws SystemException {
    if (ob == null) {
        throw new IllegalArgumentException("ob can't be null.");
    }
    if (field == null) {
        throw new IllegalArgumentException("field can't be null.");
    }
    try {
        field.setAccessible(true);
        final Class<?> type = field.getType();
        if ((field.getAnnotation(ClassPath.class) != null)) {
            field.set(ob, loadClass(type, value));
        } else {
            // here.
            if (int.class.equals(type)) {
                field.set(ob, Integer.valueOf(value));
            } else if (double.class.equals(type)) {
                field.set(ob, Double.valueOf(value));
            } else if (boolean.class.equals(type)) {
                field.set(ob, Boolean.valueOf(value));
            } else if (float.class.equals(type)) {
                field.set(ob, Float.valueOf(value));
            } else if (long.class.equals(type)) {
                field.set(ob, Long.valueOf(value));
            } else if (String.class.equals(type)) {
                field.set(ob, value);
            } else if (Map.class.equals(type)) {
                field.set(ob, PropertiesReader.setMap(value));
            } else if (type.isEnum()) {
                final Object typeValue = UtilsEnum.getEnum(type, value);
                field.set(ob, typeValue);
            } else {
                throw new IllegalArgumentException(String.format("Cannot handle type: '%s', value '%s'.", type, value));
            }
        }
    } catch (final Exception ex) {
        final String msg = String.format("for object '%s': can't set field: '%s' to value: '%s'.", ob, field, value);
        PropertiesReader.logger.error(msg, ex);
        throw new SystemException(msg);
    }
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) SystemException(de.simpleworks.staf.commons.exceptions.SystemException)

Example 5 with SystemException

use of de.simpleworks.staf.commons.exceptions.SystemException in project staf by simpleworks-gmbh.

the class STAFTable method getRows.

public List<WebElement> getRows() {
    if (Convert.isEmpty(rows)) {
        final WebDriverWait wait = new WebDriverWait(getWebDriver(), getTimeout());
        wait.until(ExpectedConditions.visibilityOfElementLocated(getBy()));
        try {
            rows.addAll(getChildElements(By.tagName("tr")));
        } catch (final SystemException ex) {
            final String msg = "can't fetch rows.";
            STAFTable.logger.error(msg, ex);
            rows.clear();
        }
        if (STAFTable.logger.isDebugEnabled()) {
            STAFTable.logger.debug(String.format("Found %d rows", Integer.valueOf(rows.size())));
        }
    }
    return rows;
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Aggregations

SystemException (de.simpleworks.staf.commons.exceptions.SystemException)86 File (java.io.File)15 IOException (java.io.IOException)13 URISyntaxException (java.net.URISyntaxException)12 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)10 AsynchronousIssueRestClient (com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient)10 ArrayList (java.util.ArrayList)10 Issue (com.atlassian.jira.rest.client.api.domain.Issue)9 TestPlan (de.simpleworks.staf.commons.elements.TestPlan)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)8 URL (java.net.URL)8 Test (org.junit.jupiter.api.Test)8 Order (org.junit.jupiter.api.Order)7 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)7 TestCase (de.simpleworks.staf.commons.elements.TestCase)6 MapperTestcaseReport (de.simpleworks.staf.commons.mapper.report.MapperTestcaseReport)6 TestcaseReport (de.simpleworks.staf.commons.report.TestcaseReport)6 HashMap (java.util.HashMap)6 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)5