Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

010 - Improve bdd scenarios #13

Open
wants to merge 4 commits into
base: feat-continuous-testing-docker
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<maven.compiler.target>17</maven.compiler.target>
<hamcrest.version>2.2</hamcrest.version>
<junit.version>5.8.2</junit.version>
<cucumber.version>7.0.0</cucumber.version>
<cucumber.version>7.6.0</cucumber.version>
<maven.antrun.version>3.0.0</maven.antrun.version>
<junit.platform.version>1.8.2</junit.platform.version>
<junit.platform.version>1.9.0</junit.platform.version>
<apache.httpcomponents.version>4.5.13</apache.httpcomponents.version>
<jetty.maven.plugin.version>11.0.7</jetty.maven.plugin.version>
<jersey.version>3.0.3</jersey.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)));
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.geekshubs.calculator.configuration;

public class Values {
public static final String ENCODING = System.getProperty("project.build.sourceEncoding", "UTF-8");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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=<first>&y=<second>
Then I should receive 200 response status code
And should receive result 16
And should receive result <result>

Examples:
| first | second | result |
| -2 | 3 | 1 |
| 10 | 15 | 25 |
| 99 | -99 | 0 |
| -1 | -10 | -11 |
3 changes: 3 additions & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -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
Loading