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();
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations