From 2e3c92635eebf77503ddbc44bcd65d7f47f3530e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 20 Jun 2024 00:03:21 +0200 Subject: [PATCH 1/4] chore: update testing dependencies --- README.md | 4 ++-- pom.xml | 4 ++-- src/test/resources/junit-platform.properties | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/junit-platform.properties diff --git a/README.md b/README.md index c343456..2c161bf 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ $ docker run --rm -p 8080:8080 myjetty > Explain: --rm means delete the container after stopping it. -Access the web app at http://localhost:8080/api/calculator/ping in browser. +Access the web app at http://localhost:8080/calculator/api/calculator/ping in browser. Press Control-C to stop and remove the container. @@ -141,4 +141,4 @@ Run all tests in docker-compose environment: $ docker-compose up ``` -Access the web app at http://localhost:8080/api/calculator/ping in browser. +Access the web app at http://localhost:8080/calculator/api/calculator/ping in browser. diff --git a/pom.xml b/pom.xml index 5ad7dcc..8bb72c9 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ 17 2.2 5.8.2 - 7.0.0 + 7.6.0 3.0.0 - 1.8.2 + 1.9.0 4.5.13 11.0.7 3.0.3 diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties new file mode 100644 index 0000000..f9ba3c9 --- /dev/null +++ b/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +cucumber.publish.quiet=false +cucumber.publish.enabled=true +cucumber.plugin=pretty, html:target/cucumber-reports/Cucumber.html, json:target/cucumber-reports/Cucumber.json, junit:target/cucumber-reports/Cucumber.xml From 8bdb6071b0bf81b5561ff38fc99d6bb234993511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 20 Jun 2024 00:03:44 +0200 Subject: [PATCH 2/4] feat: update bdd scenarios --- .../calculator/aceptance/api/PingSteps.java | 10 ++++++---- .../geekshubs/calculator/configuration/Values.java | 5 +++++ .../calculator/integration/ITCalculatorAPITest.java | 12 +++++++----- .../calculator/acceptance/api/ping.feature | 13 ++++++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/geekshubs/calculator/configuration/Values.java diff --git a/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java b/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java index a32cfc3..fcdf8a8 100644 --- a/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java +++ b/src/test/java/com/geekshubs/calculator/aceptance/api/PingSteps.java @@ -8,6 +8,8 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +import com.geekshubs.calculator.configuration.Values; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -32,12 +34,12 @@ public void iShouldReceiveStatusCodeResponse(int code) { @Then("^should receive a welcome message$") public void shouldReceiveAWelcomeMessage() throws Exception { - assertThat(EntityUtils.toString(response.getEntity()), containsString("Welcome to Java Maven Calculator Web App!!!")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("Welcome to Java Maven Calculator Web App!!!")); } - @Then("^should receive result (\\d+)$") + @Then("^should receive result (-?\\d+)$") public void shouldReceiveResultCorrect(int result) throws Exception { - assertThat(EntityUtils.toString(response.getEntity()), containsString(String.format("\"result\":%d", result))); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString(String.format("\"result\":%d", result))); } -} \ No newline at end of file +} diff --git a/src/test/java/com/geekshubs/calculator/configuration/Values.java b/src/test/java/com/geekshubs/calculator/configuration/Values.java new file mode 100644 index 0000000..7828d97 --- /dev/null +++ b/src/test/java/com/geekshubs/calculator/configuration/Values.java @@ -0,0 +1,5 @@ +package com.geekshubs.calculator.configuration; + +public class Values { + public static final String ENCODING = System.getProperty("project.build.sourceEncoding", "UTF-8"); +} \ 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 171c602..e4256c9 100644 --- a/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java +++ b/src/test/java/com/geekshubs/calculator/integration/ITCalculatorAPITest.java @@ -7,6 +7,8 @@ import org.apache.http.util.EntityUtils; import org.junit.jupiter.api.Test; +import com.geekshubs.calculator.configuration.Values; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -19,7 +21,7 @@ public void testPing() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/ping"); HttpResponse response = httpclient.execute(httpGet); assertEquals(200, response.getStatusLine().getStatusCode()); - assertThat(EntityUtils.toString(response.getEntity()), containsString("Welcome to Java Maven Calculator Web App!!!")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("Welcome to Java Maven Calculator Web App!!!")); } @Test @@ -28,7 +30,7 @@ public void testAdd() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/add?x=8&y=26"); HttpResponse response = httpclient.execute(httpGet); assertEquals(200, response.getStatusLine().getStatusCode()); - assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":34")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("\"result\":34")); } @Test @@ -37,7 +39,7 @@ public void testSub() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/sub?x=12&y=8"); HttpResponse response = httpclient.execute(httpGet); assertEquals(200, response.getStatusLine().getStatusCode()); - assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":4")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("\"result\":4")); } @Test @@ -46,7 +48,7 @@ public void testMul() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:8080/calculator/api/calculator/mul?x=11&y=8"); HttpResponse response = httpclient.execute(httpGet); assertEquals(200, response.getStatusLine().getStatusCode()); - assertThat(EntityUtils.toString(response.getEntity()), containsString("\"result\":88")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("\"result\":88")); } @Test @@ -55,6 +57,6 @@ public void testDiv() throws Exception { 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("\"result\":1")); + assertThat(EntityUtils.toString(response.getEntity(), Values.ENCODING), containsString("\"result\":1")); } } diff --git a/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature b/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature index 456cb66..d3a9898 100644 --- a/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature +++ b/src/test/resources/com/geekshubs/calculator/acceptance/api/ping.feature @@ -6,7 +6,14 @@ Feature: Ping check 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 + Scenario Outline: Should receive a sum result for + When I make a GET call on /calculator/api/calculator/add?x=&y= Then I should receive 200 response status code - And should receive result 16 + And should receive result + + Examples: + | first | second | result | + | -2 | 3 | 1 | + | 10 | 15 | 25 | + | 99 | -99 | 0 | + | -1 | -10 | -11 | From 542bb22b383ffe01e5810da4517afbea56eaa447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 20 Jun 2024 00:08:19 +0200 Subject: [PATCH 3/4] chore: fix pom format --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8bb72c9..bee17d9 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ 17 2.2 5.8.2 - 7.6.0 + 7.6.0 3.0.0 - 1.9.0 + 1.9.0 4.5.13 11.0.7 3.0.3 From d29dd6b2b66faf211ca769b7c18faea6cb80eb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 20 Jan 2022 23:28:46 +0000 Subject: [PATCH 4/4] feat: enable gitpod --- .gitpod.Dockerfile | 7 +++++++ .gitpod.yml | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .gitpod.Dockerfile create mode 100644 .gitpod.yml diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 0000000..eb553cb --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,7 @@ +FROM gitpod/workspace-full + +USER gitpod + +RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \ + sdk install java 17.0.9-tem && \ + sdk default java 17.0.9-tem" diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..0c92254 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,24 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +image: + file: .gitpod.Dockerfile + +tasks: + - init: mvn package -DskipTests=false + +vscode: + extensions: + - redhat.java + - vscjava.vscode-java-debug + - vscjava.vscode-maven + +# Ports to expose on workspace startup +ports: + - port: 8080 + onOpen: open-preview + name: Calculator API + description: Calculator API init + visibility: private + protocol: http