Search in sources :

Example 6 with Location

use of io.cucumber.plugin.event.Location in project cucumber-jvm by cucumber.

the class GherkinMessagesPickle method createCucumberSteps.

private static List<Step> createCucumberSteps(io.cucumber.messages.types.Pickle pickle, GherkinDialect dialect, CucumberQuery cucumberQuery) {
    List<Step> list = new ArrayList<>();
    String previousGivenWhenThen = dialect.getGivenKeywords().stream().filter(s -> !StepType.isAstrix(s)).findFirst().orElseThrow(() -> new IllegalStateException("No Given keyword for dialect: " + dialect.getName()));
    for (io.cucumber.messages.types.PickleStep pickleStep : pickle.getSteps()) {
        String gherkinStepId = pickleStep.getAstNodeIds().get(0);
        io.cucumber.messages.types.Step gherkinStep = cucumberQuery.getGherkinStep(gherkinStepId);
        Location location = GherkinMessagesLocation.from(gherkinStep.getLocation());
        String keyword = gherkinStep.getKeyword();
        Step step = new GherkinMessagesStep(pickleStep, dialect, previousGivenWhenThen, location, keyword);
        if (step.getType().isGivenWhenThen()) {
            previousGivenWhenThen = step.getKeyword();
        }
        list.add(step);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Step(io.cucumber.core.gherkin.Step) Location(io.cucumber.plugin.event.Location)

Example 7 with Location

use of io.cucumber.plugin.event.Location in project cucumber-jvm by cucumber.

the class TeamCityPlugin method printTestCaseStarted.

private void printTestCaseStarted(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    URI uri = testCase.getUri();
    String timestamp = extractTimeStamp(event);
    Location location = testCase.getLocation();
    Predicate<Node> withLocation = candidate -> location.equals(candidate.getLocation());
    List<Node> path = parsedTestSources.get(uri).stream().map(node -> node.findPathTo(withLocation)).filter(Optional::isPresent).map(Optional::get).findFirst().orElse(emptyList());
    poppedNodes(path).forEach(node -> finishNode(timestamp, node));
    pushedNodes(path).forEach(node -> startNode(uri, timestamp, node));
    this.currentStack = path;
    this.currentTestCase = testCase;
    print(TEMPLATE_PROGRESS_TEST_STARTED, timestamp);
}
Also used : TestStepStarted(io.cucumber.plugin.event.TestStepStarted) ExceptionUtils.printStackTrace(io.cucumber.core.exception.ExceptionUtils.printStackTrace) ZonedDateTime(java.time.ZonedDateTime) TestStep(io.cucumber.plugin.event.TestStep) TestSourceParsed(io.cucumber.plugin.event.TestSourceParsed) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) HashMap(java.util.HashMap) Status(io.cucumber.plugin.event.Status) TestCase(io.cucumber.plugin.event.TestCase) Supplier(java.util.function.Supplier) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Matcher(java.util.regex.Matcher) EmbedEvent(io.cucumber.plugin.event.EmbedEvent) WriteEvent(io.cucumber.plugin.event.WriteEvent) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Locale(java.util.Locale) Map(java.util.Map) HookTestStep(io.cucumber.plugin.event.HookTestStep) URI(java.net.URI) ZoneOffset(java.time.ZoneOffset) Event(io.cucumber.plugin.event.Event) EventPublisher(io.cucumber.plugin.event.EventPublisher) PrintStream(java.io.PrintStream) Result(io.cucumber.plugin.event.Result) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Node(io.cucumber.plugin.event.Node) Location(io.cucumber.plugin.event.Location) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) HookType(io.cucumber.plugin.event.HookType) List(java.util.List) Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Optional(java.util.Optional) TestCase(io.cucumber.plugin.event.TestCase) Node(io.cucumber.plugin.event.Node) URI(java.net.URI) Location(io.cucumber.plugin.event.Location)

Example 8 with Location

use of io.cucumber.plugin.event.Location in project cucumber-jvm by cucumber.

the class TestNGFormatter method findRootNodeName.

private String findRootNodeName(io.cucumber.plugin.event.TestCase testCase) {
    Location location = testCase.getLocation();
    Predicate<Node> withLocation = candidate -> candidate.getLocation().equals(location);
    return parsedTestSources.get(testCase.getUri()).stream().map(node -> node.findPathTo(withLocation)).filter(Optional::isPresent).map(Optional::get).findFirst().map(nodes -> nodes.get(0)).flatMap(Node::getName).orElse("Unknown");
}
Also used : Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) TransformerException(javax.xml.transform.TransformerException) ExceptionUtils.printStackTrace(io.cucumber.core.exception.ExceptionUtils.printStackTrace) StreamResult(javax.xml.transform.stream.StreamResult) TestSourceParsed(io.cucumber.plugin.event.TestSourceParsed) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) HashMap(java.util.HashMap) Status(io.cucumber.plugin.event.Status) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Document(org.w3c.dom.Document) Duration(java.time.Duration) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) URI(java.net.URI) ROOT(java.util.Locale.ROOT) XMLConstants(javax.xml.XMLConstants) EventPublisher(io.cucumber.plugin.event.EventPublisher) OutputStream(java.io.OutputStream) Result(io.cucumber.plugin.event.Result) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Node(io.cucumber.plugin.event.Node) IOException(java.io.IOException) ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) Location(io.cucumber.plugin.event.Location) OutputKeys(javax.xml.transform.OutputKeys) Instant(java.time.Instant) List(java.util.List) Element(org.w3c.dom.Element) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Closeable(java.io.Closeable) Writer(java.io.Writer) ZERO(java.time.Duration.ZERO) Optional(java.util.Optional) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) CucumberException(io.cucumber.core.exception.CucumberException) Optional(java.util.Optional) Node(io.cucumber.plugin.event.Node) Location(io.cucumber.plugin.event.Location)

Example 9 with Location

use of io.cucumber.plugin.event.Location in project cucumber-jvm by cucumber.

the class DefaultSummaryPrinterTest method does_not_print_duplicate_snippets.

@Test
void does_not_print_duplicate_snippets() {
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(13, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(14, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
    assertThat(new String(out.toByteArray(), UTF_8), equalToCompressingWhiteSpace("" + "\n" + "0 Scenarios\n" + "0 Steps\n" + "0m0.000s\n" + "\n" + "\n" + "You can implement missing steps with the snippets below:\n" + "\n" + "snippet\n" + "\n" + "\n"));
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Location(io.cucumber.plugin.event.Location) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 10 with Location

use of io.cucumber.plugin.event.Location in project cucumber-jvm by cucumber.

the class CanonicalEventOrderTest method createTestCaseEvent.

private static TestCaseStarted createTestCaseEvent(Instant instant, URI uri, int line) {
    final TestCase testCase = mock(TestCase.class);
    given(testCase.getUri()).willReturn(uri);
    given(testCase.getLocation()).willReturn(new Location(line, -1));
    return new TestCaseStarted(instant, testCase);
}
Also used : TestCase(io.cucumber.plugin.event.TestCase) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Location(io.cucumber.plugin.event.Location)

Aggregations

Location (io.cucumber.plugin.event.Location)10 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)4 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)4 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)4 URI (java.net.URI)4 EventPublisher (io.cucumber.plugin.event.EventPublisher)3 Node (io.cucumber.plugin.event.Node)3 Result (io.cucumber.plugin.event.Result)3 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)3 TestCase (io.cucumber.plugin.event.TestCase)3 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)3 TestSourceParsed (io.cucumber.plugin.event.TestSourceParsed)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Predicate (java.util.function.Predicate)3 CucumberException (io.cucumber.core.exception.CucumberException)2 ExceptionUtils.printStackTrace (io.cucumber.core.exception.ExceptionUtils.printStackTrace)2