Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
73795a3
feat: Add integration components tests
ricardogarfe Jan 19, 2022
4767a00
feat: Run actions on all pull requests
ricardogarfe Jan 19, 2022
5af203e
feat: Extract service instance
ricardogarfe Jan 19, 2022
23d7dc8
feat: Add JaCoCo and sonarcloud.io configuration
ricardogarfe Jan 19, 2022
ef4cec1
feat: Publish API methods
ricardogarfe Jan 19, 2022
d48c83d
fix: fix html bugs
ricardogarfe Jan 19, 2022
a61a67c
fix: fix test workflow
ricardogarfe Jan 19, 2022
b0f8c02
fix: workflow from all branches
ricardogarfe Jan 19, 2022
a90d4ef
fix: Revert workflow workaround
ricardogarfe Jan 19, 2022
6a63cf6
feat: Divide tests execution
ricardogarfe Jan 19, 2022
2e14200
feat: Add cucumber tests first draft
ricardogarfe Jan 19, 2022
389ad4c
feat: Refactor cucumber runner test Class
ricardogarfe Jan 19, 2022
4e19288
feat: enable service and bdd test
ricardogarfe Dec 16, 2022
4a58388
feat: update ci workflow to build branches with main
ricardogarfe Jan 25, 2024
c929dd7
feat: update ci workflow to build branches with main
ricardogarfe Jan 25, 2024
6916006
feat: upgrade jdk to 17
ricardogarfe Jan 25, 2024
6ef8548
feat: Publish API methods
ricardogarfe Jan 19, 2022
1e29f83
fix: fix html bugs
ricardogarfe Jan 19, 2022
e86623a
fix: fix test workflow
ricardogarfe Jan 19, 2022
5d733c8
fix: workflow from all branches
ricardogarfe Jan 19, 2022
dadd916
fix: Revert workflow workaround
ricardogarfe Jan 19, 2022
7050632
feat: Divide tests execution
ricardogarfe Jan 19, 2022
8037ed0
feat: set maven-war-plugin version
ricardogarfe Jan 25, 2024
4aecbdb
Merge branch 'feat-integration-e2e-api' into feat-bdd-api
ricardogarfe Jan 25, 2024
ed43938
chore: enable run workflow manually
ricardogarfe Jun 19, 2024
f917098
Merge branch 'feat-integration-e2e-api' into feat-bdd-api
ricardogarfe Jun 19, 2024
518a441
feat: enable gitpod
ricardogarfe Jan 20, 2022
e28041a
Merge branch 'feat-integration-e2e-api' into feat-bdd-api
ricardogarfe Jun 21, 2024
1ff8adb
test: fix expected results
ricardogarfe Jun 21, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
workflow_dispatch:
workflow_run:
workflows: 'CI' # runs after CI workflow

types:
- completed
jobs:
report:
runs-on: ubuntu-latest
Expand Down
73 changes: 73 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +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>
<maven.antrun.version>3.0.0</maven.antrun.version>
<junit.platform.version>1.8.2</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 Expand Up @@ -86,6 +89,67 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -157,7 +221,16 @@
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT*.java</exclude>
<exclude>**/ITCucumberRunner.java</exclude>
</excludes>
<properties>
<!-- Work around. Surefire does not include enough
information to disambiguate between different
examples and scenarios. -->
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ 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
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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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