Skip to content

010 - Improve bdd scenarios #13

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

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 1 commit
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
Prev Previous commit
Next Next commit
feat: update bdd scenarios
  • Loading branch information
ricardogarfe committed Jun 19, 2024
commit 8bdb6071b0bf81b5561ff38fc99d6bb234993511
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 |