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 1500e7ba01841036d630a7135bc81b76c7f6154e..985f2af32dfa3426d4ebac5297623e01a1a40ebf 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 84816a0d5f0da2d95a4c3a4bd438425512a8a775..50466f2b2b943af9281ae66e327264604814e04c 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 69f35a277ebd746360fa97332cae1659069264d3..e6ab96f8a4896fe2a5eec48cb951293338d6023f 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