Skip to content

Commit

Permalink
cached step names without placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Jun 10, 2024
1 parent 97b6a11 commit 54427d9
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 27 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [3.6.3] - 2024-06-10

### Changed

* Cached slow method results to speed up report generation (#343), contributed by @simonstratmann

## [3.6.2] - 2024-03-25

### Fixed
Expand Down Expand Up @@ -871,7 +877,9 @@ the core component is now the reporting engine that is the base for other forms

Initial project version on GitHub and Maven Central.

[3.6.2]: https://github.com/trivago/cluecumber-report-plugin/tree/v3.6.2ss
[3.6.3]: https://github.com/trivago/cluecumber-report-plugin/tree/v3.6.3

[3.6.2]: https://github.com/trivago/cluecumber-report-plugin/tree/v3.6.2

[3.6.1]: https://github.com/trivago/cluecumber-report-plugin/tree/v3.6.1

Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>cluecumber-core</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<packaging>jar</packaging>

<parent>
<artifactId>cluecumber-parent</artifactId>
<groupId>com.trivago.rta</groupId>
<version>3.6.2</version>
<version>3.6.3</version>
</parent>

<name>Cluecumber Core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class CluecumberCore {

private final CluecumberEngine cluecumberEngine;

/**
* The constructor for the Cluecumber core.
* @param builder The builder instance.
* @throws CluecumberException Thrown in case of any error.
*/
private CluecumberCore(Builder builder) throws CluecumberException {
cluecumberEngine = DaggerCluecumberCoreGraph.create().getCluecumberEngine();
cluecumberEngine.setCustomCssFile(builder.customCssFile);
Expand Down
12 changes: 6 additions & 6 deletions engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<parent>
<artifactId>cluecumber-parent</artifactId>
<groupId>com.trivago.rta</groupId>
<version>3.6.2</version>
<version>3.6.3</version>
</parent>

<artifactId>cluecumber-engine</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<packaging>jar</packaging>

<name>Cluecumber Engine</name>
Expand All @@ -29,11 +29,11 @@
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<tinylog-impl.version>2.7.0</tinylog-impl.version>
<freemarker.version>2.3.32</freemarker.version>
<tinylog-impl.version>2.8.0-M1</tinylog-impl.version>
<freemarker.version>2.3.33</freemarker.version>
<gson-fire.version>1.9.0</gson-fire.version>
<gson.version>2.10.1</gson.version>
<dagger.version>2.51</dagger.version>
<gson.version>2.11.0</gson.version>
<dagger.version>2.51.1</dagger.version>
<property-aggregator.version>1.5.0</property-aggregator.version>
<properties-maven-plugin.version>1.1.0</properties-maven-plugin.version>
<openpojo.version>0.9.1</openpojo.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.trivago.cluecumber.engine.rendering.pages.renderering.RenderingUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -40,6 +42,8 @@ public class Step extends ResultMatch {
private int index = 0;
private boolean hasSubSections = false;

private static final Map<String, String> stepMatchToNameWithArgumentPlaceholders = new HashMap<>();

/**
* Check if there are before or after step hooks with content.
*
Expand Down Expand Up @@ -149,15 +153,17 @@ public String returnNameWithArguments() {
* @return The scenario name with empty arguments.
*/
public String returnNameWithArgumentPlaceholders() {
String tmpName = getName();
List<Argument> arguments = getArguments();
for (int i = arguments.size() - 1; i >= 0; i--) {
String argument = arguments.get(i).getVal();
if (argument != null) {
tmpName = tmpName.replaceFirst(Pattern.quote(argument), Matcher.quoteReplacement("{}"));
return stepMatchToNameWithArgumentPlaceholders.computeIfAbsent(getMatch().getLocation(), matchName -> {
String tmpName = getName();
List<Argument> arguments = getArguments();
for (int i = arguments.size() - 1; i >= 0; i--) {
String argument = arguments.get(i).getVal();
if (argument != null) {
tmpName = tmpName.replaceFirst(Pattern.quote(argument), Matcher.quoteReplacement("{}"));
}
}
}
return tmpName;
return tmpName;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public void returnNameWithArgumentPlaceholdersTest() {
argument.setVal("argument");
arguments.add(argument);
when(step.getArguments()).thenReturn(arguments);
Match match = mock(Match.class);
when(match.getLocation()).thenReturn("location");
when(step.getMatch()).thenReturn(match);
step.setResult(result);
assertEquals(step.returnNameWithArgumentPlaceholders(), "This is a name with an {} inside.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private List<Report> getTestReports() {
result.setStatus(Status.SKIPPED.getStatusString());
step.setResult(result);
match = new Match();
match.setLocation("location2");
match.setLocation("location3");
step.setMatch(match);
steps.add(step);
element.setSteps(steps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ public void visitTest() throws CluecumberException {
stepVisitor.visit(getAllScenarioPageCollection());
verify(fileIo, times(1))
.writeContentToFile("MyRenderedSteps", "dummyPath/pages/step-summary.html");
verify(fileIo, times(1))
.writeContentToFile("MyRenderedScenarios", "dummyPath/pages/step-scenarios/step_732281846.html");
}
}
2 changes: 1 addition & 1 deletion examples/maven-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>blog.softwaretester</groupId>
<artifactId>maven-example</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<packaging>pom</packaging>

<properties>
Expand Down
6 changes: 5 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
build-and-test:
mvn clean install
mvn verify -f=examples/maven-example -e
open examples/maven-example/target/cluecumber-report/pages/scenario-detail/scenario_1.html
open examples/maven-example/target/cluecumber-report/pages/scenario-detail/scenario_1.html

show-versions:
mvn versions:display-dependency-updates
mvn versions:display-plugin-updates
4 changes: 2 additions & 2 deletions maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<artifactId>cluecumber-maven</artifactId>
<packaging>maven-plugin</packaging>
<version>3.6.2</version>
<version>3.6.3</version>

<parent>
<artifactId>cluecumber-parent</artifactId>
<groupId>com.trivago.rta</groupId>
<version>3.6.2</version>
<version>3.6.3</version>
</parent>

<name>Cluecumber Maven</name>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-parent</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<packaging>pom</packaging>

<name>Cluecumber Parent</name>
Expand All @@ -32,8 +32,8 @@
<maven.version>3.11.0</maven.version>
<maven.gpg.plugin.version>3.1.0</maven.gpg.plugin.version>
<nexus.staging.maven.plugin.version>1.6.13</nexus.staging.maven.plugin.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<mockito-core.version>5.11.0</mockito-core.version>
<junit-jupiter.version>5.11.0-M2</junit-jupiter.version>
<mockito-core.version>5.12.0</mockito-core.version>
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
Expand Down

0 comments on commit 54427d9

Please sign in to comment.