From e69a092278ea0c63335d228233b187695e6436f6 Mon Sep 17 00:00:00 2001 From: Ian Moore Date: Tue, 28 Mar 2017 21:11:12 +0100 Subject: [PATCH] code cleanup and lib version updates --- core/pom.xml | 17 +- .../report/DefaultExecutionReportBuilder.java | 328 ------------------ .../substeps/report/DetailedJsonBuilder.java | 232 ------------- .../substeps/report/ExecutionStats.java | 236 ------------- .../substeps/report/ReportData.java | 75 ---- .../substeps/report/ScreenshotWriter.java | 76 ---- .../substeps/report/TestCounterSet.java | 61 ---- .../substeps/report/TestCounters.java | 152 -------- .../substeps/report/TreeJsonBuilder.java | 196 ----------- core/src/main/resources/templates/detail.vm | 38 -- .../main/resources/templates/report_frame.vm | 162 --------- .../main/resources/templates/summary.txt.vm | 42 --- .../org/substeps/report/ReportBuilder.scala | 67 +++- .../substeps/model/PatternMapTest.java | 2 +- .../DefaultExecutionReportBuilderTest.java | 307 ---------------- .../substeps/report/ExecutionStatsTest.java | 136 -------- .../runner/ExecutionNodeRunnerTest.java | 21 +- .../syntax/SubStepDefinitionParserTest.java | 7 +- .../MockStepImplementations.java | 3 +- pom.xml | 6 +- .../substeps/ant/SubStepsTask.java | 3 +- runner/Junit/pom.xml | 2 +- .../runner/BaseJunitFeatureRunnerTest.java | 22 +- .../runner/JunitFeatureRunnerTest.java | 62 ++-- runner/Maven/pom.xml | 22 +- .../glossary/SubstepsGlossaryMojo.java | 1 - .../mojo/runner/SubstepsRunnerMojoTest.java | 3 +- 27 files changed, 127 insertions(+), 2152 deletions(-) delete mode 100644 core/src/main/java/com/technophobia/substeps/report/DefaultExecutionReportBuilder.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/DetailedJsonBuilder.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/ExecutionStats.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/ReportData.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/ScreenshotWriter.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/TestCounterSet.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/TestCounters.java delete mode 100644 core/src/main/java/com/technophobia/substeps/report/TreeJsonBuilder.java delete mode 100644 core/src/main/resources/templates/detail.vm delete mode 100644 core/src/main/resources/templates/report_frame.vm delete mode 100644 core/src/main/resources/templates/summary.txt.vm delete mode 100644 core/src/test/java/com/technophobia/substeps/report/DefaultExecutionReportBuilderTest.java delete mode 100644 core/src/test/java/com/technophobia/substeps/report/ExecutionStatsTest.java diff --git a/core/pom.xml b/core/pom.xml index 41bcb09a..986b45e2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -38,11 +38,6 @@ test - - - com.thoughtworks.xstream - xstream - com.google.code.gson gson @@ -63,21 +58,15 @@ test - - velocity - velocity - 1.5 - - org.apache.commons commons-lang3 - 3.4 + 3.5 commons-io commons-io - 2.4 + 2.5 joda-time @@ -113,7 +102,7 @@ org.mockito - mockito-all + mockito-core diff --git a/core/src/main/java/com/technophobia/substeps/report/DefaultExecutionReportBuilder.java b/core/src/main/java/com/technophobia/substeps/report/DefaultExecutionReportBuilder.java deleted file mode 100644 index 8cbfb1eb..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/DefaultExecutionReportBuilder.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.google.common.io.Files; -import com.technophobia.substeps.execution.ExecutionResult; -import com.technophobia.substeps.execution.node.ExecutionNode; -import com.technophobia.substeps.execution.node.RootNode; -import com.technophobia.substeps.helper.AssertHelper; -import com.technophobia.substeps.model.exception.SubstepsException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.exception.MethodInvocationException; -import org.apache.velocity.exception.ParseErrorException; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.net.JarURLConnection; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -/** - * @author ian - */ -public class DefaultExecutionReportBuilder extends ExecutionReportBuilder { - - private final Logger log = LoggerFactory.getLogger(DefaultExecutionReportBuilder.class); - - private final Properties velocityProperties = new Properties(); - - public static final String FEATURE_REPORT_FOLDER = "feature_report"; - private static final String SCREENSHOT_FOLDER = "screenshots"; - public static final String JSON_DATA_FILENAME = "report_data.json"; - public static final String JSON_DETAIL_DATA_FILENAME = "detail_data.js"; - - private static final String DEFAULT_REPORT_TITLE = "Substep Test Execution Report"; - - private static final String JSON_STATS_DATA_FILENAME = "susbteps-stats.js"; - - private static Map resultToImageMap = new HashMap(); - - private final ReportData data = new ReportData(); - - static { - - resultToImageMap.put(ExecutionResult.PASSED, "img/PASSED.png"); - resultToImageMap.put(ExecutionResult.NOT_RUN, "img/NOT_RUN.png"); - resultToImageMap.put(ExecutionResult.PARSE_FAILURE, "img/PARSE_FAILURE.png"); - resultToImageMap.put(ExecutionResult.FAILED, "img/FAILED.png"); - } - - /** - * @parameter default-value = ${project.build.directory} - */ - private File outputDirectory; - - /** - * @parameter default-value = "Substeps report" - */ - private String reportTitle; - - public DefaultExecutionReportBuilder() { - this.velocityProperties.setProperty("resource.loader", "class"); - this.velocityProperties.setProperty("class.resource.loader.class", - "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); - } - - @Override - public void setOutputDirectory(final File outputDirectory) { - this.outputDirectory = outputDirectory; - } - - @Override - public void buildReport() { - - this.log.debug("Build report in: " + this.outputDirectory.getAbsolutePath()); - - final File reportDir = new File(this.outputDirectory + File.separator + FEATURE_REPORT_FOLDER); - - final File screenshotDirectory = new File(reportDir, SCREENSHOT_FOLDER); - - try { - - this.log.debug("trying to create: " + reportDir.getAbsolutePath()); - - if (reportDir.exists()) { - FileUtils.deleteDirectory(reportDir); - } - - AssertHelper.assertTrue("failed to create directory: " + reportDir, reportDir.mkdirs()); - - copyStaticResources(reportDir); - - buildMainReport(this.data, reportDir); - - TreeJsonBuilder.writeTreeJson(this.data, new File(reportDir, JSON_DATA_FILENAME)); - - DetailedJsonBuilder.writeDetailJson(this.data, SCREENSHOT_FOLDER, new File(reportDir, - JSON_DETAIL_DATA_FILENAME)); - - buildStatsJSON(this.data, reportDir); - - for (final ExecutionNode rootNode : this.data.getRootNodes()) { - - ScreenshotWriter.writeScreenshots(screenshotDirectory, rootNode); - } - - } catch (final IOException ex) { - this.log.error("IOException: ", ex); - } catch (final URISyntaxException ex) { - this.log.error("URISyntaxException: ", ex); - } - } - - /** - * @param data - * @param reportDir - */ - private void buildStatsJSON(final ReportData data, final File reportDir) throws IOException { - - final File jsonFile = new File(reportDir, JSON_STATS_DATA_FILENAME); - - final ExecutionStats stats = new ExecutionStats(); - stats.buildStats(data); - - final BufferedWriter writer = Files.newWriter(jsonFile, Charset.defaultCharset()); - try { - buildStatsJSON(stats, writer); - } finally { - writer.close(); - } - - } - - /** - * @param stats - * @param writer - */ - private void buildStatsJSON(final ExecutionStats stats, final BufferedWriter writer) throws IOException { - - writer.append("var featureStatsData = ["); - boolean first = true; - - for (final TestCounterSet stat : stats.getSortedList()) { - - if (!first) { - writer.append(",\n"); - } - writer.append("[\"").append(stat.getTag()).append("\","); - writer.append("\"").append(Integer.toString(stat.getFeatureStats().getCount())).append("\","); - writer.append("\"").append(Integer.toString(stat.getFeatureStats().getRun())).append("\","); - writer.append("\"").append(Integer.toString(stat.getFeatureStats().getPassed())).append("\","); - writer.append("\"").append(Integer.toString(stat.getFeatureStats().getFailed())).append("\","); - writer.append("\"").append(Double.toString(stat.getFeatureStats().getSuccessPc())).append("\"]"); - - first = false; - } - - writer.append("];\n"); - - writer.append("var scenarioStatsData = ["); - first = true; - - for (final TestCounterSet stat : stats.getSortedList()) { - - if (!first) { - writer.append(",\n"); - } - writer.append("[\"").append(stat.getTag()).append("\","); - writer.append("\"").append(Integer.toString(stat.getScenarioStats().getCount())).append("\","); - writer.append("\"").append(Integer.toString(stat.getScenarioStats().getRun())).append("\","); - writer.append("\"").append(Integer.toString(stat.getScenarioStats().getPassed())).append("\","); - writer.append("\"").append(Integer.toString(stat.getScenarioStats().getFailed())).append("\","); - writer.append("\"").append(Double.toString(stat.getScenarioStats().getSuccessPc())).append("\"") - .append("]"); - - first = false; - } - - writer.append("];\n"); - - } - - /** - * @param reportDir - * @throws IOException - */ - public void copyStaticResources(final File reportDir) throws URISyntaxException, IOException { - - this.log.debug("Copying old_static resources to: " + reportDir.getAbsolutePath()); - - final URL staticURL = getClass().getResource("/static"); - if (staticURL == null) { - throw new IllegalStateException("Failed to copy old_static resources for report. URL for resources is null."); - } - - copyResourcesRecursively(staticURL, reportDir); - } - - private void buildMainReport(final ReportData data, final File reportDir) throws IOException { - - this.log.debug("Building main report file."); - - final VelocityContext vCtx = new VelocityContext(); - - final String vml = "report_frame.vm"; - - final ExecutionStats stats = new ExecutionStats(); - stats.buildStats(data); - - final SimpleDateFormat sdf = new SimpleDateFormat("EEE dd MMM yyyy HH:mm"); - final String dateTimeStr = sdf.format(new Date()); - - vCtx.put("stats", stats); - vCtx.put("dateTimeStr", dateTimeStr); - - if (StringUtils.isEmpty(this.reportTitle)) { - this.reportTitle = DEFAULT_REPORT_TITLE; - } - - vCtx.put("reportTitle", this.reportTitle); - - renderAndWriteToFile(reportDir, vCtx, vml, "report_frame.html"); - - } - - private void renderAndWriteToFile(final File reportDir, final VelocityContext vCtx, final String vm, - final String targetFilename) throws IOException { - - final Writer writer = new BufferedWriter(new FileWriter(new File(reportDir, targetFilename))); - - final VelocityEngine velocityEngine = new VelocityEngine(); - - try { - - velocityEngine.init(this.velocityProperties); - velocityEngine.getTemplate("templates/" + vm).merge(vCtx, writer); - - } catch (final ResourceNotFoundException e) { - throw new SubstepsException(e); - } catch (final ParseErrorException e) { - throw new SubstepsException(e); - } catch (final MethodInvocationException e) { - throw new SubstepsException(e); - } catch (final IOException e) { - throw new SubstepsException(e); - } catch (final Exception e) { - throw new SubstepsException(e); - } finally { - try { - if (writer != null) { - writer.close(); - } - } catch (final IOException e) { - - this.log.error("IOException: ", e); - } - } - } - - public void copyResourcesRecursively(final URL originUrl, final File destination) throws IOException { - final URLConnection urlConnection = originUrl.openConnection(); - if (urlConnection instanceof JarURLConnection) { - copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection); - } else if (originUrl.getProtocol().toLowerCase().startsWith("file")) { - - FileUtils.copyDirectory(new File(originUrl.getPath()), destination); - } else { - throw new SubstepsException("URLConnection[" + urlConnection.getClass().getSimpleName() - + "] is not a recognized/implemented connection type."); - } - } - - public void copyJarResourcesRecursively(final File destination, final JarURLConnection jarConnection) - throws IOException { - final JarFile jarFile = jarConnection.getJarFile(); - for (final JarEntry entry : Collections.list(jarFile.entries())) { - if (entry.getName().startsWith(jarConnection.getEntryName())) { - final String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); - if (!entry.isDirectory()) { - InputStream entryInputStream = null; - try { - entryInputStream = jarFile.getInputStream(entry); - FileUtils.copyInputStreamToFile(entryInputStream, new File(destination, fileName)); - } finally { - IOUtils.closeQuietly(entryInputStream); - } - } else { - new File(destination, fileName).mkdirs(); - } - } - } - } - - @Override - public void addRootExecutionNode(final RootNode node) { - - this.data.addRootExecutionNode(node); - } - -} diff --git a/core/src/main/java/com/technophobia/substeps/report/DetailedJsonBuilder.java b/core/src/main/java/com/technophobia/substeps/report/DetailedJsonBuilder.java deleted file mode 100644 index 06dd1e4a..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/DetailedJsonBuilder.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.google.common.io.Files; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor; -import com.technophobia.substeps.execution.ExecutionNodeResult; -import com.technophobia.substeps.execution.node.ExecutionNode; -import com.technophobia.substeps.execution.node.IExecutionNode; -import com.technophobia.substeps.execution.node.NodeWithChildren; -import com.technophobia.substeps.execution.node.StepImplementationNode; -import com.technophobia.substeps.model.exception.SubstepsRuntimeException; -import org.apache.commons.lang3.StringEscapeUtils; -import org.joda.time.Duration; -import org.joda.time.format.PeriodFormat; -import org.joda.time.format.PeriodFormatter; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; - -public final class DetailedJsonBuilder extends AbstractExecutionNodeVisitor { - - private final ReportData reportData; - private final String screenshotFolder; - private BufferedWriter writer; - - public static void writeDetailJson(ReportData reportData, String screenshotFolder, File jsonFile) { - - new DetailedJsonBuilder(reportData, screenshotFolder).writeFile(jsonFile); - - } - - private DetailedJsonBuilder(ReportData reportData, String screenshotFolder) { - - this.reportData = reportData; - this.screenshotFolder = screenshotFolder; - } - - private void writeFile(File jsonFile) { - try { - - writer = Files.newWriter(jsonFile, Charset.defaultCharset()); - writer.append("var detail = new Array();"); - - for (ExecutionNode rootNode : reportData.getRootNodes()) { - - for (JsonObject nodeAsJson : rootNode.accept(this)) { - - writer.append("\ndetail[" + nodeAsJson.get("id") + "]=" + nodeAsJson.toString() + ";"); - } - - } - - } catch (IOException e) { - - throw new SubstepsRuntimeException("Failed writing to detail json file", e); - } finally { - - if (writer != null) { - try { - writer.flush(); - writer.close(); - } catch (IOException e) { - throw new SubstepsRuntimeException("Failed writing to detail json file", e); - } - } - - } - - } - - @Override - public JsonObject visit(NodeWithChildren node) { - - return createBasicDetailsWithChildDetails(node.getClass().getSimpleName(), node, node.getChildren()); - } - - @Override - public JsonObject visit(StepImplementationNode stepImplementationNode) { - - JsonObject json = createBasicDetails("Step", stepImplementationNode); - addLinkToScreenshot(stepImplementationNode.getResult(), json); - - String methodInfo = createMethodInfo(stepImplementationNode); - - json.addProperty("method", methodInfo); - - return json; - } - - private JsonObject createBasicDetailsWithChildDetails(String nodeType, IExecutionNode node, - List childNodes) { - - JsonObject json = createBasicDetails(nodeType, node); - addDetailsForChildren(json, childNodes); - - return json; - } - - public JsonObject createBasicDetails(String nodeType, IExecutionNode node) { - - JsonObject thisNode = new JsonObject(); - - thisNode.addProperty("nodetype", nodeType); - thisNode.addProperty("filename", node.getFilename()); - thisNode.addProperty("result", node.getResult().getResult().toString()); - thisNode.addProperty("id", node.getId()); - thisNode.addProperty("emessage", getExceptionMessage(node)); - thisNode.addProperty("stacktrace", getStackTrace(node)); - - thisNode.addProperty("runningDurationMillis", node.getResult().getRunningDuration()); - thisNode.addProperty("runningDurationString", convert(node.getResult().getRunningDuration())); - - String description = node.getDescription() == null ? null : node.getDescription().trim(); - String descriptionEscaped = replaceNewLines(StringEscapeUtils.escapeHtml4(description)); - - thisNode.addProperty("description", descriptionEscaped); - - return thisNode; - } - - private void addLinkToScreenshot(ExecutionNodeResult result, JsonObject thisNode) { - - if (result.getScreenshot() != null) { - thisNode.addProperty("screenshot", screenshotFolder + File.separator + result.getExecutionNodeId() - + ScreenshotWriter.SCREENSHOT_SUFFIX); - } - } - - private String convert(Long runningDurationMillis) { - - return runningDurationMillis == null ? "No duration recorded" : convert(runningDurationMillis.longValue()); - } - - private String convert(long runningDurationMillis) { - Duration duration = new Duration(runningDurationMillis); - PeriodFormatter formatter = PeriodFormat.getDefault(); - return formatter.print(duration.toPeriod()); - } - - private void addDetailsForChildren(JsonObject json, List childNodes) { - - JsonArray children = new JsonArray(); - json.add("children", children); - - for (IExecutionNode childNode : childNodes) { - - JsonObject childObject = new JsonObject(); - childObject.addProperty("result", childNode.getResult().getResult().toString()); - childObject.addProperty("description", StringEscapeUtils.escapeHtml4(childNode.getDescription())); - children.add(childObject); - } - } - - private String createMethodInfo(StepImplementationNode node) { - - final StringBuilder methodInfoBuffer = new StringBuilder(); - node.appendMethodInfo(methodInfoBuffer); - - String methodInfo = methodInfoBuffer.toString(); - if (methodInfo.contains("\"")) { - methodInfo = methodInfo.replace("\"", "\\\""); - } - - return replaceNewLines(methodInfo); - } - - private String getExceptionMessage(IExecutionNode node) { - String exceptionMessage = ""; - - if (node.getResult().getThrown() != null) { - - final String exceptionMsg = StringEscapeUtils.escapeHtml4(node.getResult().getThrown().getMessage()); - - exceptionMessage = replaceNewLines(exceptionMsg); - - } - - return exceptionMessage; - } - - private String getStackTrace(IExecutionNode node) { - String stackTrace = ""; - - if (node.getResult().getThrown() != null) { - - final StackTraceElement[] stackTraceElements = node.getResult().getThrown().getStackTrace(); - - final StringBuilder buf = new StringBuilder(); - - for (final StackTraceElement e : stackTraceElements) { - - buf.append(StringEscapeUtils.escapeHtml4(e.toString().trim())).append("
"); - } - stackTrace = buf.toString(); - } - - return stackTrace; - } - - private String replaceNewLines(final String s) { - - if (s != null && s.contains("\n")) { - - return s.replaceAll("\n", "
"); - } else { - return s; - } - } - -} diff --git a/core/src/main/java/com/technophobia/substeps/report/ExecutionStats.java b/core/src/main/java/com/technophobia/substeps/report/ExecutionStats.java deleted file mode 100644 index 65740b78..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/ExecutionStats.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.google.common.collect.Sets; -import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor; -import com.technophobia.substeps.execution.node.*; - -import java.io.Serializable; -import java.util.*; - -/** - * @author ian - */ -public class ExecutionStats extends AbstractExecutionNodeVisitor { - - private final TestCounterSet totals = new TestCounterSet(); - - private final Map taggedStats = new HashMap(); - - private List sortedList = null; - - public void buildStats(final ReportData data) { - - for (RootNode rootNode : data.getRootNodes()) { - - buildStatsForRootNode(rootNode); - } - } - - private void buildStatsForRootNode(RootNode rootNode) { - - for (FeatureNode featureNode : rootNode.getChildren()) { - - buildStatsForFeatureNode(featureNode); - - for (ScenarioNode scenarioNode : featureNode.getChildren()) { - - buildStatsForScenarioNode(scenarioNode); - } - } - } - - private void buildStatsForScenarioNode(ScenarioNode scenarioNode) { - for (TestCounterSet stats : getAllStatsForTags(scenarioNode.getTags())) { - stats.getScenarioStats().apply(scenarioNode); - } - scenarioNode.dispatch(this); - } - - private void buildStatsForFeatureNode(FeatureNode featureNode) { - - for (TestCounterSet stats : getAllStatsForTags(featureNode.getTags())) { - stats.getFeatureStats().apply(featureNode); - } - } - - @Override - public Void visit(BasicScenarioNode scenarioNode) { - - Set testStats = getAllStatsForTags(scenarioNode.getTags()); - - for (StepNode childNode : scenarioNode.getChildren()) { - - for (TestCounterSet stats : testStats) { - - stats.getScenarioStepStats().apply(childNode); - } - } - - return null; - } - - @Override - public Void visit(OutlineScenarioNode outlineScenarioNode) { - - for (OutlineScenarioRowNode row : outlineScenarioNode.getChildren()) { - - visit(row.getBasicScenarioNode()); - } - - return null; - } - - private Set getAllStatsForTags(Set tags) { - - Set testStats = Sets.newHashSetWithExpectedSize(tags.size() + 1); - testStats.add(totals); - for (String tag : tags) { - testStats.add(getOrCreateStatsForTag(tag)); - } - return testStats; - } - - private TestCounterSet getOrCreateStatsForTag(String tag) { - if (taggedStats.get(tag) == null) { - TestCounterSet newStats = new TestCounterSet(); - newStats.setTag(tag); - taggedStats.put(tag, newStats); - } - - return taggedStats.get(tag); - } - - public int getTotalFeatures() { - return totals.getFeatureStats().getCount(); - } - - public int getTotalFeaturesRun() { - return totals.getFeatureStats().getRun(); - } - - public int getTotalFeaturesPassed() { - return totals.getFeatureStats().getPassed(); - } - - public int getTotalFeaturesFailed() { - return totals.getFeatureStats().getFailed(); - } - - public int getTotalFeaturesSkipped() { - return totals.getFeatureStats().getIgnored(); - } - - public double getTotalFeaturesSuccess() { - - return totals.getFeatureStats().getSuccessPc(); - } - - public double getTotalFeaturesFailedPC() { - - return 100 - totals.getFeatureStats().getSuccessPc(); - } - - public int getTotalScenarios() { - return totals.getScenarioStats().getCount(); - } - - public int getTotalScenariosRun() { - return totals.getScenarioStats().getRun(); - } - - public int getTotalScenariosPassed() { - return totals.getScenarioStats().getPassed(); - } - - public int getTotalScenariosFailed() { - return totals.getScenarioStats().getFailed(); - } - - public int getTotalScenariosSkipped() { - return totals.getScenarioStats().getIgnored(); - } - - public double getTotalScenariosSuccess() { - - return totals.getScenarioStats().getSuccessPc(); - } - - public int getTotalScenarioSteps() { - return totals.getScenarioStepStats().getCount(); - } - - public int getTotalScenarioStepsRun() { - return totals.getScenarioStepStats().getRun(); - } - - public int getTotalScenarioStepsPassed() { - return totals.getScenarioStepStats().getPassed(); - } - - public int getTotalScenarioStepsFailed() { - return totals.getScenarioStepStats().getFailed(); - } - - public int getTotalScenarioStepsSkipped() { - return totals.getScenarioStepStats().getIgnored(); - } - - public double getTotalScenarioStepsSuccess() { - - return totals.getScenarioStepStats().getSuccessPc(); - - } - - private static class TestStatSetComparator implements Comparator, Serializable { - - private static final long serialVersionUID = -1736428075471005357L; - - /* - * (non-Javadoc) - * - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - @Override - public int compare(final TestCounterSet t1, final TestCounterSet t2) { - // not sure which way around this is!! - return t1.getScenarioStepStats().getFailed() - t2.getScenarioStepStats().getFailed(); - } - - } - - /** - * @return the sortedList - */ - public List getSortedList() { - - if (taggedStats != null) { - - sortedList = new ArrayList(); - sortedList.addAll(taggedStats.values()); - - if (taggedStats.size() > 1) { - Collections.sort(sortedList, new TestStatSetComparator()); - } - } - - return sortedList; - } -} diff --git a/core/src/main/java/com/technophobia/substeps/report/ReportData.java b/core/src/main/java/com/technophobia/substeps/report/ReportData.java deleted file mode 100644 index f4fedcfe..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/ReportData.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor; -import com.technophobia.substeps.execution.node.ExecutionNode; -import com.technophobia.substeps.execution.node.IExecutionNode; -import com.technophobia.substeps.execution.node.RootNode; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author ian - */ -class ReportData { - - private List rootNodes; - - public void addRootExecutionNode(final RootNode node) { - if (rootNodes == null) { - rootNodes = new ArrayList(); - } - rootNodes.add(node); - } - - private List flattenTree(final IExecutionNode node) { - - return node.accept(new AbstractExecutionNodeVisitor() { - - @Override - public IExecutionNode visit(IExecutionNode node) { - return node; - } - }); - } - - /** - * @return the nodeList - */ - public List getNodeList() { - - final List nodeList = new ArrayList(); - - for (final ExecutionNode rootNode : this.rootNodes) { - nodeList.addAll(flattenTree(rootNode)); - } - - return nodeList; - } - - /** - * @return the rootNodes - */ - public List getRootNodes() { - return rootNodes; - } - -} diff --git a/core/src/main/java/com/technophobia/substeps/report/ScreenshotWriter.java b/core/src/main/java/com/technophobia/substeps/report/ScreenshotWriter.java deleted file mode 100644 index f8a025a6..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/ScreenshotWriter.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor; -import com.technophobia.substeps.execution.node.ExecutionNode; -import com.technophobia.substeps.execution.node.StepImplementationNode; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileOutputStream; - -public final class ScreenshotWriter extends AbstractExecutionNodeVisitor { - - public static final String SCREENSHOT_SUFFIX = "node-failure.png"; - - private File directoryForScreenshots; - - private final static Logger log = LoggerFactory.getLogger(ScreenshotWriter.class); - - public static void writeScreenshots(File directoryForScreenshots, ExecutionNode rootNode) { - - rootNode.accept(new ScreenshotWriter(directoryForScreenshots)); - } - - private ScreenshotWriter(File directoryForScreenshots) { - - directoryForScreenshots.mkdirs(); - this.directoryForScreenshots = directoryForScreenshots; - } - - @Override - public Void visit(StepImplementationNode executionNode) { - - if (executionNode.getResult() != null) { - - byte[] screenshot = executionNode.getResult().getScreenshot(); - - if (screenshot != null) { - - File screenshotFile = new File(directoryForScreenshots, executionNode.getId() + SCREENSHOT_SUFFIX); - - try { - - IOUtils.write(screenshot, new FileOutputStream(screenshotFile)); - - } catch (Exception e) { - - log.error("Unable to create screenshot", e); - } - - } - } - - return null; - } - -} diff --git a/core/src/main/java/com/technophobia/substeps/report/TestCounterSet.java b/core/src/main/java/com/technophobia/substeps/report/TestCounterSet.java deleted file mode 100644 index 616a7c8e..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/TestCounterSet.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -public class TestCounterSet { - - private String tag = null; - - private TestCounters featureStats = new TestCounters(); - private TestCounters scenarioStats = new TestCounters(); - private TestCounters scenarioStepStats = new TestCounters(); - - public String getTag() { - return tag; - } - - public void setTag(final String tag) { - this.tag = tag; - } - - public TestCounters getFeatureStats() { - return featureStats; - } - - public void setFeatureStats(final TestCounters featureStats) { - this.featureStats = featureStats; - } - - public TestCounters getScenarioStats() { - return scenarioStats; - } - - public void setScenarioStats(final TestCounters scenarioStats) { - this.scenarioStats = scenarioStats; - } - - public TestCounters getScenarioStepStats() { - return scenarioStepStats; - } - - public void setScenarioStepStats(final TestCounters scenarioStepStats) { - this.scenarioStepStats = scenarioStepStats; - } - -} \ No newline at end of file diff --git a/core/src/main/java/com/technophobia/substeps/report/TestCounters.java b/core/src/main/java/com/technophobia/substeps/report/TestCounters.java deleted file mode 100644 index e01b57f1..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/TestCounters.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.technophobia.substeps.execution.ExecutionNodeResult; -import com.technophobia.substeps.execution.node.IExecutionNode; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -/** - * @author ian - */ -public class TestCounters { - - private int count = 0; - private int run = 0; - private int ignored = 0; - private int passed = 0; - private int failed = 0; - - - public double getSuccessPc() { - - double rtn = 0.0; - if (run > 0) { - - final double d = (double) passed / (double) run * 100; - final BigDecimal bd = BigDecimal.valueOf(d).setScale(1, RoundingMode.HALF_UP); - rtn = bd.doubleValue(); - } - return rtn; - } - - - public void addCount() { - count++; - } - - - public void addRun() { - run++; - } - - - public void addIgnored() { - ignored++; - } - - - public void addPassed() { - passed++; - } - - - public void addFailed() { - failed++; - } - - - /** - * @return the count - */ - public int getCount() { - return count; - } - - - /** - * @return the run - */ - public int getRun() { - return run; - } - - - /** - * @return the ignored - */ - public int getIgnored() { - return ignored; - } - - - /** - * @return the passed - */ - public int getPassed() { - return passed; - } - - - /** - * @return the failed - */ - public int getFailed() { - return failed; - } - - - public void apply(final IExecutionNode node) { - - final ExecutionNodeResult result = node.getResult(); - - count++; - - switch (result.getResult()) { - case IGNORED: - case NOT_INCLUDED: - case NOT_RUN: { - ignored++; - - break; - } - - case RUNNING: { - run++; - break; - } - - case PASSED: { - run++; - passed++; - break; - } - - case FAILED: { - run++; - failed++; - break; - } - - } - } - -} diff --git a/core/src/main/java/com/technophobia/substeps/report/TreeJsonBuilder.java b/core/src/main/java/com/technophobia/substeps/report/TreeJsonBuilder.java deleted file mode 100644 index 63f57435..00000000 --- a/core/src/main/java/com/technophobia/substeps/report/TreeJsonBuilder.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor; -import com.technophobia.substeps.execution.ExecutionResult; -import com.technophobia.substeps.execution.node.*; -import com.technophobia.substeps.model.exception.SubstepsRuntimeException; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public final class TreeJsonBuilder extends AbstractExecutionNodeVisitor { - - private final ReportData reportData; - - private static Map resultToImageMap = new HashMap(); - - private static final Predicate NODE_HAS_ERROR = new Predicate() { - @Override - public boolean apply(ExecutionNode node) { - return node.hasError(); - } - }; - - static { - - resultToImageMap.put(ExecutionResult.PASSED, "img/PASSED.png"); - resultToImageMap.put(ExecutionResult.NOT_RUN, "img/NOT_RUN.png"); - resultToImageMap.put(ExecutionResult.PARSE_FAILURE, "img/PARSE_FAILURE.png"); - resultToImageMap.put(ExecutionResult.FAILED, "img/FAILED.png"); - } - - public static void writeTreeJson(ReportData reportData, File jsonFile) { - - new TreeJsonBuilder(reportData).createFile(jsonFile); - - } - - private TreeJsonBuilder(ReportData reportData) { - - this.reportData = reportData; - } - - private void createFile(File jsonFile) { - - JsonObject tree = buildTree(); - writeFile(jsonFile, tree); - } - - private void writeFile(File jsonFile, JsonObject tree) { - BufferedWriter writer = null; - - try { - - writer = Files.newWriter(jsonFile, Charset.defaultCharset()); - writer.append("var treeData = " + tree.toString()); - - } catch (IOException e) { - - throw new SubstepsRuntimeException("Failed writing to detail json file", e); - - } finally { - - if (writer != null) { - try { - writer.flush(); - writer.close(); - } catch (IOException e) { - throw new SubstepsRuntimeException("Failed writing to detail json file", e); - } - } - - } - } - - private JsonObject buildTree() { - List rootNodes = reportData.getRootNodes(); - - JsonObject tree = new JsonObject(); - - boolean rootNodeInError = Iterables.any(rootNodes, NODE_HAS_ERROR); - - addChildren(tree, rootNodeInError, rootNodes); - - JsonObject data = new JsonObject(); - tree.add("data", data); - data.addProperty("title", "Substeps tests"); - - JsonObject attr = new JsonObject(); - data.add("attr", attr); - attr.addProperty("id", "0"); - - String icon = rootNodeInError ? resultToImageMap.get(ExecutionResult.FAILED) : resultToImageMap - .get(ExecutionResult.PASSED); - data.addProperty("icon", icon); - - if (rootNodeInError) { - - data.addProperty("state", "open"); - } - return tree; - } - - private JsonObject createJsonWithBasicNodeDetails(IExecutionNode node) { - - JsonObject json = new JsonObject(); - JsonObject data = new JsonObject(); - json.add("data", data); - data.addProperty("title", getDescriptionForNode(node)); - JsonObject attr = new JsonObject(); - data.add("attr", attr); - attr.addProperty("id", Long.toString(node.getId())); - data.addProperty("icon", getNodeImage(node)); - return json; - } - - @Override - public JsonObject visit(NodeWithChildren node) { - - return addChildren(createJsonWithBasicNodeDetails(node), node.hasError(), node.getChildren()); - } - - @Override - public JsonObject visit(StepImplementationNode node) { - - return createJsonWithBasicNodeDetails(node); - } - - private String getNodeImage(final IExecutionNode node) { - return resultToImageMap.get(node.getResult().getResult()); - } - - private String getDescriptionForNode(final IExecutionNode node) { - - final StringBuilder buf = new StringBuilder(); - - ExecutionReportBuilder.buildDescriptionString(null, node, buf); - - // need to replace " - String msg = buf.toString(); - if (msg.contains("\"")) { - msg = msg.replace("\"", "\\\""); - } - - return msg; - } - - JsonObject addChildren(JsonObject json, boolean hasError, List childNodes) { - - if (childNodes != null && !childNodes.isEmpty()) { - - if (hasError) { - json.addProperty("state", "open"); - } - - JsonArray children = new JsonArray(); - - for (IExecutionNode node : childNodes) { - - children.add(node.dispatch(this)); - } - - json.add("children", children); - - } - - return json; - } -} diff --git a/core/src/main/resources/templates/detail.vm b/core/src/main/resources/templates/detail.vm deleted file mode 100644 index bd22e633..00000000 --- a/core/src/main/resources/templates/detail.vm +++ /dev/null @@ -1,38 +0,0 @@ -

$!node.getType() - $node.filename - Result: $node.result.result.toString()

- -File: $node.id in - -

Details: $node.getDebugStringForThisNode()

- -#if ($node.result.thrown) - -

$node.result.thrown.message

- -
-$node.result.getStackTrace()
-
- -#end - - - - - - #foreach( $child in $node.children ) - - #set( $class = "") - - #if($child.getResult().getResult() == "PASSED") - #set($class = 'class="success"') - #elseif($child.getResult().getResult() == "FAILED") - #set($class = 'class="error"') - #end - - - - - #end - -
- $child.getDescription() -
diff --git a/core/src/main/resources/templates/report_frame.vm b/core/src/main/resources/templates/report_frame.vm deleted file mode 100644 index a460e289..00000000 --- a/core/src/main/resources/templates/report_frame.vm +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - SubSteps report - - - - - - - - - - - -
-
- -
- -
- -
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Summary

NumberRunPassedFailedSkippedSuccess %
Features$stats.getTotalFeatures()$stats.getTotalFeaturesRun()$stats.getTotalFeaturesPassed()$stats.getTotalFeaturesFailed()$stats.getTotalFeaturesSkipped()$stats.getTotalFeaturesSuccess() %
Scenarios$stats.getTotalScenarios()$stats.getTotalScenariosRun()$stats.getTotalScenariosPassed()$stats.getTotalScenariosFailed()$stats.getTotalScenariosSkipped()$stats.getTotalScenariosSuccess() %
Scenario steps$stats.getTotalScenarioSteps()$stats.getTotalScenarioStepsRun()$stats.getTotalScenarioStepsPassed()$stats.getTotalScenarioStepsFailed()$stats.getTotalScenarioStepsSkipped()$stats.getTotalScenarioStepsSuccess() %
-
- - - - - - - -
-

Test details

-
- - - -
- -
- -
- - -
-
-
-
-
-
- - - - - - - - - - - - - - diff --git a/core/src/main/resources/templates/summary.txt.vm b/core/src/main/resources/templates/summary.txt.vm deleted file mode 100644 index c0023e4c..00000000 --- a/core/src/main/resources/templates/summary.txt.vm +++ /dev/null @@ -1,42 +0,0 @@ -## Copyright Technophobia Ltd 2012 - -features.total=$stats.getTotalFeatures() -features.total.run=$stats.getTotalFeaturesRun() -features.total.passed=$stats.getTotalFeaturesPassed() -features.total.failed=$stats.getTotalFeaturesFailed() -features.total.skipped=$stats.getTotalFeaturesSkipped() -features.total.success.pc=$stats.getTotalFeaturesSuccess() - -scenarios.total=$stats.getTotalScenarios() -scenarios.total.run=$stats.getTotalScenariosRun() -scenarios.total.passed=$stats.getTotalScenariosPassed() -scenarios.total.failed=$stats.getTotalScenariosFailed() -scenarios.total.skipped=$stats.getTotalScenariosSkipped() -scenarios.total.success.pc=$stats.getTotalScenariosSuccess() - -scenario.steps.total=$stats.getTotalScenarioSteps() -scenario.steps.total.run=$stats.getTotalScenarioStepsRun() -scenario.steps.total.passed=$stats.getTotalScenarioStepsPassed() -scenario.steps.total.failed=$stats.getTotalScenarioStepsFailed() -scenario.steps.total.skipped=$stats.getTotalScenarioStepsSkipped() -scenario.steps.total.success.pc=$stats.getTotalScenarioStepsSuccess() - -## break down by tag - -#foreach( $statSet in $stats.sortedList ) - -features.${statSet.tag}=$statSet.featureStats.count -features.${statSet.tag}.run=$statSet.featureStats.run -features.${statSet.tag}.passed=$statSet.featureStats.passed -features.${statSet.tag}.failed=$statSet.featureStats.failed -features.${statSet.tag}.success.pc=$statSet.featureStats.getSuccessPc() - - -scenarios.${statSet.tag}=$statSet.scenarioStats.count -scenarios.${statSet.tag}.run=$statSet.scenarioStats.run -scenarios.${statSet.tag}.passed=$statSet.scenarioStats.passed -scenarios.${statSet.tag}.failed=$statSet.scenarioStats.failed -scenarios.${statSet.tag}.success.pc=$statSet.scenarioStats.getSuccessPc() - -#end - diff --git a/core/src/main/scala/org/substeps/report/ReportBuilder.scala b/core/src/main/scala/org/substeps/report/ReportBuilder.scala index 1ff0579b..37a208f1 100644 --- a/core/src/main/scala/org/substeps/report/ReportBuilder.scala +++ b/core/src/main/scala/org/substeps/report/ReportBuilder.scala @@ -1,15 +1,16 @@ package org.substeps.report -import java.io.{BufferedWriter, File, FileNotFoundException} +import java.io._ +import java.net.{JarURLConnection, URISyntaxException, URL} import java.nio.charset.Charset -import java.time.{Instant, LocalDateTime, ZoneId, ZoneOffset} import java.time.format.DateTimeFormatter +import java.time.{Instant, LocalDateTime, ZoneId} +import java.util.Collections -import com.google.common.io.Files -import com.technophobia.substeps.execution.ExecutionResult -import com.technophobia.substeps.report.{DefaultExecutionReportBuilder, DetailedJsonBuilder} -import org.apache.commons.io.FileUtils -import org.apache.commons.lang3.StringEscapeUtils +import com.google.common.io.{FileWriteMode, Files} +import com.technophobia.substeps.model.exception.SubstepsException +import org.apache.commons.io.{FileUtils, IOUtils} +import org.apache.commons.lang3.{StringEscapeUtils, StringUtils} import org.json4s._ import org.json4s.native.Serialization import org.json4s.native.Serialization._ @@ -517,13 +518,59 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr - def copyStaticResources() = { + def copyStaticResources() : Unit = { - val defaultBuilder = new DefaultExecutionReportBuilder + copyStaticResources(reportDir) + } + + /** + * @param reportDir + * @throws IOException + */ + @throws[URISyntaxException] + @throws[IOException] + def copyStaticResources(reportDir: File): Unit = { + this.log.debug("Copying old_static resources to: " + reportDir.getAbsolutePath) + val staticURL = getClass.getResource("/static") + if (staticURL == null) throw new IllegalStateException("Failed to copy old_static resources for report. URL for resources is null.") + copyResourcesRecursively(staticURL, reportDir) + } - defaultBuilder.copyStaticResources(reportDir) + @throws[IOException] + def copyResourcesRecursively(originUrl: URL, destination: File): Unit = { + val urlConnection = originUrl.openConnection + if (urlConnection.isInstanceOf[JarURLConnection]) copyJarResourcesRecursively(destination, urlConnection.asInstanceOf[JarURLConnection]) + else if (originUrl.getProtocol.toLowerCase.startsWith("file")) FileUtils.copyDirectory(new File(originUrl.getPath), destination) + else throw new SubstepsException("URLConnection[" + urlConnection.getClass.getSimpleName + "] is not a recognized/implemented connection type.") } + @throws[IOException] + def copyJarResourcesRecursively(destination: File, jarConnection: JarURLConnection): Unit = { + val jarFile = jarConnection.getJarFile + import scala.collection.JavaConversions._ + for (entry <- Collections.list(jarFile.entries)) { + if (entry.getName.startsWith(jarConnection.getEntryName)) { + val fileName = StringUtils.removeStart(entry.getName, jarConnection.getEntryName) + if (!entry.isDirectory) { + + val entryInputStream = jarFile.getInputStream(entry) + try { + val byteSink = Files.asByteSink(new File(destination, fileName), FileWriteMode.APPEND) + byteSink.writeFrom(entryInputStream) + // FileUtils.copyInputStreamToFile(entryInputStream, new File(destination, fileName)) + } + finally { + + IOUtils.closeQuietly(entryInputStream) + + } + } + else new File(destination, fileName).mkdirs + } + } + } + + def createFile(name : String) = { val f = new File(reportDir, name) f.createNewFile() diff --git a/core/src/test/java/com/technophobia/substeps/model/PatternMapTest.java b/core/src/test/java/com/technophobia/substeps/model/PatternMapTest.java index 68a919eb..2564d5c9 100755 --- a/core/src/test/java/com/technophobia/substeps/model/PatternMapTest.java +++ b/core/src/test/java/com/technophobia/substeps/model/PatternMapTest.java @@ -19,7 +19,7 @@ package com.technophobia.substeps.model; -import junit.framework.Assert; +import org.junit.Assert; import org.junit.Test; import java.util.List; diff --git a/core/src/test/java/com/technophobia/substeps/report/DefaultExecutionReportBuilderTest.java b/core/src/test/java/com/technophobia/substeps/report/DefaultExecutionReportBuilderTest.java deleted file mode 100644 index c3fdcf3d..00000000 --- a/core/src/test/java/com/technophobia/substeps/report/DefaultExecutionReportBuilderTest.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.gson.*; -import com.technophobia.substeps.execution.Feature; -import com.technophobia.substeps.execution.node.*; -import org.apache.log4j.Logger; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author ian - */ -public class DefaultExecutionReportBuilderTest { - - private static final String STEP_NODE = "stepNode"; - private static final String SCENARIO_NAME = "scenarioName"; - private static final String RESULT = "result"; - private static final String DESCRIPTION = "description"; - private static final String FEATURE_NAME = "test feature"; - private static final String NOT_RUN = "NOT_RUN"; - private static final String PASSED = "PASSED"; - private static final String NODE_TYPE = "nodetype"; - - private static final Logger LOG = Logger.getLogger(DefaultExecutionReportBuilderTest.class); - - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - RootNode rootNode; - - List featureNodes = Lists.newArrayList(); - - List scenarioNodes = Lists.newArrayList(); - - List stepNodes = Lists.newArrayList(); - - private Integer nodeIdOffset = Integer.MAX_VALUE; - - private String arrayCreationLine; - - private static final String DETAIL_PATTERN = "detail\\[(\\d+)\\]=(\\{.*\\});"; - private static final String ARRAY_CREATION_LINE = "var detail = new Array();"; - - private Map details; - private DefaultExecutionReportBuilder builder; - - public void nonFailingMethod() { - System.out.println("no fail"); - } - - public void failingMethod() { - System.out.println("uh oh"); - throw new IllegalStateException("that's it, had enough"); - } - - @Before - public void createData() { - - builder = new DefaultExecutionReportBuilder(); - builder.setOutputDirectory(testFolder.getRoot()); - - rootNode = createRootNode(); - - builder.addRootExecutionNode(rootNode); - - } - - private RootNode createRootNode() { - - return new RootNode("Description", Collections.singletonList(createFeature(FEATURE_NAME, "test file")), "env", "tags", "non-fatal-tags"); - } - - private FeatureNode createFeature(String name, String fileName) { - - final Feature feature = new Feature(name, fileName); - final FeatureNode featureNode = new FeatureNode(feature, - Collections.>singletonList(createScenario(SCENARIO_NAME)), - Collections.emptySet()); - featureNodes.add(featureNode); - - return featureNode; - } - - private BasicScenarioNode createScenario(String scenarioName) { - - BasicScenarioNode scenarioNode = new BasicScenarioNode(scenarioName, null, createSteps(), - Collections.emptySet(), 2); - scenarioNodes.add(scenarioNode); - return scenarioNode; - } - - private List createSteps() { - - Method nonFailMethod = null; - Method failMethod = null; - try { - nonFailMethod = this.getClass().getMethod("nonFailingMethod"); - failMethod = this.getClass().getMethod("failingMethod"); - } catch (final Exception e) { - Assert.fail(e.getMessage()); - } - Assert.assertNotNull(nonFailMethod); - Assert.assertNotNull(failMethod); - - StepNode stepImpl1 = createStep(this.getClass(), nonFailMethod, STEP_NODE + "1"); - StepNode stepImpl2 = createStep(this.getClass(), failMethod, STEP_NODE + "2"); - StepNode stepImpl3 = createStep(this.getClass(), nonFailMethod, STEP_NODE + "3"); - - return Lists.newArrayList(stepImpl1, stepImpl2, stepImpl3); - } - - private StepImplementationNode createStep(Class stepClass, Method stepMethod, String stepLine) { - - final StepImplementationNode stepNode = new StepImplementationNode(stepClass, stepMethod, - Collections.emptySet(), 3); - stepNode.getResult().setStarted(); - stepNodes.add(stepNode); - stepNode.setLine(stepLine); - stepNode.getResult().setFinished(); - return stepNode; - } - - @Test - public void testDetailReport() throws IOException { - - builder.buildReport(); - - decomposeReport(); - - Assert.assertEquals("The array creation line was not as expected", ARRAY_CREATION_LINE, arrayCreationLine); - assertThereAreAsManyDetailsInTheReportAsNodesCreated(); - assertRootNodeAsExpected(6 + nodeIdOffset); - assertFeatureNodeAsExpected(5 + nodeIdOffset); - assertScenarioNodeAsExpected(4 + nodeIdOffset); - assertStepNodeAsExpected(3 + nodeIdOffset, STEP_NODE + "3"); - assertStepNodeAsExpected(2 + nodeIdOffset, STEP_NODE + "2"); - assertStepNodeAsExpected(1 + nodeIdOffset, STEP_NODE + "1"); - } - - private void assertRootNodeAsExpected(int index) { - - JsonObject rootNode = details.get(index); - - Assert.assertNotNull(rootNode); - - assertBasics(index, rootNode, "RootNode", NOT_RUN); - - JsonArray children = rootNode.getAsJsonArray("children"); - Assert.assertEquals(1, children.size()); - JsonObject child = (JsonObject) Iterables.getOnlyElement(children); - Assert.assertEquals(NOT_RUN, child.get(RESULT).getAsString()); - Assert.assertEquals(FEATURE_NAME, child.get(DESCRIPTION).getAsString()); - } - - private void assertFeatureNodeAsExpected(int index) { - - JsonObject featureNode = details.get(index); - assertBasics(index, featureNode, "FeatureNode", NOT_RUN); - - Assert.assertEquals(FEATURE_NAME, featureNode.get(DESCRIPTION).getAsString()); - - JsonArray children = featureNode.getAsJsonArray("children"); - Assert.assertEquals(1, children.size()); - JsonObject child = (JsonObject) Iterables.getOnlyElement(children); - Assert.assertEquals(NOT_RUN, child.get(RESULT).getAsString()); - Assert.assertEquals(SCENARIO_NAME, child.get(DESCRIPTION).getAsString()); - } - - private void assertScenarioNodeAsExpected(int index) { - - JsonObject scenarioNode = details.get(index); - assertBasics(index, scenarioNode, "BasicScenarioNode", NOT_RUN); - Assert.assertEquals(SCENARIO_NAME, scenarioNode.get(DESCRIPTION).getAsString()); - - JsonArray children = scenarioNode.getAsJsonArray("children"); - Assert.assertEquals(stepNodes.size(), children.size()); - - Iterator childIterator = children.iterator(); - - assertChildStepNode((JsonObject) childIterator.next(), "stepNode1"); - assertChildStepNode((JsonObject) childIterator.next(), "stepNode2"); - assertChildStepNode((JsonObject) childIterator.next(), "stepNode3"); - } - - private void assertChildStepNode(JsonObject child, String description) { - - Assert.assertEquals(PASSED, child.get(RESULT).getAsString()); - Assert.assertEquals(description, child.get(DESCRIPTION).getAsString()); - } - - private void assertStepNodeAsExpected(int index, String description) { - - JsonObject stepNode = details.get(index); - assertBasics(index, stepNode, "Step", PASSED); - Assert.assertEquals(description, stepNode.get(DESCRIPTION).getAsString()); - - Assert.assertFalse(stepNode.has("children")); - } - - private void assertBasics(int index, JsonObject node, String nodeType, String result) { - - Assert.assertEquals(nodeType, node.get(NODE_TYPE).getAsString()); - Assert.assertEquals(result, node.get(RESULT).getAsString()); - Assert.assertEquals(index, node.get("id").getAsInt()); - - } - - private void assertThereAreAsManyDetailsInTheReportAsNodesCreated() { - - int numberOfNodes = 1 + featureNodes.size() + scenarioNodes.size() + stepNodes.size(); - - Assert.assertEquals("There should have been a detail line for each node", numberOfNodes, details.size()); - } - - private BufferedReader getDetailReportReader() throws IOException { - File detailFile = new File(testFolder.getRoot(), DefaultExecutionReportBuilder.FEATURE_REPORT_FOLDER - + File.separator + DefaultExecutionReportBuilder.JSON_DETAIL_DATA_FILENAME); - return new BufferedReader(new FileReader(detailFile)); - } - - private void decomposeReport() throws IOException { - - BufferedReader reportReader = null; - - LOG.debug("decomposeReport() entered"); - - try { - reportReader = getDetailReportReader(); - - arrayCreationLine = reportReader.readLine(); - - Pattern pattern = Pattern.compile(DETAIL_PATTERN); - - JsonParser parser = new JsonParser(); - details = Maps.newHashMap(); - String line; - while ((line = reportReader.readLine()) != null) { - - LOG.debug("Line found in detail report = " + line); - - Matcher matcher = pattern.matcher(line); - - Assert.assertTrue("A line in the report did not conform to the expected format, line was '" + line - + "'", matcher.matches()); - String index = matcher.group(1); - String detail = matcher.group(2); - - JsonObject json = null; - try { - json = (JsonObject) parser.parse(detail); - } catch (JsonSyntaxException jse) { - jse.printStackTrace(); - Assert.fail("Invalid json found '" + detail + "'"); - } - - int indexInt = Integer.valueOf(index); - - nodeIdOffset = indexInt < nodeIdOffset ? indexInt - 1 : nodeIdOffset; - - details.put(indexInt, json); - } - } finally { - if (reportReader != null) { - reportReader.close(); - - } - } - - } - -} diff --git a/core/src/test/java/com/technophobia/substeps/report/ExecutionStatsTest.java b/core/src/test/java/com/technophobia/substeps/report/ExecutionStatsTest.java deleted file mode 100644 index 03b6d170..00000000 --- a/core/src/test/java/com/technophobia/substeps/report/ExecutionStatsTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright Technophobia Ltd 2012 - * - * This file is part of Substeps. - * - * Substeps is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Substeps is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Substeps. If not, see . - */ -package com.technophobia.substeps.report; - -import com.technophobia.substeps.execution.Feature; -import com.technophobia.substeps.execution.node.*; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - *
- *
- * Given the following substep configuration
- *
- * where SS = SubstepNode
- *       SI = StepImplementationNode
- *
- *
- *                            SS - SI
- *                            /    /
- *                          *SS - SS - SI
- *                          /
- *            *BasicScenarioA - *SS - SI
- *            /                   \
- *      *Feature1                  SI
- *            \
- *            *BasicScenarioB - *SS - SI
- *                           \
- *                            *SI
- *                                                   SI
- *                                                  /
- *                                               *SS - SI
- *                                              /
- *                                BasicScenarioC - *SS - SI   SI
- *                                /                          /
- *                             Row1                       *SS - SI
- *                            /                           /
- *             *ScenarioOutline1 - Row2 - BasicScenarioC  - *SS - SI
- *             /
- *      *Feature2
- *             \
- *             *ScenarioOutline2 - Row1 - BasicScenarioD - *SI
- *                           \
- *                           Row2
- *                              \
- *                               BasicScenarioD - *SI
- *
- * The starred nodes should contribute to the counts.
- *
- * Therefore we have
- *
- * 2  features
- * 4  scenarios
- * 10 scenario steps
- *
- * 
- * - * @author rbarefield - */ -public class ExecutionStatsTest { - - private ReportData reportData; - - private static final int FEATURES_EXPECTED = 2; - private static final int SCENARIOS_EXPECTED = 4; - private static final int SCENARIO_STEPS_EXPECTED = 10; - - @Before - public void setupDataAsAbove() { - - TestRootNodeBuilder rootBuilder = new TestRootNodeBuilder(); - - TestFeatureNodeBuilder feature1 = rootBuilder.addFeature(new Feature("Feature1", "File")); - TestFeatureNodeBuilder feature2 = rootBuilder.addFeature(new Feature("Feature2", "File")); - - TestBasicScenarioNodeBuilder scenarioA = feature1.addBasicScenario("ScenarioA"); - TestBasicScenarioNodeBuilder scenarioB = feature1.addBasicScenario("ScenarioB"); - - TestSubstepNodeBuilder aSubstep1 = scenarioA.addSubstep(); - aSubstep1.addSubstep().addStepImpl(getClass(), null); - aSubstep1.addSubstep().addStepImpl(getClass(), null); - scenarioA.addSubstep().addStepImpl(getClass(), null).addStepImpl(getClass(), null); - scenarioB.addStepImpl(getClass(), null).addSubstep().addStepImpl(getClass(), null); - - TestOutlineScenarioNodeBuilder scenarioOutline1 = feature2.addOutlineScenario("SO1"); - TestOutlineScenarioRowNodeBuilder row1 = scenarioOutline1.addRow(1); - TestOutlineScenarioRowNodeBuilder row2 = scenarioOutline1.addRow(2); - - TestBasicScenarioNodeBuilder basicScenarioC = row1.setBasicScenario("BasicScenarioC"); - basicScenarioC.addSubstep().addStepImpls(2, getClass(), null); - basicScenarioC.addSubstep().addStepImpl(getClass(), null); - row2.setBasicScenario(basicScenarioC); - - TestOutlineScenarioNodeBuilder scenarioOutline2 = feature2.addOutlineScenario("SO2"); - - TestOutlineScenarioRowNodeBuilder sO2Row1 = scenarioOutline2.addRow(0); - - TestBasicScenarioNodeBuilder basicScenarioD = sO2Row1.setBasicScenario("BasicScenarioD"); - basicScenarioD.addStepImpl(getClass(), null); - - TestOutlineScenarioRowNodeBuilder sO2Row2 = scenarioOutline2.addRow(1); - sO2Row2.setBasicScenario(basicScenarioD); - - reportData = new ReportData(); - reportData.addRootExecutionNode(rootBuilder.build()); - - } - - @Test - public void testCorrectNodesAreUsed() { - - ExecutionStats executionStats = new ExecutionStats(); - executionStats.buildStats(reportData); - - Assert.assertEquals(FEATURES_EXPECTED, executionStats.getTotalFeatures()); - Assert.assertEquals(SCENARIOS_EXPECTED, executionStats.getTotalScenarios()); - Assert.assertEquals(SCENARIO_STEPS_EXPECTED, executionStats.getTotalScenarioSteps()); - } -} diff --git a/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java b/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java index bf3c5e92..fcc63568 100644 --- a/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java +++ b/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java @@ -50,10 +50,11 @@ import java.util.*; import java.util.regex.Matcher; -import static org.hamcrest.CoreMatchers.any; import static org.hamcrest.CoreMatchers.is; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; + import static org.mockito.Mockito.*; /** @@ -112,7 +113,7 @@ public void testParseErrorResultsInFailedTest() { Assert.assertThat(scenarioNode.getResult().getResult(), is(ExecutionResult.PARSE_FAILURE)); - verify(notifier, times(1)).onNodeFailed(eq(scenarioNode), argThat(any(UnimplementedStepException.class))); + verify(notifier, times(1)).onNodeFailed(eq(scenarioNode), any(UnimplementedStepException.class)); Assert.assertThat(failures.size(), is(2)); @@ -148,7 +149,7 @@ public void testSubStepDefinitionMatchesStepImplFailure() { Assert.assertThat(scenarioNode.getResult().getResult(), is(ExecutionResult.PARSE_FAILURE)); - verify(notifier, times(1)).onNodeFailed(eq(scenarioNode), argThat(any(SubstepsConfigurationException.class))); + verify(notifier, times(1)).onNodeFailed(eq(scenarioNode), any(SubstepsConfigurationException.class)); Assert.assertThat(failures.size(), is(2)); @@ -193,7 +194,7 @@ public void testParseError2ResultsInFailedTest() { Assert.assertThat(scenarioOutlineNode2.getResult().getResult(), is(ExecutionResult.PARSE_FAILURE)); verify(notifier, times(1)).onNodeFailed(eq(scenarioOutlineNode2), - argThat(any(SubstepsConfigurationException.class))); + any(SubstepsConfigurationException.class)); } @@ -366,7 +367,7 @@ public void testNoTestsExecutedResultsInTwoFailures() { runner.run(); final List failures = runner.getFailures(); - verify(mockNotifer, times(1)).onNodeFailed(argThat(is(node)), argThat(any(NoTestsRunException.class))); + verify(mockNotifer, times(1)).onNodeFailed(eq(node), any(NoTestsRunException.class)); // verify(mockNotifer, times(1)).onNodeFailed(argThat(is(node)), argThat(any(SubstepsRuntimeException.class))); Assert.assertFalse("expecting some failures", failures.isEmpty()); @@ -407,11 +408,11 @@ public void testScenarioOutlineFailsWithNoExamples() { // list contains just those nodes that have actually failed, not the // entire tree. - verify(mockNotifer, times(2)).onNodeFailed(argThat(is(rootNode)), argThat(any(Throwable.class))); + verify(mockNotifer, times(2)).onNodeFailed(eq(rootNode), any(Throwable.class)); - verify(mockNotifer, times(1)).onNodeFailed(argThat(is(featureNode)), argThat(any(Throwable.class))); + verify(mockNotifer, times(1)).onNodeFailed(eq(featureNode), any(Throwable.class)); - verify(mockNotifer, times(1)).onNodeFailed(argThat(is(outlineNode)), argThat(any(Throwable.class))); + verify(mockNotifer, times(1)).onNodeFailed(eq(outlineNode), any(Throwable.class)); Assert.assertFalse("expecting some failures", failures.isEmpty()); diff --git a/core/src/test/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParserTest.java b/core/src/test/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParserTest.java index f6bddb08..749c7fa2 100644 --- a/core/src/test/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParserTest.java +++ b/core/src/test/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParserTest.java @@ -29,12 +29,11 @@ import java.io.File; import java.util.List; -import static org.hamcrest.CoreMatchers.any; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.fail; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -59,7 +58,7 @@ public void shouldReportDuplicateDefinition() { this.parser.parseSubStepFile(new File( "./target/test-classes/com/technophobia/substeps/runner/syntax/duplicate-definition.substeps")); - verify(this.errorReporter).reportSubstepsError(argThat(is(any(SubstepsParsingException.class)))); + verify(this.errorReporter).reportSubstepsError(any(SubstepsParsingException.class)); } @Test @@ -69,7 +68,7 @@ public void shouldReportEmptyDefinition() { this.parser.parseSubStepFile(new File( "./target/test-classes/com/technophobia/substeps/runner/syntax/empty-definition.substeps")); - verify(this.errorReporter).reportSubstepsError(argThat(is(any(SubstepsParsingException.class)))); + verify(this.errorReporter).reportSubstepsError(any(SubstepsParsingException.class)); } @Test diff --git a/core/src/test/java/com/technophobia/substeps/stepimplementations/MockStepImplementations.java b/core/src/test/java/com/technophobia/substeps/stepimplementations/MockStepImplementations.java index faca5b27..3894a738 100644 --- a/core/src/test/java/com/technophobia/substeps/stepimplementations/MockStepImplementations.java +++ b/core/src/test/java/com/technophobia/substeps/stepimplementations/MockStepImplementations.java @@ -21,7 +21,8 @@ import com.technophobia.substeps.model.SubSteps.Step; import com.technophobia.substeps.model.SubSteps.StepImplementations; import com.technophobia.substeps.runner.TestCallback; -import junit.framework.Assert; + +import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pom.xml b/pom.xml index 1b7125e6..fadb1c96 100644 --- a/pom.xml +++ b/pom.xml @@ -126,11 +126,11 @@ 1.0.0-SNAPSHOT - 1.7.13 + 1.7.14 4.12 1.3 - 2.0.2-beta + 2.7.19 21.0 0.7.6.201602180812 @@ -273,7 +273,7 @@ org.mockito - mockito-all + mockito-core ${mockito.version} test diff --git a/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java b/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java index e75eb0be..f2e217c5 100644 --- a/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java +++ b/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java @@ -4,9 +4,10 @@ import com.technophobia.substeps.model.exception.SubstepsRuntimeException; import com.technophobia.substeps.report.ExecutionReportBuilder; import com.technophobia.substeps.runner.*; -import junit.framework.Assert; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; +import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/runner/Junit/pom.xml b/runner/Junit/pom.xml index 37aa7837..56c2c15f 100644 --- a/runner/Junit/pom.xml +++ b/runner/Junit/pom.xml @@ -26,7 +26,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/runner/Junit/src/test/java/com/technophobia/substeps/runner/BaseJunitFeatureRunnerTest.java b/runner/Junit/src/test/java/com/technophobia/substeps/runner/BaseJunitFeatureRunnerTest.java index fc2de31f..ba79060b 100644 --- a/runner/Junit/src/test/java/com/technophobia/substeps/runner/BaseJunitFeatureRunnerTest.java +++ b/runner/Junit/src/test/java/com/technophobia/substeps/runner/BaseJunitFeatureRunnerTest.java @@ -36,7 +36,6 @@ */ public abstract class BaseJunitFeatureRunnerTest implements TestCallback { protected TestNotifier testNotifier = null; - // List invocations = null; protected List descriptionSnapshots = null; protected int descriptionSnapshotsIdx = 0; @@ -47,13 +46,12 @@ public abstract class BaseJunitFeatureRunnerTest implements TestCallback { @Before public void before() { testNotifier = new TestNotifier(); - // invocations = new ArrayList(); - descriptionKeys = new ArrayList(); + descriptionKeys = new ArrayList<>(); - descriptionSnapshots = new ArrayList(); + descriptionSnapshots = new ArrayList<>(); descriptionSnapshotsIdx = 0; - assertions = new ArrayList(); + assertions = new ArrayList<>(); } @@ -64,10 +62,6 @@ protected Map, Object> getImplsCache(final JunitFeatureRunner runner) { final Field runnerField = runner.getClass().getDeclaredField("runner"); runnerField.setAccessible(true); - // final Field runnerField = - // runner.getClass().getDeclaredField("scenarioRunner"); - // runnerField.setAccessible(true); - final Object runnerObject = runnerField.get(runner); final Field implCacheField = runnerObject.getClass().getDeclaredField("methodExecutor"); @@ -133,14 +127,6 @@ public void doCallback(final String methodName, final String[] params) { assertions.add(ae); } - // final Description current = testNotifier.getCurrentlyRunning(); - // if (current != null) - // { - // final String displayName = current.getDisplayName(); - // - // final String key = displayName.split(" ")[0]; - // - // } descriptionSnapshotsIdx++; // from this method name we want to get back to the description @@ -183,7 +169,7 @@ private void assertNotificationState() { List toKeyList(final List dess) { List rtn = null; if (dess != null) { - rtn = new ArrayList(); + rtn = new ArrayList<>(); for (final Description d : dess) { rtn.add(d.getDisplayName().split(" ")[0]); } diff --git a/runner/Junit/src/test/java/com/technophobia/substeps/runner/JunitFeatureRunnerTest.java b/runner/Junit/src/test/java/com/technophobia/substeps/runner/JunitFeatureRunnerTest.java index 79a60ed1..15b218e2 100644 --- a/runner/Junit/src/test/java/com/technophobia/substeps/runner/JunitFeatureRunnerTest.java +++ b/runner/Junit/src/test/java/com/technophobia/substeps/runner/JunitFeatureRunnerTest.java @@ -23,21 +23,18 @@ import com.technophobia.substeps.stepimplementations.MockStepImplementations; import com.technophobia.substeps.steps.TestStepImplementations; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.hamcrest.CoreMatchers.any; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; /** @@ -45,8 +42,6 @@ */ public class JunitFeatureRunnerTest extends BaseJunitFeatureRunnerTest { -// private static final String SUBSTEPS_RESOURCES_BASE_DIRECTORY = "../../core/src/test/resources/"; - private File baseResourcesDir; public JunitFeatureRunnerTest(){ @@ -56,12 +51,7 @@ public JunitFeatureRunnerTest(){ while (!found){ - File[] children = coreDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.endsWith("core"); - } - }); + File[] children = coreDir.listFiles((dir, name) -> name.endsWith("core")); if (children != null && children.length > 0){ found = true; @@ -70,7 +60,6 @@ public boolean accept(File dir, String name) { else { coreDir = coreDir.getAbsoluteFile().getParentFile(); } - } } @@ -87,7 +76,7 @@ public void testScenarioWithMissingStepsCausesFailure() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(TestStepImplementations.class); runner.init(this.getClass(), stepImplsList, feature, tag, substeps, null); @@ -102,7 +91,7 @@ public void testMissingSubStepCausesFailure() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(TestStepImplementations.class); runner.init(this.getClass(), stepImplsList, feature, tag, substeps, null); @@ -117,7 +106,7 @@ public void testTableParameterPassingWithOutlines() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(TestStepImplementations.class); runner.init(this.getClass(), stepImplsList, feature, tag, substeps, null); @@ -133,9 +122,9 @@ public void testTableParameterPassingWithOutlines() { runner.run(notifier); - final List> expectedTableParameter = new ArrayList>(); + final List> expectedTableParameter = new ArrayList<>(); - final Map row = new HashMap(); + final Map row = new HashMap<>(); expectedTableParameter.add(row); row.put("column1", "one"); @@ -153,7 +142,7 @@ public void testNestedParameterPassing() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(TestStepImplementations.class); runner.init(this.getClass(), stepImplsList, @@ -178,7 +167,7 @@ public void testNestedParameterPassing() { public void testRunFeaturesInFolders() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(TestStepImplementations.class); runner.init(this.getClass(), stepImplsList, getResourcePath( "features_dir"), null, @@ -206,7 +195,7 @@ public void testRunFeaturesInFolders() { public void testRunWithNoTags() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(MockStepImplementations.class); // pass in the stuff that would normally be placed in the annotation @@ -251,8 +240,8 @@ public void testRunWithNoTags() { verify(spy, times(1)).meth8("something in quotes"); verify(spy, times(1)).meth9(); - final List> table = new ArrayList>(); - final Map row = new HashMap(); + final List> table = new ArrayList<>(); + final Map row = new HashMap<>(); row.put("param1", "W"); row.put("param2", "X"); row.put("param3", "Y"); @@ -268,11 +257,11 @@ public void testRunWithNoTags() { int failed = 6; Assert.assertEquals(started, failed + finished); - verify(notifier, times(started)).fireTestStarted(argThat(any(Description.class))); + verify(notifier, times(started)).fireTestStarted(any(Description.class)); // this is now up to 25 as more of a hierarchy with outlines - verify(notifier, times(finished)).fireTestFinished(argThat(any(Description.class))); - verify(notifier, times(failed)).fireTestFailure(argThat(any(Failure.class))); + verify(notifier, times(finished)).fireTestFinished(any(Description.class)); + verify(notifier, times(failed)).fireTestFailure(any(Failure.class)); // test failures now cascade upwards verify(spy, times(1)).meth4("#quoted parameter"); @@ -289,7 +278,7 @@ public void testNotifications() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(MockStepImplementations.class); // pass in the stuff that would normally be placed in the annotation @@ -315,14 +304,11 @@ public void testNotifications() { verifyNotifications(notifier, rootDescription); - verify(notifier, never()).fireTestFailure(argThat(any(Failure.class))); + verify(notifier, never()).fireTestFailure(any(Failure.class)); } - /** - * @param notifier - * @param rootDescription - */ + private void verifyNotifications(final RunNotifier notifier, final Description rootDescription) { int idx = 1; @@ -361,7 +347,7 @@ public void testStepWithInlineTable() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(MockStepImplementations.class); // pass in the stuff that would normally be placed in the annotation @@ -382,8 +368,8 @@ public void testStepWithInlineTable() { // now verify that what was run was indeed run - final List> table = new ArrayList>(); - final Map row = new HashMap(); + final List> table = new ArrayList<>(); + final Map row = new HashMap<>(); row.put("param1", "W"); row.put("param2", "X"); row.put("param3", "Y"); @@ -398,7 +384,7 @@ public void testStepWithInlineTable() { public void testSubStepFailureHandledCorrectly() { final JunitFeatureRunner runner = new JunitFeatureRunner(); - final List> stepImplsList = new ArrayList>(); + final List> stepImplsList = new ArrayList<>(); stepImplsList.add(MockStepImplementations.class); // pass in the stuff that would normally be placed in the annotation @@ -427,9 +413,9 @@ public void testSubStepFailureHandledCorrectly() { verify(spy, never()).meth9(); verify(spy, never()).meth6(); - verify(notifier, times(6)).fireTestStarted(argThat(any(Description.class))); + verify(notifier, times(6)).fireTestStarted(any(Description.class)); - verify(notifier, times(5)).fireTestFailure(argThat(any(Failure.class))); + verify(notifier, times(5)).fireTestFailure(any(Failure.class)); } diff --git a/runner/Maven/pom.xml b/runner/Maven/pom.xml index 07a121c9..5ba02899 100644 --- a/runner/Maven/pom.xml +++ b/runner/Maven/pom.xml @@ -69,13 +69,6 @@ provided - - - org.jsoup - jsoup - 1.9.1 - - org.json4s json4s-core_2.11 @@ -124,10 +117,23 @@ gson + + org.apache.httpcomponents + httpclient + 4.5.3 + + org.eclipse.jgit org.eclipse.jgit - 4.6.0.201612231935-r + 4.6.1.201703071140-r + + + + org.apache.httpcomponents + httpclient + +