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
39 changes: 0 additions & 39 deletions .github/workflows/test-testdata.yml

This file was deleted.

5 changes: 5 additions & 0 deletions compatibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>compatibility-kit</artifactId>
<version>23.2.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.cucumber.core.options.RuntimeOptionsBuilder;
import io.cucumber.core.order.PickleOrder;
import io.cucumber.core.order.StandardPickleOrders;
import io.cucumber.core.plugin.MessageFormatter;
import io.cucumber.core.runtime.Runtime;
import org.hamcrest.Matcher;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -23,6 +29,8 @@
import java.util.Map;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.newBufferedReader;
import static java.nio.file.Files.newOutputStream;
import static java.util.Collections.emptyList;
import static org.hamcrest.CoreMatchers.is;
Expand All @@ -35,17 +43,23 @@ public class CompatibilityTest {
@ParameterizedTest
@MethodSource("io.cucumber.compatibility.TestCase#testCases")
void produces_expected_output_for(TestCase testCase) throws IOException {
Path parentDir = Files.createDirectories(Paths.get("target", "messages",
testCase.getId()));


Path parentDir = Files.createDirectories(Paths.get("target", "messages", testCase.getId()));
Path outputNdjson = parentDir.resolve("out.ndjson");

try {
PickleOrder pickleOrder = StandardPickleOrders.lexicalUriOrder();
if ("multiple-features-reversed".equals(testCase.getId())) {
pickleOrder = StandardPickleOrders.reverseLexicalUriOrder();
}
Runtime.builder()
.withRuntimeOptions(new RuntimeOptionsBuilder()
.addGlue(testCase.getGlue())
.setPickleOrder(pickleOrder)
.addFeature(testCase.getFeatures()).build())
.withAdditionalPlugins(
new MessageFormatter(newOutputStream(outputNdjson)))
new MessageFormatter(newOutputStream(outputNdjson)))
.build()
.run();
} catch (Exception e) {
Expand All @@ -71,8 +85,18 @@ void produces_expected_output_for(TestCase testCase) throws IOException {
return;
}

// exception: Cucumber JVM does not support messages for global hooks
if ("global-hooks".equals(testCase.getId())
|| "global-hooks-afterall-error".equals(testCase.getId())
|| "global-hooks-attachments".equals(testCase.getId())
|| "global-hooks-beforeall-error".equals(testCase.getId())

) {
return;
}

List<JsonNode> expected = readAllMessages(testCase.getExpectedFile());
List<JsonNode> actual = readAllMessages(outputNdjson);
List<JsonNode> actual = readAllMessages(Files.newInputStream(outputNdjson));

Map<String, List<JsonNode>> expectedEnvelopes = openEnvelopes(expected);
Map<String, List<JsonNode>> actualEnvelopes = openEnvelopes(actual);
Expand Down Expand Up @@ -104,19 +128,19 @@ void produces_expected_output_for(TestCase testCase) throws IOException {
}

expectedEnvelopes.forEach((messageType, expectedMessages) -> assertThat(
actualEnvelopes,
hasEntry(is(messageType),
containsInRelativeOrder(aComparableMessage(messageType, expectedMessages)))));
actualEnvelopes,
hasEntry(is(messageType),
containsInRelativeOrder(aComparableMessage(messageType, expectedMessages)))));
}

