Search in sources :

Example 61 with StubFeatureSupplier

use of io.cucumber.core.runtime.StubFeatureSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_a_step_with_a_data_table.

@Test
void should_format_scenario_with_a_step_with_a_data_table() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n" + "      | aa | 11 |\n" + "      | bb | 22 |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()", DataTable.class))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"rows\": [\n" + "              {\n" + "                \"cells\": [\n" + "                  \"aa\",\n" + "                  \"11\"\n" + "                ]\n" + "              },\n" + "              {\n" + "                \"cells\": [\n" + "                  \"bb\",\n" + "                  \"22\"\n" + "                ]\n" + "              }\n" + "            ],\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 62 with StubFeatureSupplier

use of io.cucumber.core.runtime.StubFeatureSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_handle_embed_with_name_from_a_hook.

@Test
void should_handle_embed_with_name_from_a_hook() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition("Hooks.before_hook_1()", testCaseState -> testCaseState.attach(new byte[] { 1, 2, 3 }, "mime-type;base64", "someEmbedding"))), singletonList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()")), emptyList())).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"before\": [\n" + "          {\n" + "            \"match\": {\n" + "              \"location\": \"Hooks.before_hook_1()\"\n" + "            },\n" + "            \"embeddings\": [\n" + "              {\n" + "                \"mime_type\": \"mime-type;base64\",\n" + "                \"data\": \"AQID\",\n" + "                \"name\": \"someEmbedding\"\n" + "              }\n" + "            ],\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ],\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Builder(io.cucumber.core.runtime.Runtime.Builder) ZoneId.of(java.time.ZoneId.of) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Scanner(java.util.Scanner) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) Clock.fixed(java.time.Clock.fixed) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Collections.emptyList(java.util.Collections.emptyList) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) EPOCH(java.time.Instant.EPOCH) Duration.ofMillis(java.time.Duration.ofMillis) InputStream(java.io.InputStream) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 63 with StubFeatureSupplier

use of io.cucumber.core.runtime.StubFeatureSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_handle_several_features.

@Test
void should_handle_several_features() {
    Feature feature1 = TestFeatureParser.parse("path/test1.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n");
    Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: Orange party\n" + "\n" + "  Scenario: Monkey eats oranges\n" + "    Given there are oranges\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"), new StubStepDefinition("there are oranges", "StepDefs.there_are_oranges()"))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test1.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  },\n" + "  {\n" + "    \"id\": \"orange-party\",\n" + "    \"uri\": \"file:path/test2.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Orange party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"orange-party;monkey-eats-oranges\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.001Z\",\n" + "        \"name\": \"Monkey eats oranges\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are oranges\",\n" + "            \"line\": 4,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_oranges()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 64 with StubFeatureSupplier

use of io.cucumber.core.runtime.StubFeatureSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_a_rule_and_background.

@Test
void should_format_scenario_with_a_rule_and_background() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Background: \n" + "     Given there are bananas\n" + "\n" + "  Rule: This is all monkey business\n" + "\n" + "  Background: \n" + "     Given there are bananas\n" + "\n" + "    Scenario: Monkey eats bananas\n" + "      Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"line\": 1,\n" + "    \"elements\": [\n" + "      {\n" + "        \"line\": 3,\n" + "        \"name\": \"\",\n" + "        \"description\": \"\",\n" + "        \"type\": \"background\",\n" + "        \"keyword\": \"Background\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"line\": 4,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Given \"\n" + "          },\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"line\": 9,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Given \"\n" + "          }\n" + "        ]\n" + "      },\n" + "      {\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"line\": 11,\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"description\": \"\",\n" + "        \"id\": \";monkey-eats-bananas\",\n" + "        \"type\": \"scenario\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"line\": 12,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Given \"\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"name\": \"Banana party\",\n" + "    \"description\": \"\",\n" + "    \"id\": \"banana-party\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 65 with StubFeatureSupplier

use of io.cucumber.core.runtime.StubFeatureSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_an_undefined_step.

@Test
void should_format_scenario_with_an_undefined_step() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier()).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"match\": {},\n" + "            \"result\": {\n" + "              \"status\": \"undefined\"\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)78 Feature (io.cucumber.core.gherkin.Feature)77 ByteArrayOutputStream (java.io.ByteArrayOutputStream)77 Test (org.junit.jupiter.api.Test)77 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)70 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)55 UUID (java.util.UUID)53 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)25 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)18 DocString (io.cucumber.docstring.DocString)17 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)16 PrintStream (java.io.PrintStream)11 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)6 Runtime (io.cucumber.core.runtime.Runtime)6 DataTable (io.cucumber.datatable.DataTable)6 Arrays.asList (java.util.Arrays.asList)6 Collections.emptyList (java.util.Collections.emptyList)6 Collections.singletonList (java.util.Collections.singletonList)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6