Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
levvolkov committed Mar 15, 2024
1 parent 5eb238e commit 949a3e9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 46 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ group 'ru.netology'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

repositories {
mavenCentral()
}

dependencies {
testImplementation 'io.rest-assured:rest-assured:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.1'
testImplementation 'io.rest-assured:json-schema-validator:4.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
}

test {
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/ru/netology/rest/MobileBankApiTestV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;


class MobileBankApiTestV1 {
@Test
Expand All @@ -16,9 +14,8 @@ void shouldReturnDemoAccounts() {
// Выполняемые действия
.when()
.get("/demo/accounts")
// код теста
// Проверки
.then()
.statusCode(200)
.body(matchesJsonSchemaInClasspath("accounts.schema.json"));
.statusCode(200);
}
}
}
1 change: 1 addition & 0 deletions src/test/java/ru/netology/rest/MobileBankApiTestV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;


class MobileBankApiTestV4 {
@Test
void shouldReturnDemoAccounts() {
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/ru/netology/rest/MobileBankApiTestV6.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

class MobileBankApiTestV6 {
private RequestSpecification requestSpec = new RequestSpecBuilder()
.setBaseUri("http://localhost")
.setBasePath("/api/v1")
.setPort(9999)
.setAccept(ContentType.JSON)
.setContentType(ContentType.JSON)
.log(LogDetail.ALL)
.build();
.setBaseUri("http://localhost")
.setBasePath("/api/v1")
.setPort(9999)
.setAccept(ContentType.JSON)
.setContentType(ContentType.JSON)
.log(LogDetail.ALL)
.build();

@Test
void shouldReturnDemoAccounts() {
// Given - When - Then
// Предусловия
given()
.spec(requestSpec) // со спецификацией проще (особенно когда много тестов)
// Выполняемые действия
.when()
.get("/demo/accounts")
// Проверки
.then()
.statusCode(200);
// Given - When - Then
// Предусловия
given()
.spec(requestSpec) // со спецификацией проще (особенно когда много тестов)
// Выполняемые действия
.when()
.get("/demo/accounts")
// Проверки
.then()
.statusCode(200);
}
}
}
20 changes: 1 addition & 19 deletions src/test/resources/accounts.schema.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
// версия схемы: https://json-schema.org/understanding-json-schema/reference/schema.html
"type": "array",
// тип корневого элемента: https://json-schema.org/understanding-json-schema/reference/type.html
"items": {
// какие элементы допустимы внутри массива: https://json-schema.org/understanding-json-schema/reference/array.html#items
"type": "object",
// должны быть объектами: https://json-schema.org/understanding-json-schema/reference/object.html
"required": [
// должны содержать следующие поля: https://json-schema.org/understanding-json-schema/reference/object.html#required-properties
"id",
"name",
"number",
"balance",
"currency"
],
"additionalProperties": false,
// дополнительных полей быть не должно
"properties": {
// описание полей: https://json-schema.org/understanding-json-schema/reference/object.html#properties
"id": {
"type": "integer"
// целое число: https://json-schema.org/understanding-json-schema/reference/numeric.html#integer
},
"name": {
"type": "string",
// строка: https://json-schema.org/understanding-json-schema/reference/string.html
"minLength": 1
// минимальная длина — 1: https://json-schema.org/understanding-json-schema/reference/string.html#length
},
"number": {
"type": "string",
// строка: https://json-schema.org/understanding-json-schema/reference/string.html
"pattern": "^•• \\d{4}$"
// соответствует регулярному выражению: https://json-schema.org/understanding-json-schema/reference/string.html#regular-expressions
},
"balance": {
"type": "integer"
// целое число: https://json-schema.org/understanding-json-schema/reference/numeric.html#integer
"default": 0
},
"currency": {
"type": "string",
"enum": [
"RUB",
"USD"
]
// строка: https://json-schema.org/understanding-json-schema/reference/string.html
"enum": ["RUB", "USD"]
}
}
}
Expand Down

0 comments on commit 949a3e9

Please sign in to comment.