Search in sources :

Example 26 with CucumberException

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();
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SingleValueConverter(cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) CucumberException(cucumber.runtime.CucumberException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with CucumberException

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));
    }
}
Also used : InputStream(java.io.InputStream) CucumberException(cucumber.runtime.CucumberException) File(java.io.File)

Example 28 with CucumberException

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);
    }
}
Also used : IOException(java.io.IOException) CucumberException(cucumber.runtime.CucumberException)

Example 29 with CucumberException

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);
    }
}
Also used : Matcher(java.util.regex.Matcher) IOException(java.io.IOException) CucumberException(cucumber.runtime.CucumberException) URISyntaxException(java.net.URISyntaxException)

Example 30 with CucumberException

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) CucumberException(cucumber.runtime.CucumberException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

CucumberException (cucumber.runtime.CucumberException)37 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)4 IOException (java.io.IOException)4 Step (gherkin.formatter.model.Step)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 StepdefBody (cucumber.api.java8.StepdefBody)2 RuntimeOptionsFactory (cucumber.runtime.RuntimeOptionsFactory)2 Resource (cucumber.runtime.io.Resource)2 Java8StepDefinition (cucumber.runtime.java.Java8StepDefinition)2 AssetManager (android.content.res.AssetManager)1 DataTable (cucumber.api.DataTable)1 PendingException (cucumber.api.PendingException)1 Scenario (cucumber.api.Scenario)1 After (cucumber.api.java.After)1 Cucumber (cucumber.api.junit.Cucumber)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1