Skip to content
Snippets Groups Projects
Commit 5142d563 authored by Sara Prifti's avatar Sara Prifti
Browse files

different cases for buyTickets Tests Work!

parent 7142e8cc
Branches Ying
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import static de.rwth.swc.sqa.model.Ticket.ValidForEnum.*;
@Service
public class DataService {
public static List<Customer> customerList = new ArrayList<Customer>();
......@@ -38,25 +40,36 @@ public class DataService {
//if customer is a senior
if(DataService.customerIsSenior(customer)){
if(ticket.getValidFor().getValue().equals("1d") || ticket.getValidFor().getValue().equals("30d") || ticket.getValidFor().getValue().equals("1y")){
isValid=true;
if(ticket.getStudent()==false){
isValid=true;
}
return isValid;
}
//if customer is a student
//it does not matter if it`s not a student since he is still an adult and can buy an adult ticket
}else if (DataService.customerIsStudent(customer)){
if(ticket.getValidFor().getValue().equals("30d") || ticket.getValidFor().getValue().equals("1y")){
isValid=true;
if (ticket.getValidFor().getValue().equals("30d") || ticket.getValidFor().getValue().equals("1y")) {
isValid = true;
return isValid;
}
}else if (DataService.customerIsChild(customer)){
if(ticket.getValidFor().getValue().equals("1h") || ticket.getValidFor().getValue().equals("30d") || ticket.getValidFor().getValue().equals("1y")){
isValid=true;
if((ticket.getValidFor().getValue().equals("1h") || ticket.getValidFor().getValue().equals("30d") || ticket.getValidFor().getValue().equals("1y") )){
if(ticket.getStudent()==false){
isValid=true;
}
return isValid;
}
}else if (DataService.customerIsAdult(customer)){
isValid=true;
return isValid;
if(ticket.getStudent()==false){
isValid=true;
return isValid;
}
}
return isValid;
}
......@@ -77,7 +90,7 @@ public class DataService {
//customer is senior
//Senior
//Senior >60
//born before 1962
public static boolean customerIsSenior(Customer customer){
boolean isSenior= false;
......@@ -90,7 +103,7 @@ public class DataService {
}
//customer is a child
//customer is a child <14
//born before 2008
public static boolean customerIsChild(Customer customer){
boolean isChild= false;
......@@ -102,7 +115,7 @@ public class DataService {
}
//Student
//Student <28
//born after 1994
public static boolean customerIsStudent(Customer customer){
boolean isStudent= false;
......@@ -113,7 +126,7 @@ public class DataService {
return isStudent;
}
//Adult
//Adult is not a child
//after 2008
public static boolean customerIsAdult(Customer customer){
boolean isAdult = false;
......
......@@ -40,6 +40,7 @@ public class TicketController implements TicketsApi{
Customer customer=new Customer();
customer.setBirthdate(body.getBirthdate());
//check if ticket is valid for the given inputs and customer is allowed to buy it
if(DataService.ticketIsValidForTheCustomerAge(customer,ticket)){
DataService.ticketList.add(ticket);
......
......@@ -44,29 +44,94 @@ public class TicketTest {
.body(parms1).when().post("/tickets").then().statusCode(400);
//200
//adult and not student
parms1.clear();
parms1.put("birthdate", "1992-01-01");
parms1.put("validFor", "1d");
parms1.put("zone", "A");
parms1.put("student", false);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(200);
//adult and student
//400
parms1.clear();
parms1.put("birthdate", "1992-01-01");
parms1.put("validFor", "30d");
parms1.put("zone", "A");
parms1.put("student", true);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(400);
//senior and 24h ticket
//200
parms1.clear();
parms1.put("birthdate", "1992-01-01");
parms1.put("birthdate", "1962-01-01");
parms1.put("validFor", "30d");
parms1.put("zone", "A");
parms1.put("student", false);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(200);
//child and 24h ticket
//400
parms1.clear();
parms1.put("birthdate", "2010-01-01");
parms1.put("validFor", "1d");
parms1.put("zone", "A");
parms1.put("student", false);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(400);
//child and 30d ticket
parms1.clear();
parms1.put("birthdate", "2010-01-01");
parms1.put("validFor", "30d");
parms1.put("zone", "A");
parms1.put("student", false);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(200);
//student and 1h ticket
parms1.clear();
parms1.put("birthdate", "1997-01-01");
parms1.put("validFor", "1h");
parms1.put("zone", "A");
parms1.put("student", true);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(200);
.body(parms1).when().post("/tickets").then().statusCode(400);
//student and not a student ticket => does not matter since he/she can buy an adult ticket
parms1.clear();
parms1.put("birthdate", "1997-01-01");
parms1.put("validFor", "1h");
parms1.put("zone", "A");
parms1.put("student", true);
parms1.put("discountCard", true);
parms1.put("disabled", true);
parms1.put("validFrom", "2022-05-20 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms1).when().post("/tickets").then().statusCode(400);
}
......@@ -103,7 +168,7 @@ public class TicketTest {
parms.put("disabled", true);
parms.put("date", "2022-05-22 10:00:00");
RestAssured.given().header("content-Type", "application/json").and()
.body(parms).when().post(path).then().statusCode(200);
.body(parms).when().post(path).then().statusCode(403);
//200//信息一致,且有效期内
......@@ -112,7 +177,7 @@ public class TicketTest {
parms.put("ticketId", ticketId);
parms.put("birthdate", "1992-01-01");
parms.put("zone", "A");
parms.put("student", true);
parms.put("student", false);
parms.put("disabled", true);
parms.put("date", "2022-05-20 12:00:00");
RestAssured.given().header("content-Type", "application/json").and()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment