Search in sources :

Example 1 with Location

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

the class Runner method emitSnippetSuggestedEvent.

private void emitSnippetSuggestedEvent(Pickle pickle, Step step) {
    List<String> snippets = generateSnippetsForStep(step);
    if (snippets.isEmpty()) {
        return;
    }
    Suggestion suggestion = new Suggestion(step.getText(), snippets);
    Location scenarioLocation = pickle.getLocation();
    Location stepLocation = step.getLocation();
    SnippetsSuggestedEvent event = new SnippetsSuggestedEvent(bus.getInstant(), pickle.getUri(), scenarioLocation, stepLocation, suggestion);
    bus.send(event);
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) Location(io.cucumber.plugin.event.Location)

Example 2 with Location

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

the class PickleOrderTest method reverse_lexical_uri_order.

@Test
void reverse_lexical_uri_order() {
    when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
    when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
    when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
    when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
    when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
    PickleOrder order = StandardPickleOrders.reverseLexicalUriOrder();
    List<Pickle> pickles = order.orderPickles(Arrays.asList(secondPickle, thirdPickle, firstPickle));
    assertThat(pickles, contains(thirdPickle, secondPickle, firstPickle));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) Location(io.cucumber.plugin.event.Location) Test(org.junit.jupiter.api.Test)

Example 3 with Location

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

the class PickleOrderTest method lexical_uri_order.

@Test
void lexical_uri_order() {
    when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
    when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
    when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
    when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
    when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
    PickleOrder order = StandardPickleOrders.lexicalUriOrder();
    List<Pickle> pickles = order.orderPickles(Arrays.asList(thirdPickle, secondPickle, firstPickle));
    assertThat(pickles, contains(firstPickle, secondPickle, thirdPickle));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) Location(io.cucumber.plugin.event.Location) Test(org.junit.jupiter.api.Test)

Example 4 with Location

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

the class TeamCityPlugin method getSnippets.

private String getSnippets(TestCase testCase) {
    URI uri = testCase.getUri();
    Location location = testCase.getLocation();
    List<Suggestion> suggestionForTestCase = suggestions.stream().filter(suggestion -> suggestion.getUri().equals(uri) && suggestion.getTestCaseLocation().equals(location)).map(SnippetsSuggestedEvent::getSuggestion).collect(Collectors.toList());
    return createMessage(suggestionForTestCase);
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) URI(java.net.URI) Location(io.cucumber.plugin.event.Location)

Example 5 with Location

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

the class TimelineFormatter method findRootNodeName.

private String findRootNodeName(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 : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) TestSourceParsed(io.cucumber.plugin.event.TestSourceParsed) HashMap(java.util.HashMap) TestCase(io.cucumber.plugin.event.TestCase) ObjectMapper(io.cucumber.messages.internal.com.fasterxml.jackson.databind.ObjectMapper) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Map(java.util.Map) URI(java.net.URI) ROOT(java.util.Locale.ROOT) EventPublisher(io.cucumber.plugin.event.EventPublisher) OutputStream(java.io.OutputStream) Include(io.cucumber.messages.internal.com.fasterxml.jackson.annotation.JsonInclude.Include) TestCaseEvent(io.cucumber.plugin.event.TestCaseEvent) Predicate(java.util.function.Predicate) SerializationFeature(io.cucumber.messages.internal.com.fasterxml.jackson.databind.SerializationFeature) Collection(java.util.Collection) FileOutputStream(java.io.FileOutputStream) Node(io.cucumber.plugin.event.Node) IOException(java.io.IOException) Location(io.cucumber.plugin.event.Location) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Feature(io.cucumber.messages.internal.com.fasterxml.jackson.core.JsonGenerator.Feature) TreeMap(java.util.TreeMap) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Closeable(java.io.Closeable) Optional(java.util.Optional) CucumberException(io.cucumber.core.exception.CucumberException) InputStream(java.io.InputStream) Optional(java.util.Optional) Node(io.cucumber.plugin.event.Node) 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