diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml
index 1edc962..cd77302 100644
--- a/.github/workflows/test-report.yml
+++ b/.github/workflows/test-report.yml
@@ -4,7 +4,8 @@ on:
workflow_dispatch:
workflow_run:
workflows: 'CI' # runs after CI workflow
-
+ types:
+ - completed
jobs:
report:
runs-on: ubuntu-latest
diff --git a/pom.xml b/pom.xml
index 392ff37..d0e740d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,9 @@
17
2.2
5.8.2
+ 7.0.0
+ 3.0.0
+ 1.8.2
4.5.13
11.0.7
3.0.3
@@ -86,6 +89,67 @@
${junit.version}
test
+
+ io.cucumber
+ cucumber-java
+ ${cucumber.version}
+ test
+
+
+ io.cucumber
+ cucumber-junit-platform-engine
+ ${cucumber.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-console
+ ${junit.platform.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+
+ org.junit.platform
+ junit-platform-launcher
+ ${junit.platform.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-suite
+ ${junit.platform.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-suite-engine
+ ${junit.platform.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-suite-api
+ ${junit.platform.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.version}
+ test
+
org.apache.httpcomponents
httpclient
@@ -157,7 +221,16 @@
**/IT*.java
+ **/ITCucumberRunner.java
+
+
+
+ cucumber.junit-platform.naming-strategy=long
+
+
diff --git a/src/test/java/com/geekshubs/calculator/aceptance/api/ITCucumberRunner.java b/src/test/java/com/geekshubs/calculator/aceptance/api/ITCucumberRunner.java
new file mode 100644
index 0000000..3e9abc7
--- /dev/null
+++ b/src/test/java/com/geekshubs/calculator/aceptance/api/ITCucumberRunner.java
@@ -0,0 +1,17 @@
+package com.geekshubs.calculator.aceptance.api;
+
+import org.junit.platform.suite.api.ConfigurationParameter;
+import org.junit.platform.suite.api.IncludeEngines;
+import org.junit.platform.suite.api.SelectClasspathResource;
+import org.junit.platform.suite.api.Suite;
+
+import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
+import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
+
+@Suite
+@IncludeEngines("cucumber")
+@SelectClasspathResource("com/geekshubs/calculator/acceptance/api/ping.feature")
+@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
+@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.geekshubs.calculator.aceptance.api")
+public class ITCucumberRunner {
+}
diff --git a/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java b/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java
new file mode 100644
index 0000000..07451c2
--- /dev/null
+++ b/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java
@@ -0,0 +1,41 @@
+package com.geekshubs.calculator.aceptance.api;
+
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class PingSteps {
+
+ HttpResponse response;
+
+ @When("^I make a GET call on ([^\"]*)$")
+ public void iMakeAGETCallOn(String path) throws Exception {
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpGet httpGet = new HttpGet(String.format("http://localhost:8080%s",path));
+ response = httpclient.execute(httpGet);
+ }
+
+ @Then("^I should receive (\\d+) response status code$")
+ public void iShouldReceiveStatusCodeResponse(int code) {
+ assertEquals(code, response.getStatusLine().getStatusCode());
+ }
+
+ @Then("^should receive a welcome message$")
+ public void shouldReceiveAWelcomeMessage() throws Exception {
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("Welcome to Java Maven Calculator Web App!!!"));
+ }
+
+ @Then("^should receive result (\\d+)$")
+ public void shouldReceiveResultCorrect(int result) throws Exception {
+ assertThat(EntityUtils.toString(response.getEntity()), containsString(String.format("\"result\":%d", result)));
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java b/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java
index a8e32fc..7d7754f 100644
--- a/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java
+++ b/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java
@@ -29,7 +29,7 @@ public void testAdd() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/add?x=2&y=3");
HttpResponse response = httpclient.execute(httpGet);
assertEquals(200, response.getStatusLine().getStatusCode());
- assertThat(EntityUtils.toString(response.getEntity()), containsString("5"));
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":5"));
}
@Test
@@ -37,7 +37,7 @@ public void testSub() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/sub?x=2&y=3");
HttpResponse response = httpclient.execute(httpGet);
assertEquals(200, response.getStatusLine().getStatusCode());
- assertThat(EntityUtils.toString(response.getEntity()), containsString("-1"));
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":-1"));
}
@Test
@@ -45,15 +45,16 @@ public void testMul() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/mul?x=2&y=3");
HttpResponse response = httpclient.execute(httpGet);
assertEquals(200, response.getStatusLine().getStatusCode());
- assertThat(EntityUtils.toString(response.getEntity()), containsString("6"));
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":6"));
}
@Test
public void testDiv() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/div?x=6&y=3");
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/div?x=12&y=12");
HttpResponse response = httpclient.execute(httpGet);
assertEquals(200, response.getStatusLine().getStatusCode());
- assertThat(EntityUtils.toString(response.getEntity()), containsString("2"));
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":1"));
}
@Test
diff --git a/src/test/java/com/geekshubs/calculator/rest/CalculatorAPITest.java b/src/test/java/com/geekshubs/calculator/rest/CalculatorAPITest.java
index a7d2e34..a7d3119 100644
--- a/src/test/java/com/geekshubs/calculator/rest/CalculatorAPITest.java
+++ b/src/test/java/com/geekshubs/calculator/rest/CalculatorAPITest.java
@@ -12,7 +12,7 @@ public class CalculatorAPITest {
@Test
public void testPing() {
- assertThat(new CalculatorAPI().ping(), containsString("Welcome to Java Maven Calculator Web App!!!"));
+ assertThat(calculatorAPI.ping(), containsString("Welcome to Java Maven Calculator Web App!!!"));
}
@Test
diff --git a/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature b/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature
new file mode 100644
index 0000000..456cb66
--- /dev/null
+++ b/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature
@@ -0,0 +1,12 @@
+@API
+Feature: Ping check
+
+ Scenario: Should have a working ping check
+ When I make a GET call on /calculator/api/calculator/ping
+ Then I should receive 200 response status code
+ And should receive a welcome message
+
+ Scenario: Should receive a sum result
+ When I make a GET call on /calculator/api/calculator/add?x=8&y=8
+ Then I should receive 200 response status code
+ And should receive result 16