|
@ -2,6 +2,8 @@ package org.example; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
class AdministrationTest { |
|
|
class AdministrationTest { |
|
@ -274,4 +276,119 @@ class AdministrationTest { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testEnrollProfInCourse() { |
|
|
|
|
|
Administration administration = new Administration(); |
|
|
|
|
|
|
|
|
|
|
|
//Professor who is about to get enrolled in a course |
|
|
|
|
|
Professor professor = new Professor("P1001", "Alex", "Professor" ); |
|
|
|
|
|
administration.addProfessor(professor); |
|
|
|
|
|
|
|
|
|
|
|
//The "User input" to determine the professor |
|
|
|
|
|
String profID = professor.getProfessorID(); |
|
|
|
|
|
|
|
|
|
|
|
//Course the professor is being enrolled in |
|
|
|
|
|
Course course = new Course("Swag", "C101", 5); |
|
|
|
|
|
administration.addCourse(course); |
|
|
|
|
|
|
|
|
|
|
|
//The "User input" to determine the course |
|
|
|
|
|
String courseID = course.getCourseID(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Professor professorFound = administration.findProfessorById(profID); |
|
|
|
|
|
Course courseFound = administration.findCourseByID(courseID); |
|
|
|
|
|
|
|
|
|
|
|
//Grabs the coursesTaught List from the Professor the user wants to enroll |
|
|
|
|
|
List<Course> courseList = professorFound.getCoursesTaught(); |
|
|
|
|
|
//Assigning the course to the Prof by adding it the to the courseList |
|
|
|
|
|
courseList.add(course); |
|
|
|
|
|
//The Professor gets the updated courseList |
|
|
|
|
|
professorFound.setCoursesTaught(courseList); |
|
|
|
|
|
|
|
|
|
|
|
//Grabs the courseTaught List from the created Professor |
|
|
|
|
|
List<Course> checkList = professor.getCoursesTaught(); |
|
|
|
|
|
boolean hasCourse = false; |
|
|
|
|
|
|
|
|
|
|
|
//Checks if this List no contains the newly added course |
|
|
|
|
|
for (Course courseSearch : checkList) |
|
|
|
|
|
{ |
|
|
|
|
|
if(courseSearch.getCourseID() == courseID) |
|
|
|
|
|
{ |
|
|
|
|
|
hasCourse = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//If true everything worked |
|
|
|
|
|
assertTrue(hasCourse); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void registerUser() { |
|
|
|
|
|
Administration administration = new Administration(); |
|
|
|
|
|
//Selects the userType |
|
|
|
|
|
int userType = 1; |
|
|
|
|
|
|
|
|
|
|
|
//Checks if the user Input correct; in this case its pre-determined |
|
|
|
|
|
boolean correctData = false; |
|
|
|
|
|
while(!correctData) |
|
|
|
|
|
{ |
|
|
|
|
|
//User Input |
|
|
|
|
|
String userName = "Tobias"; |
|
|
|
|
|
String userId = "S1010"; |
|
|
|
|
|
|
|
|
|
|
|
//Checks if the entered id is already being used |
|
|
|
|
|
if(administration.findProfessorById(userId) != null || administration.findAdminById(userId) != null || administration.findStudentById(userId) != null) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if(administration.findProfessorById(userId) == null || administration.findAdminById(userId) == null || administration.findStudentById(userId) == null) |
|
|
|
|
|
{ |
|
|
|
|
|
//the entered id is not used |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!administration.rightPrefix(userId, userType)) |
|
|
|
|
|
{ |
|
|
|
|
|
//the prefix is wrong |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if(!administration.isNumber(userId)) |
|
|
|
|
|
{ |
|
|
|
|
|
//the substring does not contain only digits |
|
|
|
|
|
System.out.println("Every character besides the first one need to be digits"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
//the id is not being used and has the right id-"syntax" |
|
|
|
|
|
System.out.println("The Id has not been used already!"); |
|
|
|
|
|
correctData = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (userType) |
|
|
|
|
|
{ |
|
|
|
|
|
case 1: //Student |
|
|
|
|
|
Student student = new Student(userName, userId, "Student"); |
|
|
|
|
|
administration.addStudents(student); |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: //Admin |
|
|
|
|
|
Admin admin = new Admin(userName, userId, "Admin"); |
|
|
|
|
|
administration.addAdmin(admin); |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: //Professor |
|
|
|
|
|
Professor professor = new Professor(userId, userName, "Professor"); |
|
|
|
|
|
administration.addProfessor(professor); |
|
|
|
|
|
default: //Error |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//If All three are correct, the registerUser Function has been successful |
|
|
|
|
|
assertEquals("Tobias", administration.findStudentById("S1010").getStudentName()); |
|
|
|
|
|
assertEquals("S1010", administration.findStudentById("S1010").getStudentId()); |
|
|
|
|
|
assertEquals("Student",administration.findStudentById("S1010").getStudentRole()); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |