diff --git a/pom.xml b/pom.xml index 37fa339..e880646 100644 --- a/pom.xml +++ b/pom.xml @@ -30,28 +30,30 @@ rest-assured ${rest-assured.version} - - com.google.code.gson - gson - ${com.google.code.gson.version} - org.junit.jupiter junit-jupiter-api ${junit.jupiter.api.version} - test org.junit.jupiter junit-jupiter-engine ${junit.jupiter.engine.version} - test org.junit.platform junit-platform-suite-engine ${junit-platform-suite-engine.version} - test + + + com.google.code.gson + gson + ${com.google.code.gson.version} + + + io.rest-assured + json-schema-validator + 5.4.0 io.qameta.allure diff --git a/src/test/java/br/qa/thinogueiras/tests/SchemaTest.java b/src/test/java/br/qa/thinogueiras/tests/SchemaTest.java new file mode 100644 index 0000000..5192b4f --- /dev/null +++ b/src/test/java/br/qa/thinogueiras/tests/SchemaTest.java @@ -0,0 +1,43 @@ +package br.qa.thinogueiras.tests; + +import static io.restassured.RestAssured.given; +import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import br.qa.thinogueiras.core.BaseTest; + +@DisplayName("JSON Schema Tests") +public class SchemaTest extends BaseTest { + + @Test + public void shouldValidateAccountJSONSchema() { + given() + .when() + .get("/contas") + .then() + .statusCode(200) + .body(matchesJsonSchemaInClasspath("schemas/account.json")); + } + + @Test + public void shouldValidateBalanceJSONSchema() { + given() + .when() + .get("/saldo") + .then() + .statusCode(200) + .body(matchesJsonSchemaInClasspath("schemas/balance.json")); + } + + @Test + public void shouldValidateMovementJSONSchema() { + given() + .when() + .get("/transacoes") + .then() + .statusCode(200) + .body(matchesJsonSchemaInClasspath("schemas/movement.json")); + } +} diff --git a/src/test/resources/schemas/account.json b/src/test/resources/schemas/account.json new file mode 100644 index 0000000..a7b4851 --- /dev/null +++ b/src/test/resources/schemas/account.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/example.json", + "type": "array", + "default": [], + "title": "Root Schema", + "items": { + "type": "object", + "title": "A Schema", + "required": [ + "id", + "nome", + "visivel", + "usuario_id" + ], + "properties": { + "id": { + "type": "integer", + "title": "The id Schema", + "examples": [ + 2054551, + 2054552 + ] + }, + "nome": { + "type": "string", + "title": "The nome Schema", + "examples": [ + "Conta mesmo nome", + "Conta para movimentacoes", + "Conta com movimentacao", + "Conta para saldo", + "Conta para extrato", + "Conta Alterada com Sucesso", + "Conta de investimentos" + ] + }, + "visivel": { + "type": "boolean", + "title": "The visivel Schema", + "examples": [ + true + ] + }, + "usuario_id": { + "type": "integer", + "title": "The usuario_id Schema", + "examples": [ + 34767 + ] + } + } + }, + "examples": [ + [ + { + "id": 2054551, + "nome": "Conta mesmo nome", + "visivel": true, + "usuario_id": 34767 + }, + { + "id": 2054552, + "nome": "Conta para movimentacoes", + "visivel": true, + "usuario_id": 34767 + } + ] + ] +} \ No newline at end of file diff --git a/src/test/resources/schemas/balance.json b/src/test/resources/schemas/balance.json new file mode 100644 index 0000000..9163906 --- /dev/null +++ b/src/test/resources/schemas/balance.json @@ -0,0 +1,59 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/example.json", + "type": "array", + "default": [], + "title": "Root Schema", + "items": { + "type": "object", + "title": "A Schema", + "required": [ + "conta_id", + "conta", + "saldo" + ], + "properties": { + "conta_id": { + "type": "integer", + "title": "The conta_id Schema", + "examples": [ + 2054722, + 2054723 + ] + }, + "conta": { + "type": "string", + "title": "The conta Schema", + "examples": [ + "Conta para movimentacoes", + "Conta com movimentacao", + "Conta para saldo", + "Conta para extrato" + ] + }, + "saldo": { + "type": "string", + "title": "The saldo Schema", + "examples": [ + "-1500.00", + "534.00", + "-220.00" + ] + } + } + }, + "examples": [ + [ + { + "conta_id": 2054722, + "conta": "Conta para movimentacoes", + "saldo": "-1500.00" + }, + { + "conta_id": 2054724, + "conta": "Conta para saldo", + "saldo": "534.00" + } + ] + ] +} \ No newline at end of file diff --git a/src/test/resources/schemas/movement.json b/src/test/resources/schemas/movement.json new file mode 100644 index 0000000..3e1e370 --- /dev/null +++ b/src/test/resources/schemas/movement.json @@ -0,0 +1,180 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/example.json", + "type": "array", + "default": [], + "title": "Root Schema", + "items": { + "type": "object", + "title": "A Schema", + "required": [ + "id", + "descricao", + "envolvido", + "observacao", + "tipo", + "data_transacao", + "data_pagamento", + "valor", + "status", + "conta_id", + "usuario_id", + "transferencia_id", + "parcelamento_id" + ], + "properties": { + "id": { + "type": "integer", + "title": "The id Schema", + "examples": [ + 1926111, + 1926112, + 1926113, + 1926114, + 1926115, + 1926116 + ] + }, + "descricao": { + "type": "string", + "title": "The descricao Schema", + "examples": [ + "Movimentacao para exclusao", + "Movimentacao de conta", + "Movimentacao 1, calculo saldo", + "Movimentacao 2, calculo saldo", + "Movimentacao 3, calculo saldo", + "Movimentacao para extrato" + ] + }, + "envolvido": { + "type": "string", + "title": "The envolvido Schema", + "examples": [ + "AAA", + "BBB", + "CCC", + "DDD", + "EEE", + "FFF" + ] + }, + "observacao": { + "type": "null", + "title": "The observacao Schema", + "examples": [ + null + ] + }, + "tipo": { + "type": "string", + "title": "The tipo Schema", + "examples": [ + "DESP", + "REC" + ] + }, + "data_transacao": { + "type": "string", + "title": "The data_transacao Schema", + "examples": [ + "2024-03-04T03:00:00.000Z" + ] + }, + "data_pagamento": { + "type": "string", + "title": "The data_pagamento Schema", + "examples": [ + "2024-03-04T03:00:00.000Z" + ] + }, + "valor": { + "type": [ + "integer", + "string" + ], + "title": "The valor Schema", + "examples": [ + 1500, + "3500.00", + 1000, + "1534.00", + 220 + ] + }, + "status": { + "type": "boolean", + "title": "The status Schema", + "examples": [ + true, + false + ] + }, + "conta_id": { + "type": "integer", + "title": "The conta_id Schema", + "examples": [ + 2054740, + 2054741, + 2054742, + 2054743 + ] + }, + "usuario_id": { + "type": "integer", + "title": "The usuario_id Schema", + "examples": [ + 34767 + ] + }, + "transferencia_id": { + "type": "null", + "title": "The transferencia_id Schema", + "examples": [ + null + ] + }, + "parcelamento_id": { + "type": "null", + "title": "The parcelamento_id Schema", + "examples": [ + null + ] + } + } + }, + "examples": [ + [ + { + "id": 1926111, + "descricao": "Movimentacao para exclusao", + "envolvido": "AAA", + "observacao": null, + "tipo": "DESP", + "data_transacao": "2024-03-04T03:00:00.000Z", + "data_pagamento": "2024-03-04T03:00:00.000Z", + "valor": 1500, + "status": true, + "conta_id": 2054740, + "usuario_id": 34767, + "transferencia_id": null, + "parcelamento_id": null + }, + { + "id": 1926112, + "descricao": "Movimentacao de conta", + "envolvido": "BBB", + "observacao": null, + "tipo": "DESP", + "data_transacao": "2024-03-04T03:00:00.000Z", + "data_pagamento": "2024-03-04T03:00:00.000Z", + "valor": 1500, + "status": true, + "conta_id": 2054741, + "usuario_id": 34767, + "transferencia_id": null, + "parcelamento_id": null + } + ] + ] +} \ No newline at end of file