From 5240ba623e2a77cf1bf446180085fa8ef9b975de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Bu=C3=9Fmann?= <till.bussmann@rwth-aachen.de> Date: Mon, 20 Jun 2022 20:42:37 +0200 Subject: [PATCH] Updated tests to new specification --- .../rwth/swc/sqa/controller/CustomerTest.java | 26 +++++++++++++++++++ .../swc/sqa/controller/DiscountCardTest.java | 7 +++++ .../rwth/swc/sqa/controller/TicketTest.java | 23 +++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/rwth/swc/sqa/controller/CustomerTest.java b/src/test/java/de/rwth/swc/sqa/controller/CustomerTest.java index 1500e7b..985f2af 100644 --- a/src/test/java/de/rwth/swc/sqa/controller/CustomerTest.java +++ b/src/test/java/de/rwth/swc/sqa/controller/CustomerTest.java @@ -76,4 +76,30 @@ class CustomerTest { .statusCode(expectedStatus); } + @Test + void customerInsertWithExistingId() { + // Create a new customer + Customer customer = new Customer(); + customer.birthdate("2000-05-20"); + customer.id(13L); + + given().header("Content-Type", "application/json") + .body(customer) + .post(CUSTOMERS_PATH).then() + .assertThat() + .statusCode(201) + .body("birthdate", equalTo(customer.getBirthdate())) + .body("disabled", equalTo(false)); + + Customer customer2 = new Customer(); + customer2.birthdate("2010-05-20"); + customer2.id(13L); + + given().header("Content-Type", "application/json") + .body(customer) + .post(CUSTOMERS_PATH).then() + .assertThat() + .statusCode(400); + } + } \ No newline at end of file diff --git a/src/test/java/de/rwth/swc/sqa/controller/DiscountCardTest.java b/src/test/java/de/rwth/swc/sqa/controller/DiscountCardTest.java index 84816a0..50466f2 100644 --- a/src/test/java/de/rwth/swc/sqa/controller/DiscountCardTest.java +++ b/src/test/java/de/rwth/swc/sqa/controller/DiscountCardTest.java @@ -3,6 +3,10 @@ package de.rwth.swc.sqa.controller; import de.rwth.swc.sqa.model.Customer; import de.rwth.swc.sqa.model.DiscountCard; import io.restassured.RestAssured; +import io.restassured.path.json.JsonPath; +import io.restassured.response.Response; +import org.json.JSONArray; +import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -10,6 +14,9 @@ import org.junit.jupiter.params.provider.CsvSource; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; +import java.util.ArrayList; +import java.util.List; + import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; diff --git a/src/test/java/de/rwth/swc/sqa/controller/TicketTest.java b/src/test/java/de/rwth/swc/sqa/controller/TicketTest.java index 69f35a2..e6ab96f 100644 --- a/src/test/java/de/rwth/swc/sqa/controller/TicketTest.java +++ b/src/test/java/de/rwth/swc/sqa/controller/TicketTest.java @@ -2,6 +2,7 @@ package de.rwth.swc.sqa.controller; import de.rwth.swc.sqa.model.TicketRequest; import io.restassured.RestAssured; +import io.swagger.models.auth.In; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -44,7 +45,6 @@ class TicketTest { .body("validFrom", equalTo(ticket.getValidFrom())) .body("validFor", equalTo(ticket.getValidFor().toString())) .body("disabled", equalTo(false)) - .body("discountCard", equalTo(0)) .body("student", equalTo(false)) .body("zone", equalTo(ticket.getZone().toString())); } @@ -143,4 +143,25 @@ class TicketTest { .statusCode(expectedStatus); } + @ParameterizedTest + @CsvSource({"25,201", + "50,201", + "33,400", + "100,400"}) + void ticketWithInvalidDiscountCardValues(int givenValue, int expectedStatus) { + // Create a new ticket + TicketRequest ticket = new TicketRequest(); + ticket.validFrom("2020-05-20T10:38:59"); + ticket.birthdate("2000-05-20"); + ticket.validFor(TicketRequest.ValidForEnum._1Y); + ticket.zone(TicketRequest.ZoneEnum.C); + ticket.discountCard(givenValue); + + given().header("Content-Type", "application/json") + .body(ticket) + .post(TICKETS_PATH).then() + .assertThat() + .statusCode(expectedStatus); + } + } \ No newline at end of file -- GitLab