Skip to content

Commit

Permalink
Added configuration file to the Difido HTML report and the ability to…
Browse files Browse the repository at this point in the history
… replace error status with failure. issue #258
  • Loading branch information
itaiag committed Apr 4, 2016
1 parent ef21f55 commit ab0d0dc
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ runnerState.properties
log
myFile.txt
*.xml.versionsBackup
difido.properties
remoteDifido.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jsystem.extensions.report.difido.DifidoConfig.DifidoProperty;
import jsystem.extensions.report.html.ExtendLevelTestReporter;
import jsystem.framework.FrameworkOptions;
import jsystem.framework.JSystemProperties;
Expand Down Expand Up @@ -279,7 +280,13 @@ private static String getMachineName() {

@Override
public void addError(Test arg0, Throwable arg1) {
currentTest.setStatus(Status.error);
if (DifidoConfig.getInstance().getBoolean(DifidoProperty.errorsToFailures)) {
// We don't want errors in the report, so we will change each error
// to failure.
currentTest.setStatus(Status.failure);
} else {
currentTest.setStatus(Status.error);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package jsystem.extensions.report.difido;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;

/**
* Allows configuration of the Difido HTML report. This will affect the local
* and the remote reports.
*
* @author Itai Agmon
*
*/
class DifidoConfig {

private static final Logger log = Logger.getLogger(DifidoConfig.class.getName());

private static final String FILE_NAME = "difido.properties";

private static DifidoConfig instance;

private Properties properties;

static DifidoConfig getInstance() {
if (null == instance) {
instance = new DifidoConfig();
}
return instance;
}

private DifidoConfig() {
File configFile = new File(FILE_NAME);
if (!configFile.exists()) {
createDefaultConfigFile();
}
readConfigFile();
}

private void readConfigFile() {
properties = new Properties();
try (FileInputStream in = new FileInputStream(FILE_NAME)) {
properties.load(in);
} catch (IOException e) {
log.warning("Failed to read Difido configuration file");
}
}

private void createDefaultConfigFile() {
Properties properties = new Properties();
for (DifidoProperty prop : DifidoProperty.values()) {
properties.setProperty(prop.propName, prop.defaultValue != null ? prop.defaultValue.toString() : "");
}
try (FileOutputStream out = new FileOutputStream(FILE_NAME)) {
properties.store(out, "Difido report properties");

} catch (IOException e) {
log.warning("Failed to create default Difido properties file due to " + e.getMessage());
}

}

/**
* Get the value of the specified property. If the property was not found,
* it will return the default value.
*
* @param property
* @return property value from type string
*/
String getString(DifidoProperty property) {
String value = null;
if (properties.containsKey(property.getPropName())) {
value = properties.getProperty(property.getPropName());
} else {
value = property.getDefaultValue();
}
if (null == value) {
value = "";
}
return value.trim();
}

/**
* Get the value of the specified property. If the property was not found,
* it will return the default value.
*
* @param property
* @return property value from type boolean
*/
boolean getBoolean(DifidoProperty property) {
String value = getString(property);
return Boolean.parseBoolean(value);
}

enum DifidoProperty {
errorsToFailures("errors.to.failures", "false", "Replace each error with failure");

private String propName;

private String defaultValue;

private String description;

DifidoProperty(String propName, String defaultValue, String description) {
this.propName = propName;
this.defaultValue = defaultValue;
this.description = description;
}

protected String getPropName() {
return propName;
}

protected String getDefaultValue() {
return defaultValue;
}

protected String getDescription() {
return description;
}

}

}

0 comments on commit ab0d0dc

Please sign in to comment.