use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.
the class TableConverter method toMaps.
public <K, V> List<Map<K, V>> toMaps(DataTable dataTable, Type keyType, Type valueType) {
try {
xStream.setParameterInfo(parameterInfo);
SingleValueConverter keyConverter = xStream.getSingleValueConverter(keyType);
SingleValueConverter valueConverter = xStream.getSingleValueConverter(valueType);
if (keyConverter == null || valueConverter == null) {
throw new CucumberException(String.format("Can't convert DataTable to List<Map<%s,%s>>", keyType, valueType));
}
List<Map<K, V>> result = new ArrayList<Map<K, V>>();
List<String> keyStrings = dataTable.topCells();
List<K> keys = new ArrayList<K>();
for (String keyString : keyStrings) {
keys.add((K) keyConverter.fromString(keyString));
}
List<List<String>> valueRows = dataTable.cells(1);
for (List<String> valueRow : valueRows) {
Map<K, V> map = new LinkedHashMap<K, V>();
int i = 0;
for (String cell : valueRow) {
map.put(keys.get(i), (V) valueConverter.fromString(cell));
i++;
}
result.add(Collections.unmodifiableMap(map));
}
return Collections.unmodifiableList(result);
} finally {
xStream.unsetParameterInfo();
}
}
use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.
the class HTMLFormatter method copyReportFiles.
private void copyReportFiles() {
for (String textAsset : TEXT_ASSETS) {
InputStream textAssetStream = getClass().getResourceAsStream(textAsset);
if (textAssetStream == null) {
throw new CucumberException("Couldn't find " + textAsset + ". Is cucumber-html on your classpath? Make sure you have the right version.");
}
String baseName = new File(textAsset).getName();
writeStreamAndClose(textAssetStream, reportFileOutputStream(baseName));
}
}
use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.
the class HTMLFormatter method writeStreamAndClose.
private void writeStreamAndClose(InputStream in, OutputStream out) {
byte[] buffer = new byte[16 * 1024];
try {
int len = in.read(buffer);
while (len != -1) {
out.write(buffer, 0, len);
len = in.read(buffer);
}
out.close();
} catch (IOException e) {
throw new CucumberException("Unable to write to report file item: ", e);
}
}
use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.
the class PluginFactory method create.
public Object create(String pluginString) {
Matcher pluginWithFile = PLUGIN_WITH_FILE_PATTERN.matcher(pluginString);
String pluginName;
String path = null;
if (pluginWithFile.matches()) {
pluginName = pluginWithFile.group(1);
path = pluginWithFile.group(2);
} else {
pluginName = pluginString;
}
Class pluginClass = pluginClass(pluginName);
try {
return instantiate(pluginString, pluginClass, path);
} catch (IOException e) {
throw new CucumberException(e);
} catch (URISyntaxException e) {
throw new CucumberException(e);
}
}
use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.
the class TestNGFormatter method done.
@Override
public void done() {
try {
results.setAttribute("total", String.valueOf(getElementsCountByAttribute(suite, "status", ".*")));
results.setAttribute("passed", String.valueOf(getElementsCountByAttribute(suite, "status", "PASS")));
results.setAttribute("failed", String.valueOf(getElementsCountByAttribute(suite, "status", "FAIL")));
results.setAttribute("skipped", String.valueOf(getElementsCountByAttribute(suite, "status", "SKIP")));
suite.setAttribute("name", TestNGFormatter.class.getName());
suite.setAttribute("duration-ms", getTotalDuration(suite.getElementsByTagName("test-method")));
test.setAttribute("name", TestNGFormatter.class.getName());
test.setAttribute("duration-ms", getTotalDuration(suite.getElementsByTagName("test-method")));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult streamResult = new StreamResult(writer);
DOMSource domSource = new DOMSource(document);
transformer.transform(domSource, streamResult);
} catch (TransformerException e) {
throw new CucumberException("Error transforming report.", e);
}
}
Aggregations