diff --git a/proJect/pom.xml b/proJect/pom.xml index 8427783..f4f412a 100644 --- a/proJect/pom.xml +++ b/proJect/pom.xml @@ -14,22 +14,22 @@ - org.junit.jupiter - junit-jupiter-api - 5.9.2 + io.rest-assured + rest-assured + 5.3.2 test + - org.junit.jupiter - junit-jupiter-engine - 5.9.2 - test + com.fasterxml.jackson.core + jackson-databind + 2.16.1 org.junit.jupiter - junit-jupiter-params - 5.9.2 + junit-jupiter-engine + 5.10.0 test diff --git a/proJect/src/main/java/anlov/java/Factorial.java b/proJect/src/main/java/anlov/java/Factorial.java deleted file mode 100644 index 27a9dcf..0000000 --- a/proJect/src/main/java/anlov/java/Factorial.java +++ /dev/null @@ -1,15 +0,0 @@ -package anlov.java; - -public class Factorial { - - public static long getFactorial(int num) { - if (num < 0) { - throw new IllegalArgumentException("Число должно быть положительным"); - } - int factorial = 1; - for (int i = 1; i <= num; i++) { - factorial *= i; - } - return factorial; - } -} diff --git a/proJect/src/main/java/anlov/java/Main.java b/proJect/src/main/java/anlov/java/Main.java deleted file mode 100644 index c14deaa..0000000 --- a/proJect/src/main/java/anlov/java/Main.java +++ /dev/null @@ -1,10 +0,0 @@ -package anlov.java; - - -import java.util.Arrays; - -public class Main { - public static void main(String[] args) { - System.out.println(Factorial.getFactorial(3)); - } -} \ No newline at end of file diff --git a/proJect/src/main/java/anlov/java/People.java b/proJect/src/main/java/anlov/java/People.java new file mode 100644 index 0000000..330aa11 --- /dev/null +++ b/proJect/src/main/java/anlov/java/People.java @@ -0,0 +1,33 @@ +package anlov.java; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class People { + + ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter(); + private String name; + private String work; + + public People(String name, String work) { + this.name = name; + this.work = work; + } + + public String getName() { + return name; + } + + public String getWork() { + return work; + } + + public String toJson() { + try { + return writer.writeValueAsString(this); + } catch (JsonProcessingException e) { + throw new RuntimeException(); + } + } +} \ No newline at end of file diff --git a/proJect/src/test/java/BaseTest.java b/proJect/src/test/java/BaseTest.java new file mode 100644 index 0000000..37f882a --- /dev/null +++ b/proJect/src/test/java/BaseTest.java @@ -0,0 +1,18 @@ +import anlov.java.People; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; + +import static io.restassured.RestAssured.expect; +import static io.restassured.RestAssured.given; + +public class BaseTest { + + People michail = new People("Michail", "Driver"); + + RequestSpecification baseUri = given() + .log().body() + .baseUri("https://postman-echo.com"); + + ResponseSpecification statusCode = expect() + .statusCode(200); +} \ No newline at end of file diff --git a/proJect/src/test/java/FactorialTest.java b/proJect/src/test/java/FactorialTest.java deleted file mode 100644 index 618d24f..0000000 --- a/proJect/src/test/java/FactorialTest.java +++ /dev/null @@ -1,34 +0,0 @@ -import anlov.java.Factorial; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - - -class FactorialTest { - - @DisplayName("Check factorial if num equals 0") - @Test - void checkFactorial() { - assertEquals(1, Factorial.getFactorial(0)); - } - - @DisplayName("Check factorial if num more 0") - @ParameterizedTest - @ValueSource(ints = {1, 2, 3, 4}) - void checkMoreZero(int num) { - long[] numbers = {1, 2, 6, 24}; - assertEquals(numbers[num - 1], Factorial.getFactorial(num)); - - } - - @Test - void negativeInputShouldThrowException() { - assertThrows(IllegalArgumentException.class, - () -> Factorial.getFactorial(-5), "Число должно быть больше нуля"); - } -} diff --git a/proJect/src/test/java/PostmanTest.java b/proJect/src/test/java/PostmanTest.java new file mode 100644 index 0000000..655e22d --- /dev/null +++ b/proJect/src/test/java/PostmanTest.java @@ -0,0 +1,65 @@ +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.core.IsEqual.equalTo; + +class PostmanTest extends BaseTest { + + @Test + @DisplayName("Check uri") + public void checkGet() { + baseUri + .when().get("/get") + .then() + .spec(statusCode); + } + + @Test + @DisplayName("Check Post") + public void checkPost() { + baseUri + .contentType("application/json").body(michail) + .when().post("/post") + .then() + .body("json.name", equalTo(michail.getName())) + .body("json.work", equalTo(michail.getWork())) + .spec(statusCode); + } + + @Test + @DisplayName("Check Put") + public void checkPut() { + baseUri + .contentType("application/json").body(michail.toJson()) + .when().put("/put") + .then() + .body("json.name", equalTo(michail.getName())) + .body("json.work", equalTo(michail.getWork())) + .spec(statusCode); + } + + @Test + @DisplayName("Check Patch") + public void checkPath() { + baseUri + .contentType("application/json").body(michail.toJson()) + .when().patch("/patch") + .then() + .body("json.name", equalTo(michail.getName())) + .body("json.work", equalTo(michail.getWork())) + .spec(statusCode); + + } + + @Test + @DisplayName("Check Delete") + public void checkDel() { + baseUri + .contentType("application/json").body(michail.toJson()) + .when().delete("/delete") + .then() + .body("json.name", equalTo(michail.getName())) + .body("json.work", equalTo(michail.getWork())) + .spec(statusCode); + } +} \ No newline at end of file