Skip to content
Snippets Groups Projects
Commit a4351049 authored by Rafi Zereselasie (raz070)'s avatar Rafi Zereselasie (raz070)
Browse files
parents 9ce9db12 c26de784
No related branches found
No related tags found
No related merge requests found
......@@ -250,14 +250,6 @@ public class Model {
if (start < 0 || end < 0 || end > 2359 || start >= end){
return "Invalid start or end time";
}
if (this.employees.containsKey(id)) {
int[] dayOfTheWeekAvailability = this.employees.get(id).getAvailabilityForDay(LocalDate.parse(date)
.getDayOfWeek().getValue() % 7);
if (dayOfTheWeekAvailability[0] > start || dayOfTheWeekAvailability[1] < start || dayOfTheWeekAvailability[1] < end) {
return "Shift time conflicts with employees availability";
}
}
if (this.employees.containsKey(id)){
for (Shift shift : getShiftsByDay(date)) {
if (shift.getEmployeeID() == id) {
......@@ -268,10 +260,18 @@ public class Model {
return "Shift time conflict with existing shift";
}
*/
return "Shift time conflict for employee";
return "Shift time conflict for employee";
}
}
}
if (this.employees.containsKey(id)) {
int[] dayOfTheWeekAvailability = this.employees.get(id).getAvailabilityForDay(LocalDate.parse(date)
.getDayOfWeek().getValue() % 7);
if (dayOfTheWeekAvailability[0] > start || dayOfTheWeekAvailability[1] < start || dayOfTheWeekAvailability[1] < end) {
return "Shift time conflicts with employees availability";
}
}
else {return "No Employee with that ID";}
writer.println("addShift/" + id + "/" + date + "/" + start + "/" + end + "/" + " ");
......
......@@ -4,6 +4,15 @@ import java.util.concurrent.TimeUnit;
public class ModelTestSuite {
//needs a fresh or empty database to run tests
// If running the test again, all mySQL tables need to be truncated like below.
/*
SET FOREIGN_KEY_CHECKS = 0;
truncate employees;
truncate shifts;
truncate positions;
truncate timeoff;
truncate availabilities;
*/
public static void main(String[] args) throws InterruptedException {
Model testModel = new Model("localhost", 8989);
try {
......@@ -146,6 +155,15 @@ public class ModelTestSuite {
else passed += 1;
total += 1;
TimeUnit.SECONDS.sleep(1);
output = testModel.getEmployeeByID(1);
if (!output.equals("John Smith")){
System.out.println(total + ": Test getEmployee failed.");
System.out.println("Expected: John Smith\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
if (testModel.employeeSize() != 1){
System.out.println(total + ": Test employeeSize failed.");
System.out.println("Expected: 1\nReceived: " + testModel.employeeSize() + "\n");
......@@ -163,6 +181,15 @@ public class ModelTestSuite {
TimeUnit.SECONDS.sleep(1);
output = testModel.getEmployee(testModel.getIDbyIndex(1)).getFullName();
if (!output.equals("Freya Fulltime")){
System.out.println(total + ": Test getEmployee failed.");
System.out.println("Expected: Freya Fulltime\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
TimeUnit.SECONDS.sleep(1);
output = testModel.getEmployeeByID(2);
if (!output.equals("Freya Fulltime")){
System.out.println(total + ": Test getEmployeeByID failed.");
System.out.println("Expected: Freya Fulltime\nReceived: " + output + "\n");
......@@ -177,6 +204,146 @@ public class ModelTestSuite {
else passed += 1;
total += 1;
output = testModel.addShift(1, "2022-03-20", 900, 1700);
if (!output.equals("New shift added")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: New shift added\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
TimeUnit.SECONDS.sleep(1);
output = testModel.addShift(1, "2022-03-20", 900, 1700);
if (!output.equals("Shift time conflict for employee")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: Shift time conflict for employee\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
TimeUnit.SECONDS.sleep(1);
output = testModel.addShift(1, "2022-03-20", 0, 800);
if (!output.equals("Shift time conflict for employee")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: Shift time conflict for employee\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
TimeUnit.SECONDS.sleep(1);
output = testModel.addShift(1, "2022-03-20", 1800, 2359);
if (!output.equals("Shift time conflict for employee")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: Shift time conflict for employee\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.addShift(1, "2022-03-21", 900, 1700);
if (!output.equals("New shift added")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: New shift added\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.addShift(2, "2022-03-20", 900, 1700);
if (!output.equals("New shift added")){
System.out.println(total + ": Test addShift failed.");
System.out.println("Expected: New shift added\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", -12.0f);
if (!output.equals("Invalid wage")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Invalid wage\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail.com", "306/123-4567", 12.0f);
if (!output.equals("phoneNumber contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: phoneNumber contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail.com", "306-123,4567", 12.0f);
if (!output.equals("phoneNumber contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: phoneNumber contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail/.com", "306-123-4567", 12.0f);
if (!output.equals("Email contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Email contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail.com,", "306-123-4567", 12.0f);
if (!output.equals("Email contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Email contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smi/th", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Name contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Name contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "J,ohn", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Name contains illegal character(s)")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Name contains illegal character(s)\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(-1, "John", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Invalid ID")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Invalid ID\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(4, "John", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Employee does not exist")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Employee does not exist\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(1, "John", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Employee edited")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Employee edited\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
output = testModel.editEmployee(2, "John", "Smith", false, "Johnsmith@gmail.com", "306-123-4567", 12.0f);
if (!output.equals("Employee edited")){
System.out.println(total + ": Test editEmployee failed.");
System.out.println("Expected: Employee edited\nReceived: " + output + "\n");
}
else passed += 1;
total += 1;
/*
TimeUnit.SECONDS.sleep(1);
output = testModel.removeEmployee("2");
if (!output.equals("Employee removed")){
......@@ -212,6 +379,7 @@ public class ModelTestSuite {
total += 1;
*/
total-= 1;
System.out.println(passed + "/" + total + " tests passed.");
System.exit(0);
......
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