Search in sources :

Example 31 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class TimelineFormatter method copyFile.

private static void copyFile(InputStream source, File dest) throws CucumberException {
    OutputStream os = null;
    try {
        os = new FileOutputStream(dest);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = source.read(buffer)) > 0) {
            os.write(buffer, 0, length);
        }
    } catch (IOException e) {
        throw new CucumberException("Unable to write to report file item: ", e);
    } finally {
        closeQuietly(os);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CucumberException(io.cucumber.core.exception.CucumberException)

Example 32 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class TimelineFormatter method copyReportFiles.

private void copyReportFiles() {
    if (reportDir == null) {
        return;
    }
    File outputDir = new File(reportDir.getPath());
    for (String textAsset : TEXT_ASSETS) {
        InputStream textAssetStream = getClass().getResourceAsStream(textAsset);
        if (textAssetStream == null) {
            throw new CucumberException("Couldn't find " + textAsset);
        }
        String fileName = new File(textAsset).getName();
        copyFile(textAssetStream, new File(outputDir, fileName));
        closeQuietly(textAssetStream);
    }
}
Also used : InputStream(java.io.InputStream) CucumberException(io.cucumber.core.exception.CucumberException) File(java.io.File)

Example 33 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class JUnitFormatter method handleTestRunFinished.

private void handleTestRunFinished(TestRunFinished event) {
    try {
        Instant finished = event.getInstant();
        // set up a transformer
        rootElement.setAttribute("name", JUnitFormatter.class.getName());
        rootElement.setAttribute("failures", String.valueOf(rootElement.getElementsByTagName("failure").getLength()));
        rootElement.setAttribute("skipped", String.valueOf(rootElement.getElementsByTagName("skipped").getLength()));
        rootElement.setAttribute("errors", "0");
        rootElement.setAttribute("time", calculateTotalDurationString(Duration.between(started, finished)));
        TransformerFactory factory = TransformerFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        StreamResult result = new StreamResult(writer);
        DOMSource source = new DOMSource(document);
        transformer.transform(source, result);
        closeQuietly(writer);
    } catch (TransformerException e) {
        throw new CucumberException("Error while transforming.", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Instant(java.time.Instant) CucumberException(io.cucumber.core.exception.CucumberException) TransformerException(javax.xml.transform.TransformerException)

Example 34 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class JarUriFileSystemService method handleJarUriScheme.

private static CloseablePath handleJarUriScheme(URI uri) throws IOException, URISyntaxException {
    String[] parts = uri.toString().split(JAR_URI_SEPARATOR);
    // Regular jar schemes
    if (parts.length <= 2) {
        String jarUri = parts[0];
        String jarPath = parts.length == 2 ? parts[1] : "/";
        return open(new URI(jarUri), fileSystem -> fileSystem.getPath(jarPath));
    }
    // Spring boot jar scheme
    String jarUri = parts[0];
    String jarEntry = parts[1];
    String subEntry = parts[2];
    if (jarEntry.endsWith(JAR_FILE_SUFFIX)) {
        throw new CucumberException(nestedJarEntriesExplanation(uri));
    }
    return open(new URI(jarUri), fileSystem -> fileSystem.getPath(jarEntry + subEntry));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) URI(java.net.URI)

Example 35 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class OptionsFileParser method parseFeatureWithLinesFile.

static Collection<FeatureWithLines> parseFeatureWithLinesFile(Path path) {
    try {
        List<FeatureWithLines> featurePaths = new ArrayList<>();
        readAllLines(path).forEach(line -> {
            Matcher matcher = RERUN_PATH_SPECIFICATION.matcher(line);
            while (matcher.find()) {
                featurePaths.add(FeatureWithLines.parse(matcher.group(1)));
            }
        });
        return featurePaths;
    } catch (Exception e) {
        throw new CucumberException(format("Failed to parse '%s'", path), e);
    }
}
Also used : FeatureWithLines(io.cucumber.core.feature.FeatureWithLines) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) CucumberException(io.cucumber.core.exception.CucumberException) CucumberException(io.cucumber.core.exception.CucumberException)

Aggregations

CucumberException (io.cucumber.core.exception.CucumberException)39 Test (org.junit.jupiter.api.Test)28 Executable (org.junit.jupiter.api.function.Executable)19 StepDefinition (io.cucumber.core.backend.StepDefinition)12 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)12 Feature (io.cucumber.core.gherkin.Feature)11 Step (io.cucumber.core.gherkin.Step)11 Argument (io.cucumber.core.stepexpression.Argument)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)8 PluginOption (io.cucumber.core.options.PluginOption)5 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)4 IOException (java.io.IOException)3 URI (java.net.URI)3 Options (io.cucumber.core.backend.Options)2 DataTableType (io.cucumber.datatable.DataTableType)2 File (java.io.File)2 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2