Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target/
pom.xml.versionsBackup
pom.xml.versionsBackup
88 changes: 82 additions & 6 deletions java/src/main/java/io/cucumber/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
Expand Down Expand Up @@ -74,11 +75,11 @@ public final class Query {
.collect(Collectors.toMap(identity(), (s) -> 0L));
private final Comparator<TestStepResult> testStepResultComparator = nullsFirst(comparing(o -> o.getStatus().ordinal()));
private final Map<String, TestCaseStarted> testCaseStartedById = new LinkedHashMap<>();
private final Map<String, TestCaseFinished> testCaseFinishedByTestCaseStartedId = new HashMap<>();
private final Map<String, List<TestStepFinished>> testStepsFinishedByTestCaseStartedId = new HashMap<>();
private final Map<String, List<TestStepStarted>> testStepsStartedByTestCaseStartedId = new HashMap<>();
private final Map<String, TestCaseFinished> testCaseFinishedByTestCaseStartedId = new LinkedHashMap<>();
private final Map<String, List<TestStepFinished>> testStepsFinishedByTestCaseStartedId = new LinkedHashMap<>();
private final Map<String, List<TestStepStarted>> testStepsStartedByTestCaseStartedId = new LinkedHashMap<>();
private final Map<String, Pickle> pickleById = new LinkedHashMap<>();
private final Map<String, TestCase> testCaseById = new HashMap<>();
private final Map<String, TestCase> testCaseById = new LinkedHashMap<>();
private final Map<String, Step> stepById = new LinkedHashMap<>();
private final Map<String, TestStep> testStepById = new LinkedHashMap<>();
private final Map<String, PickleStep> pickleStepById = new LinkedHashMap<>();
Expand Down Expand Up @@ -121,6 +122,12 @@ public List<TestCaseStarted> findAllTestCaseStarted() {
.collect(toList());
}

public List<TestCaseFinished> findAllTestCaseFinished() {
return this.testCaseFinishedByTestCaseStartedId.values().stream()
.filter(TestCaseFinished::getWillBeRetried)
.collect(toList());
}

public Map<Optional<Feature>, List<TestCaseStarted>> findAllTestCaseStartedGroupedByFeature() {
return findAllTestCaseStarted()
.stream()
Expand All @@ -144,6 +151,22 @@ public List<TestStep> findAllTestSteps() {
return new ArrayList<>(testStepById.values());
}

public List<TestCase> findAllTestCases() {
return new ArrayList<>(testCaseById.values());
}

public List<TestStepStarted> findAllTestStepsStarted() {
return testStepsStartedByTestCaseStartedId.values().stream()
.flatMap(Collection::stream)
.collect(toList());
}

public List<TestStepFinished> findAllTestStepsFinished() {
return testStepsFinishedByTestCaseStartedId.values().stream()
.flatMap(Collection::stream)
.collect(toList());
}

public List<Attachment> findAttachmentsBy(TestStepFinished testStepFinished) {
requireNonNull(testStepFinished);
return attachmentsByTestCaseStartedId.getOrDefault(testStepFinished.getTestCaseStartedId(), emptyList()).stream()
Expand Down Expand Up @@ -173,6 +196,12 @@ public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseStarted t
.stream()
.map(TestStepFinished::getTestStepResult)
.max(testStepResultComparator);
}

public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
return findTestCaseStartedBy(testCaseFinished)
.flatMap(this::findMostSevereTestStepResultBy);
}

public String findNameOf(GherkinDocument element, NamingStrategy namingStrategy) {
Expand Down Expand Up @@ -247,8 +276,18 @@ public Optional<Location> findLocationOf(Pickle pickle) {
public Optional<Pickle> findPickleBy(TestCaseStarted testCaseStarted) {
requireNonNull(testCaseStarted);
return findTestCaseBy(testCaseStarted)
.map(TestCase::getPickleId)
.map(pickleById::get);
.flatMap(this::findPickleBy);
}

public Optional<Pickle> findPickleBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
return findTestCaseStartedBy(testCaseFinished)
.flatMap(this::findPickleBy);
}

public Optional<Pickle> findPickleBy(TestCase testCase) {
requireNonNull(testCase);
return ofNullable(pickleById.get(testCase.getPickleId()));
}

public Optional<Pickle> findPickleBy(TestStepStarted testStepStarted) {
Expand Down Expand Up @@ -290,13 +329,25 @@ public Optional<TestCase> findTestCaseBy(TestCaseStarted testCaseStarted) {
requireNonNull(testCaseStarted);
return ofNullable(testCaseById.get(testCaseStarted.getTestCaseId()));
}

public Optional<TestCase> findTestCaseBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
return findTestCaseStartedBy(testCaseFinished)
.flatMap(this::findTestCaseBy);
}

public Optional<TestCase> findTestCaseBy(TestStepStarted testStepStarted) {
requireNonNull(testStepStarted);
return findTestCaseStartedBy(testStepStarted)
.flatMap(this::findTestCaseBy);
}

public Optional<TestCase> findTestCaseBy(TestStepFinished testStepFinished) {
requireNonNull(testStepFinished);
return findTestCaseStartedBy(testStepFinished)
.flatMap(this::findTestCaseBy);
}

public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted) {
requireNonNull(testCaseStarted);
Timestamp started = testCaseStarted.getTimestamp();
Expand All @@ -307,13 +358,31 @@ public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted
Convertor.toInstant(finished)
));
}

public Optional<Duration> findTestCaseDurationBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
return findTestCaseStartedBy(testCaseFinished)
.flatMap(this::findTestCaseDurationBy);
}

public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepStarted testStepStarted) {
requireNonNull(testStepStarted);
String testCaseStartedId = testStepStarted.getTestCaseStartedId();
return ofNullable(testCaseStartedById.get(testCaseStartedId));
}

private Optional<TestCaseStarted> findTestCaseStartedBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
String testCaseStartedId = testCaseFinished.getTestCaseStartedId();
return ofNullable(testCaseStartedById.get(testCaseStartedId));
}

public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepFinished testStepFinished) {
requireNonNull(testStepFinished);
String testCaseStartedId = testStepFinished.getTestCaseStartedId();
return ofNullable(testCaseStartedById.get(testCaseStartedId));
}

public Optional<TestCaseFinished> findTestCaseFinishedBy(TestCaseStarted testCaseStarted) {
requireNonNull(testCaseStarted);
return ofNullable(testCaseFinishedByTestCaseStartedId.get(testCaseStarted.getId()));
Expand Down Expand Up @@ -364,6 +433,13 @@ public List<TestStepFinished> findTestStepsFinishedBy(TestCaseStarted testCaseSt
return new ArrayList<>(testStepsFinished);
}

public List<TestStepFinished> findTestStepsFinishedBy(TestCaseFinished testCaseFinished) {
requireNonNull(testCaseFinished);
return findTestCaseStartedBy(testCaseFinished)
.map(this::findTestStepsFinishedBy)
.orElseGet(ArrayList::new);
}

public List<Entry<TestStepFinished, TestStep>> findTestStepFinishedAndTestStepBy(TestCaseStarted testCaseStarted) {
return findTestStepsFinishedBy(testCaseStarted).stream()
.map(testStepFinished -> findTestStepBy(testStepFinished).map(testStep -> new SimpleEntry<>(testStepFinished, testStep)))
Expand Down