Skip to content

Commit

Permalink
Suíte de testes para validação de JSON Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
thinogueiras committed Mar 5, 2024
1 parent d4eb659 commit 04d97a5
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${com.google.code.gson.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>${junit-platform-suite-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${com.google.code.gson.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/br/qa/thinogueiras/tests/SchemaTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
70 changes: 70 additions & 0 deletions src/test/resources/schemas/account.json
Original file line number Diff line number Diff line change
@@ -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
}
]
]
}
59 changes: 59 additions & 0 deletions src/test/resources/schemas/balance.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
]
}
180 changes: 180 additions & 0 deletions src/test/resources/schemas/movement.json
Original file line number Diff line number Diff line change
@@ -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
}
]
]
}

0 comments on commit 04d97a5

Please sign in to comment.