private static List<JsonNode> readAllMessages(Path output) throws IOException {
private static List<JsonNode> readAllMessages(InputStream output) throws IOException {
List<JsonNode> expectedEnvelopes = new ArrayList<>();

ObjectMapper mapper = new ObjectMapper()
.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

Files.readAllLines(output).forEach(s -> {
readAllLines(output).forEach(s -> {
try {
expectedEnvelopes.add(mapper.readTree(s));
} catch (JsonProcessingException e) {
Expand All @@ -127,6 +151,17 @@ private static List<JsonNode> readAllMessages(Path output) throws IOException {
return expectedEnvelopes;
}

public static List<String> readAllLines(InputStream is) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) {
List<String> lines = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
return lines;
}
}

@SuppressWarnings("unchecked")
private static <T> Map<String, List<T>> openEnvelopes(List<JsonNode> actual) {
Map<String, List<T>> map = new LinkedHashMap<>();
Expand Down
40 changes: 20 additions & 20 deletions compatibility/src/test/java/io/cucumber/compatibility/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

import io.cucumber.core.feature.FeatureWithLines;
import io.cucumber.core.feature.GluePath;
import org.junit.platform.commons.support.Resource;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import static java.util.Comparator.comparing;
import static org.junit.platform.commons.support.ReflectionSupport.findAllResourcesInPackage;

final class TestCase {

private static final String FEATURES_DIRECTORY = "src/test/resources/features";
private static final String FEATURES_PACKAGE = "io.cucumber.compatibility";
private static final String TEST_CASES_PACKAGE = "io.cucumber.compatibilitykit";
private static final String GLUE_PACKAGE = "io.cucumber.compatibility";

private final String id;

private TestCase(String id) {
this.id = id;
private final String testCaseResourceName;
private final Resource expected;

private TestCase(Resource expected) {
this.expected = expected;
String expectedResourceName = expected.getName();
this.testCaseResourceName = expectedResourceName.substring(0, expectedResourceName.lastIndexOf('/'));
this.id = testCaseResourceName.substring(testCaseResourceName.lastIndexOf('/') + 1);
}

static List<TestCase> testCases() throws IOException {
List<Resource> expectedFiles = findAllResourcesInPackage(TEST_CASES_PACKAGE, resource -> resource.getName().endsWith(".ndjson"));
List<TestCase> testCases = new ArrayList<>();
Path dir = Paths.get(FEATURES_DIRECTORY);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path path : stream) {
if (path.toFile().isDirectory()) {
testCases.add(new TestCase(path.getFileName().toString()));
}
}
for (Resource expected : expectedFiles) {
testCases.add(new TestCase(expected));
}
testCases.sort(comparing(TestCase::getId));
return testCases;
Expand All @@ -44,15 +44,15 @@ String getId() {
}

URI getGlue() {
return GluePath.parse(FEATURES_PACKAGE + "." + id.replace("-", ""));
return GluePath.parse(GLUE_PACKAGE + "." + id.replace("-", ""));
}

FeatureWithLines getFeatures() {
return FeatureWithLines.parse("file:" + FEATURES_DIRECTORY + "/" + id);
return FeatureWithLines.parse("classpath:" + testCaseResourceName);
}

Path getExpectedFile() {
return Paths.get(FEATURES_DIRECTORY + "/" + id + "/" + id + ".ndjson");
InputStream getExpectedFile() throws IOException {
return expected.getInputStream();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.cucumber.compatibility.ambiguous;

import io.cucumber.java.en.Given;

public class Ambiguous {

@Given("^a step with (.*)$")
public void second_ambiguous_step(String a) {

}

@Given("^a (.*?) with (.*?)$")
public void first_ambiguous_step(String a, String b) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.cucumber.compatibility.backgrounds;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class Backgrounds {

@Given("an order for {string}")
public void context(String item) {

}

@When("an action")
public void action() {

}

@Then("an outcome")
public void outcome() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cucumber.compatibility.docstrings;

import io.cucumber.java.en.Given;

public class DocStrings {

@Given("a doc string:")
public void docString(String docString) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cucumber.compatibility.multiplefeatures;

import io.cucumber.java.en.Given;

public class MultipleFeatures {

@Given("an order for {string}")
public void an_order_for_item(String item) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cucumber.compatibility.multiplefeaturesreversed;

import io.cucumber.java.en.Given;

public class MultipleFeatures {

@Given("an order for {string}")
public void an_order_for_item(String item) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.cucumber.compatibility.regularexpression;

import io.cucumber.java.en.Given;

public class RegularExpression {
@Given("^a (.*?)(?: and a (.*?))?(?: and a (.*?))?$")
public void some_vegetables(String a, String b, String c) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.cucumber.compatibility.rulesbackgrounds;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class RulesBackgrounds {

@Given("an order for {string}")
public void context(String item) {

}

@When("an action")
public void action() {

}

@Then("an outcome")
public void outcome() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.cucumber.compatibility.unusedsteps;

import io.cucumber.java.en.Given;

public class UnusedSteps {

@Given("a step that is used")
public void a_step_that_is_used() {

}

@Given("a step that is not used")
public void a_step_that_is_not_used() {

}

}
3 changes: 0 additions & 3 deletions compatibility/src/test/resources/.gitattributes

This file was deleted.

2 changes: 0 additions & 2 deletions compatibility/src/test/resources/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions compatibility/src/test/resources/README.md

This file was deleted.

Loading
Loading