From 3974e4ca22ee35dac0963a15a169edd62d5fd288 Mon Sep 17 00:00:00 2001 From: Tahar BOUNSIAR Date: Mon, 18 Mar 2024 14:40:45 +0100 Subject: [PATCH 1/2] add support of beforeall and afterall hooks --- .../main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/src/main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java b/runtime/src/main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java index 891bdee..e0ed865 100644 --- a/runtime/src/main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java +++ b/runtime/src/main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java @@ -108,6 +108,7 @@ List getTests() { List features = new LinkedList<>(); features.add(DynamicTest.dynamicTest("Start Cucumber", context::startTestRun)); + features.add(DynamicTest.dynamicTest("Before All Features", context::runBeforeAllHooks)); Predicate filters = new Filters(runtimeOptions); @@ -155,6 +156,7 @@ List getTests() { } }); + features.add(DynamicTest.dynamicTest("After All Features", context::runAfterAllHooks)); features.add(DynamicTest.dynamicTest("Finish Cucumber", context::finishTestRun)); return features; From 6c319469ea0e2bee3e25708a500477e7c8484072 Mon Sep 17 00:00:00 2001 From: Tahar BOUNSIAR Date: Tue, 19 Mar 2024 18:11:26 +0100 Subject: [PATCH 2/2] add test using configurable fake Factory --- .../quarkiverse/cucumber/test/Endpoint.java | 2 +- .../io/quarkiverse/cucumber/test/Factory.java | 14 +++++++++++ .../io/quarkiverse/cucumber/test/Steps.java | 24 +++++++++++++++++++ deployment/src/test/resources/simple.feature | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 deployment/src/test/java/io/quarkiverse/cucumber/test/Factory.java diff --git a/deployment/src/test/java/io/quarkiverse/cucumber/test/Endpoint.java b/deployment/src/test/java/io/quarkiverse/cucumber/test/Endpoint.java index 38b7fbe..35c84e1 100644 --- a/deployment/src/test/java/io/quarkiverse/cucumber/test/Endpoint.java +++ b/deployment/src/test/java/io/quarkiverse/cucumber/test/Endpoint.java @@ -8,6 +8,6 @@ public class Endpoint { @GET public String hello() { - return "hello"; + return Factory.hello(); } } diff --git a/deployment/src/test/java/io/quarkiverse/cucumber/test/Factory.java b/deployment/src/test/java/io/quarkiverse/cucumber/test/Factory.java new file mode 100644 index 0000000..02d698a --- /dev/null +++ b/deployment/src/test/java/io/quarkiverse/cucumber/test/Factory.java @@ -0,0 +1,14 @@ +package io.quarkiverse.cucumber.test; + +public class Factory { + + private static boolean justeHello = false; + + public static void setJusteHello(boolean justeHello) { + Factory.justeHello = justeHello; + } + + public static String hello() { + return justeHello ? "hello" : "hello from factory"; + } +} diff --git a/deployment/src/test/java/io/quarkiverse/cucumber/test/Steps.java b/deployment/src/test/java/io/quarkiverse/cucumber/test/Steps.java index 06c114a..205dea2 100644 --- a/deployment/src/test/java/io/quarkiverse/cucumber/test/Steps.java +++ b/deployment/src/test/java/io/quarkiverse/cucumber/test/Steps.java @@ -1,11 +1,15 @@ package io.quarkiverse.cucumber.test; import static io.restassured.RestAssured.given; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertFalse; import jakarta.inject.Inject; import org.eclipse.microprofile.config.inject.ConfigProperty; +import io.cucumber.java.AfterAll; +import io.cucumber.java.BeforeAll; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.restassured.response.ValidatableResponse; @@ -18,6 +22,21 @@ public class Steps { private ValidatableResponse result; + @BeforeAll + public static void beforeAll() { + Factory.setJusteHello(true); + } + + @AfterAll + public static void afterAll() { + Factory.setJusteHello(false); + String response = given() + .when().get("/") + .then() + .extract().body().asString(); + assertFalse("hello".equals(response)); + } + @Given("I call the endpoint") public void i_call_endpoint() throws Exception { result = given() @@ -30,4 +49,9 @@ public void response_is_ok() throws Exception { result.statusCode(200); } + @Then("the response body is hello") + public void response_body_is_hello() throws Exception { + result.body(is("hello")); + } + } diff --git a/deployment/src/test/resources/simple.feature b/deployment/src/test/resources/simple.feature index 756eeba..31792bd 100644 --- a/deployment/src/test/resources/simple.feature +++ b/deployment/src/test/resources/simple.feature @@ -2,4 +2,5 @@ Feature: Test feature Scenario: Test scenario Given I call the endpoint - Then the response is ok \ No newline at end of file + Then the response is ok + And the response body is hello \ No newline at end of file