diff --git a/.github/images/allure-results.png b/.github/images/allure-results.png new file mode 100644 index 0000000..34310bd Binary files /dev/null and b/.github/images/allure-results.png differ diff --git a/README.md b/README.md index 075b871..336361a 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,49 @@ # Testes de API com REST-assured e JUnit 5. -## Pré-requisitos de ambiente 📋 💻 +## Pré-requisitos mínimos de ambiente: -[Java](https://www.oracle.com/br/java/technologies/downloads/#java11) 11.0.20. +* [Java](https://www.oracle.com/br/java/technologies/downloads/#java11) 11.0.x. -## Execução dos testes pelo CMD ✅ ✅ +## IDE de desenvolvimento: + +* [Eclipse](https://eclipseide.org). + +## Clone do repositório: + +``` +git clone https://github.com/thinogueiras/REST-assured.git +``` + +## Abrir o projeto no Eclipse: + +* Abra o Eclipse >> Menu File >> Import >> Maven >> Existing Maven Projects. +* Navegar até o repositório clonado >> Selecionar a pasta >> Finish. + +## Execução dos testes: + +### JUnit: + +* Após importar o projeto com sucesso no Eclipse, clique para expandir o Source Folder: `src/test/java`, clique com o botão `direito` do mouse sobre o package: `br.qa.thinogueiras.suite` >> Run As >> JUnit Test. + +### Terminal: ``` mvn clean test ``` -## Relatório da execução 📝 📄 +## Relatório: +* #### Abrir o terminal e digitar: -``` -allure serve allure-results -``` + ``` + allure serve allure-results + ``` -![Alt text](/images/allure-report.png) +![Alt text](/.github/images/allure-results.png) --- Linkedin -Thiago Nogueira dos Santos 🤓 🫰🏽 +Thiago Nogueira dos Santos 🤓 ✌🏻 QA Automation Engineer 🔎 🐞 diff --git a/images/allure-report.png b/images/allure-report.png deleted file mode 100644 index 062ac84..0000000 Binary files a/images/allure-report.png and /dev/null differ diff --git a/pom.xml b/pom.xml index 9fdf737..6fbd7c3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,4 @@ - + 4.0.0 br.qa.thinogueiras REST-assured @@ -18,7 +16,7 @@ 5.10.0 5.1.1 2.9.1 - 1.8.2 + 1.8.2 2.19.0 2.11.2 3.0.0-M7 @@ -32,11 +30,6 @@ rest-assured ${rest-assured.version} - - io.rest-assured - json-schema-validator - ${json-schema-validator.version} - com.google.code.gson gson @@ -59,7 +52,7 @@ junit-platform-suite-engine ${junit-platform-suite-engine.version} test - + io.qameta.allure allure-junit5 @@ -75,7 +68,7 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - false + false listener @@ -105,21 +98,21 @@ org.aspectj aspectjweaver ${aspectj.version} - + org.junit.jupiter junit-jupiter-engine ${junit.jupiter.engine.version} - + org.apache.maven.plugins maven-compiler-plugin ${maven-compiler-plugin.version} ${java.version} - ${java.version} + ${java.version} diff --git a/src/test/java/br/qa/thinogueiras/core/BaseTest.java b/src/test/java/br/qa/thinogueiras/core/BaseTest.java index e47c999..75a2121 100644 --- a/src/test/java/br/qa/thinogueiras/core/BaseTest.java +++ b/src/test/java/br/qa/thinogueiras/core/BaseTest.java @@ -4,7 +4,6 @@ import static io.restassured.RestAssured.basePath; import static io.restassured.RestAssured.baseURI; import static io.restassured.RestAssured.enableLoggingOfRequestAndResponseIfValidationFails; -import static io.restassured.RestAssured.get; import static io.restassured.RestAssured.port; import static io.restassured.RestAssured.requestSpecification; import static io.restassured.RestAssured.responseSpecification; @@ -15,7 +14,7 @@ import io.restassured.builder.RequestSpecBuilder; import io.restassured.builder.ResponseSpecBuilder; -public class BaseTest implements Constants { +public class BaseTest implements Constants { @BeforeAll public static void setup() { @@ -34,7 +33,5 @@ public static void setup() { enableLoggingOfRequestAndResponseIfValidationFails(); getToken(); - - get("/reset").then().statusCode(200); } } diff --git a/src/test/java/br/qa/thinogueiras/core/TokenFactory.java b/src/test/java/br/qa/thinogueiras/core/TokenFactory.java index 8e275b2..a6aa8f0 100644 --- a/src/test/java/br/qa/thinogueiras/core/TokenFactory.java +++ b/src/test/java/br/qa/thinogueiras/core/TokenFactory.java @@ -1,5 +1,6 @@ package br.qa.thinogueiras.core; +import static br.qa.thinogueiras.utils.Utils.resetUserData; import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.requestSpecification; @@ -11,24 +12,10 @@ public class TokenFactory { - private static String TOKEN; + private static String TOKEN = ""; private static RequestSpecification HEADER; private static FilterableRequestSpecification request; - - public static String getToken() { - if(TOKEN == null || HEADER == null) { - generateToken(); - } - - return TOKEN; - } - public static void removeAuthorization() { - request = (FilterableRequestSpecification) requestSpecification; - request.removeHeader("Authorization"); - HEADER = null; - } - private static void generateToken() { Map login = new HashMap<>(); login.put("email", "thinogueiras@testing.com"); @@ -45,4 +32,20 @@ private static void generateToken() { HEADER = requestSpecification.header("Authorization", "JWT " + TOKEN); } + + public static String getToken() { + if(HEADER == null) { + generateToken(); + + resetUserData();; + } + + return TOKEN; + } + + public static void removeAuthorization() { + request = (FilterableRequestSpecification) requestSpecification; + request.removeHeader("Authorization"); + HEADER = null; + } } diff --git a/src/test/java/br/qa/thinogueiras/tests/AccountTest.java b/src/test/java/br/qa/thinogueiras/tests/AccountTest.java index f39559c..c34bb83 100644 --- a/src/test/java/br/qa/thinogueiras/tests/AccountTest.java +++ b/src/test/java/br/qa/thinogueiras/tests/AccountTest.java @@ -4,6 +4,9 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; +import java.util.HashMap; +import java.util.Map; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,10 +15,15 @@ @DisplayName("Account Tests") public class AccountTest extends BaseTest { + Map payload = new HashMap<>(); + @Test - public void shouldInsertAccount() { + public void shouldInsertAccount() { + + payload.put("nome", "Conta corrente"); + given() - .body("{\"nome\": \"Conta corrente\"}") + .body(payload) .when() .post("/contas") .then() @@ -26,8 +34,10 @@ public void shouldInsertAccount() { public void shouldEditAccount() { Integer ID_ACCOUNT = getAccountIdByName("Conta para alterar"); + payload.put("nome", "Conta salário"); + given() - .body("{\"nome\": \"Conta salário\"}") + .body(payload) .pathParam("id", ID_ACCOUNT) .when() .put("/contas/{id}") @@ -38,8 +48,10 @@ public void shouldEditAccount() { @Test public void shouldNotInsertAccountWithSameName() { + payload.put("nome", "Conta mesmo nome"); + given() - .body("{\"nome\": \"Conta mesmo nome\"}") + .body(payload) .when() .post("/contas") .then() diff --git a/src/test/java/br/qa/thinogueiras/tests/AuthTest.java b/src/test/java/br/qa/thinogueiras/tests/AuthTest.java index 1565297..fdc03cc 100644 --- a/src/test/java/br/qa/thinogueiras/tests/AuthTest.java +++ b/src/test/java/br/qa/thinogueiras/tests/AuthTest.java @@ -3,6 +3,7 @@ import static br.qa.thinogueiras.core.TokenFactory.removeAuthorization; import static io.restassured.RestAssured.given; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,10 +12,13 @@ @DisplayName("Authorization Tests") public class AuthTest extends BaseTest { - @Test - public void shouldNotAccessWithoutToken() { - + @BeforeAll + public static void authorization() { removeAuthorization(); + } + + @Test + public void shouldNotAccessContasWithoutToken() { given() .when() @@ -22,4 +26,34 @@ public void shouldNotAccessWithoutToken() { .then() .statusCode(401); } + + @Test + public void shouldNotAccessSaldoWithoutToken() { + + given() + .when() + .get("/saldo") + .then() + .statusCode(401); + } + + @Test + public void shouldNotAccessTransacoesWithoutToken() { + + given() + .when() + .get("/transacoes") + .then() + .statusCode(401); + } + + @Test + public void shouldNotAccessMovimentacoesWithoutToken() { + + given() + .when() + .get("/movimentacoes") + .then() + .statusCode(401); + } } diff --git a/src/test/java/br/qa/thinogueiras/utils/Utils.java b/src/test/java/br/qa/thinogueiras/utils/Utils.java index cad8db7..73ad324 100644 --- a/src/test/java/br/qa/thinogueiras/utils/Utils.java +++ b/src/test/java/br/qa/thinogueiras/utils/Utils.java @@ -1,6 +1,7 @@ package br.qa.thinogueiras.utils; import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; import br.qa.thinogueiras.core.Movement; @@ -28,4 +29,12 @@ public static Integer getAccountIdByName(String name) { public static Integer getMovementIdByDescription(String description) { return get("/transacoes?descricao="+description).then().extract().path("id[0]"); } + + public static void resetUserData() { + given() + .when() + .get("/reset") + .then() + .statusCode(200); + } }