Search in sources :

Example 1 with TestCase

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

the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.

@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
    EventHandler handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    TestCase testCase = mock(TestCase.class);
    TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler, never()).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase) EventHandler(io.cucumber.plugin.event.EventHandler) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 2 with TestCase

use of io.cucumber.plugin.event.TestCase 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)

Example 3 with TestCase

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

the class TimelineFormatter method handleTestCaseStarted.

private void handleTestCaseStarted(TestCaseStarted event) {
    Thread thread = Thread.currentThread();
    threadGroups.computeIfAbsent(thread.getId(), threadId -> {
        GroupData group = new GroupData();
        group.setContent(thread.toString());
        group.setId(threadId);
        return group;
    });
    TestCase testCase = event.getTestCase();
    TestData data = new TestData();
    data.setId(getId(event));
    data.setFeature(findRootNodeName(testCase));
    data.setScenario(testCase.getName());
    data.setStart(event.getInstant().toEpochMilli());
    data.setTags(buildTagsValue(testCase));
    data.setGroup(thread.getId());
    allTests.put(data.getId(), data);
}
Also used : TestCase(io.cucumber.plugin.event.TestCase)

Example 4 with TestCase

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

the class JsonFormatter method createTestCase.

private Map<String, Object> createTestCase(TestCaseStarted event) {
    Map<String, Object> testCaseMap = new HashMap<>();
    testCaseMap.put("start_timestamp", getDateTimeFromTimeStamp(event.getInstant()));
    TestCase testCase = event.getTestCase();
    testCaseMap.put("name", testCase.getName());
    testCaseMap.put("line", testCase.getLine());
    testCaseMap.put("type", "scenario");
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine());
    if (astNode != null) {
        testCaseMap.put("id", TestSourcesModel.calculateId(astNode));
        Scenario scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode);
        testCaseMap.put("keyword", scenarioDefinition.getKeyword());
        testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : "");
    }
    testCaseMap.put("steps", new ArrayList<Map<String, Object>>());
    if (!testCase.getTags().isEmpty()) {
        List<Map<String, Object>> tagList = new ArrayList<>();
        for (String tag : testCase.getTags()) {
            Map<String, Object> tagMap = new HashMap<>();
            tagMap.put("name", tag);
            tagList.add(tagMap);
        }
        testCaseMap.put("tags", tagList);
    }
    return testCaseMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestCase(io.cucumber.plugin.event.TestCase) TestSourcesModel.getBackgroundForTestCase(io.cucumber.core.plugin.TestSourcesModel.getBackgroundForTestCase) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Scenario(io.cucumber.messages.types.Scenario)

Example 5 with TestCase

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

the class PrettyFormatter method printScenarioDefinition.

private void printScenarioDefinition(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    String definitionText = formatScenarioDefinition(testCase);
    String path = relativize(testCase.getUri()).getSchemeSpecificPart();
    String locationIndent = calculateLocationIndent(event.getTestCase(), SCENARIO_INDENT + definitionText);
    out.println(SCENARIO_INDENT + definitionText + locationIndent + formatLocation(path + ":" + testCase.getLocation().getLine()));
}
Also used : TestCase(io.cucumber.plugin.event.TestCase)

Aggregations

TestCase (io.cucumber.plugin.event.TestCase)13 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)5 Location (io.cucumber.plugin.event.Location)3 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 EventBus (io.cucumber.core.eventbus.EventBus)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 EventPublisher (io.cucumber.plugin.event.EventPublisher)2 Node (io.cucumber.plugin.event.Node)2 Result (io.cucumber.plugin.event.Result)2 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)2 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)2 TestSourceParsed (io.cucumber.plugin.event.TestSourceParsed)2 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)2 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 CucumberException (io.cucumber.core.exception.CucumberException)1