diff --git a/.idea/4156-Miniproject-2024-Students-Java.iml b/.idea/4156-Miniproject-2024-Students-Java.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/4156-Miniproject-2024-Students-Java.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..99e8da5a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..28c13ebd --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..712ab9d9 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..d537aae5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..e31d4fb6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..561915ce --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + 1725901419913 + + + + \ No newline at end of file diff --git a/.zshrc b/.zshrc new file mode 100644 index 00000000..99b4ebe7 --- /dev/null +++ b/.zshrc @@ -0,0 +1 @@ +export PATH=$PATH:/Users/wilson/apache-maven-3.9.5/bin/ diff --git a/IndividualProject/data.txt b/IndividualProject/data.txt new file mode 100644 index 00000000..53395194 Binary files /dev/null and b/IndividualProject/data.txt differ diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java index 272c94c9..f6214eae 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java @@ -2,6 +2,11 @@ import java.io.*; +/** + * Represents a course within a department within an educational institution. + * This class stores information about the course, including its instructor's name, + * course location, timeslot, capacity and number of enrolled students. + */ public class Course implements Serializable { /** @@ -17,37 +22,43 @@ public Course(String instructorName, String courseLocation, String timeSlot, int this.instructorName = instructorName; this.courseTimeSlot = timeSlot; this.enrollmentCapacity = capacity; - this.enrolledStudentCount = 500; + this.enrolledStudentCount = 0; } - /** + /** * Enrolls a student in the course if there is space available. * * @return true if the student is successfully enrolled, false otherwise. */ public boolean enrollStudent() { - enrolledStudentCount++; - return false; + if (enrolledStudentCount < enrollmentCapacity) { + enrolledStudentCount++; + return true; + } + return false; } - /** + /** * Drops a student from the course if a student is enrolled. * * @return true if the student is successfully dropped, false otherwise. */ public boolean dropStudent() { - enrolledStudentCount--; - return false; + if (this.enrolledStudentCount == 0) { + return false; + } + this.enrolledStudentCount--; + return true; } public String getCourseLocation() { - return this.instructorName; + return this.courseLocation; } public String getInstructorName() { - return this.courseLocation; + return this.instructorName; } @@ -57,7 +68,8 @@ public String getCourseTimeSlot() { public String toString() { - return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot; + return "\nInstructor: " + instructorName + "; Location: " + + courseLocation + "; Time: " + courseTimeSlot; } @@ -77,12 +89,17 @@ public void reassignTime(String newTime) { public void setEnrolledStudentCount(int count) { - this.enrolledStudentCount = count; + if (count > enrollmentCapacity) { + enrolledStudentCount = enrollmentCapacity; + } + else{ + enrolledStudentCount = count; + } } public boolean isCourseFull() { - return enrollmentCapacity > enrolledStudentCount; + return !(enrollmentCapacity > enrolledStudentCount); } @Serial diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java index 4bab0f08..6b793ea4 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java @@ -33,7 +33,7 @@ public Department(String deptCode, HashMap courses, String depar * @return The number of majors. */ public int getNumberOfMajors() { - return -this.numberOfMajors; + return numberOfMajors; } /** @@ -42,7 +42,7 @@ public int getNumberOfMajors() { * @return The name of the department chair. */ public String getDepartmentChair() { - return "this.departmentChair"; + return departmentChair; } /** @@ -51,7 +51,7 @@ public String getDepartmentChair() { * @return A HashMap containing courses offered by the department. */ public HashMap getCourseSelection() { - return this.courses; + return courses; } /** @@ -65,7 +65,9 @@ public void addPersonToMajor() { * Decreases the number of majors in the department by one if it's greater than zero. */ public void dropPersonFromMajor() { - numberOfMajors--; + if (numberOfMajors > 0) { + numberOfMajors--; + } } /** @@ -100,13 +102,14 @@ public void createCourse(String courseId, String instructorName, String courseLo */ public String toString() { StringBuilder result = new StringBuilder(); + result.append("Department: ").append(deptCode).append("\n") + .append("courses offered: ").append("\n"); for (Map.Entry entry : courses.entrySet()) { String key = entry.getKey(); Course value = entry.getValue(); - result.append(deptCode).append(" ").append(key).append(": ").append(value.toString()) - .append("\n"); + result.append(key).append(": ").append(value.toString()).append("\n"); } - return "result.toString()"; + return result.toString().substring(0,result.length()-1); } @Serial diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java index 80860423..76767db8 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java @@ -7,296 +7,296 @@ /** * Class contains all the startup logic for the application. - * - * DO NOT MODIFY ANYTHING BELOW THIS POINT WITH REGARD TO FUNCTIONALITY + * + *

DO NOT MODIFY ANYTHING BELOW THIS POINT WITH REGARD TO FUNCTIONALITY * YOU MAY MAKE STYLE/REFACTOR MODIFICATIONS AS NEEDED */ @SpringBootApplication public class IndividualProjectApplication implements CommandLineRunner { - /** - * The main launcher for the service all it does - * is make a call to the overridden run method. - * - * @param args A {@code String[]} of any potential - * runtime arguments - */ - public static void main(String[] args) { - SpringApplication.run(IndividualProjectApplication.class, args); - } + /** + * The main launcher for the service all it does + * is make a call to the overridden run method. + * + * @param args A {@code String[]} of any potential + * runtime arguments + */ + public static void main(String[] args) { + SpringApplication.run(IndividualProjectApplication.class, args); + } - /** - * This contains all the setup logic, it will mainly be focused - * on loading up and creating an instance of the database based - * off a saved file or will create a fresh database if the file - * is not present. - * - * @param args A {@code String[]} of any potential runtime args - */ - public void run(String[] args) { - for (String arg : args) { - if (arg.equals("setup")) { - myFileDatabase = new MyFileDatabase(1, "./data.txt"); - resetDataFile(); - System.out.println("System Setup"); - return; - } - } - myFileDatabase = new MyFileDatabase(0, "./data.txt"); - System.out.println("Start up"); - } - - /** - * Overrides the database reference, used when testing. - * - * @param testData A {@code MyFileDatabase} object referencing test data. - */ - public static void overrideDatabase(MyFileDatabase testData) { - myFileDatabase = testData; - saveData = false; - } - - /** - * Allows for data to be reset in event of errors. - */ - public void resetDataFile() { - String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"}; - String[] locations = {"417 IAB", "309 HAV", "301 URIS"}; - - //data for coms dept - Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400); - coms1004.setEnrolledStudentCount(249); - Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250); - coms3134.setEnrolledStudentCount(242); - Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400); - coms3157.setEnrolledStudentCount(311); - Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250); - coms3203.setEnrolledStudentCount(215); - Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150); - coms3261.setEnrolledStudentCount(140); - Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125); - coms3251.setEnrolledStudentCount(99); - Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300); - coms3827.setEnrolledStudentCount(283); - Course coms4156 = new Course("Gail Kaiser", "501 NWC", times[2], 120); - coms4156.setEnrolledStudentCount(109); - HashMap courses = new HashMap<>(); - courses.put("1004", coms1004); - courses.put("3134", coms3134); - courses.put("3157", coms3157); - courses.put("3203", coms3203); - courses.put("3261", coms3261); - courses.put("3251", coms3251); - courses.put("3827", coms3827); - courses.put("4156", coms4156); - Department compSci = new Department("COMS", courses, "Luca Carloni", 2700); - HashMap mapping = new HashMap<>(); - mapping.put("COMS", compSci); - - //data for econ dept - Course econ1105 = new Course("Waseem Noor", locations[1], times[3], 210); - econ1105.setEnrolledStudentCount(187); - Course econ2257 = new Course("Tamrat Gashaw", "428 PUP", times[2], 125); - econ2257.setEnrolledStudentCount(63); - Course econ3211 = new Course("Murat Yilmaz", "310 FAY", times[1], 96); - econ3211.setEnrolledStudentCount(81); - Course econ3213 = new Course("Miles Leahey", "702 HAM", times[1], 86); - econ3213.setEnrolledStudentCount(77); - Course econ3412 = new Course("Thomas Piskula", "702 HAM", times[0], 86); - econ3412.setEnrolledStudentCount(81); - Course econ4415 = new Course("Evan D Sadler", locations[1], times[2], 110); - econ4415.setEnrolledStudentCount(63); - Course econ4710 = new Course("Matthieu Gomez", "517 HAM", "8:40-9:55", 86); - econ4710.setEnrolledStudentCount(37); - Course econ4840 = new Course("Mark Dean", "142 URIS", times[3], 108); - econ4840.setEnrolledStudentCount(67); - - courses = new HashMap<>(); - courses.put("1105", econ1105); - courses.put("2257", econ2257); - courses.put("3211", econ3211); - courses.put("3213", econ3213); - courses.put("3412", econ3412); - courses.put("4415", econ4415); - courses.put("4710", econ4710); - courses.put("4840", econ4840); - - Department econ = new Department("ECON", courses, "Michael Woodford", 2345); - mapping.put("ECON", econ); - - //data for ieor dept - Course ieor2500 = new Course("Uday Menon", "627 MUDD", times[0], 50); - ieor2500.setEnrolledStudentCount(52); - Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73); - ieor3404.setEnrolledStudentCount(80); - Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96); - ieor3658.setEnrolledStudentCount(87); - Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110); - ieor4102.setEnrolledStudentCount(92); - Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150); - ieor4106.setEnrolledStudentCount(161); - Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80); - ieor4405.setEnrolledStudentCount(19); - Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150); - ieor4511.setEnrolledStudentCount(50); - Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60); - ieor4540.setEnrolledStudentCount(33); - - courses = new HashMap<>(); - courses.put("2500", ieor2500); - courses.put("3404", ieor3404); - courses.put("3658", ieor3658); - courses.put("4102", ieor4102); - courses.put("4106", ieor4106); - courses.put("4405", ieor4405); - courses.put("4511", ieor4511); - courses.put("4540", ieor4540); - - Department ieor = new Department("IEOR", courses, "Jay Sethuraman", 67); - mapping.put("IEOR", ieor); - - //data for chem dept - Course chem1403 = new Course("Ruben M Savizky", locations[1], "6:10-7:25", 120); - chem1403.setEnrolledStudentCount(100); - Course chem1500 = new Course("Joseph C Ulichny", "302 HAV", "6:10-9:50", 46); - chem1500.setEnrolledStudentCount(50); - Course chem2045 = new Course("Luis M Campos", "209 HAV", "1:10-2:25", 50); - chem2045.setEnrolledStudentCount(29); - Course chem2444 = new Course("Christopher Eckdahl", locations[1], times[0], 150); - chem2444.setEnrolledStudentCount(150); - Course chem2494 = new Course("Talha Siddiqui", "202 HAV", "1:10-5:00", 24); - chem2494.setEnrolledStudentCount(18); - Course chem3080 = new Course("Milan Delor", "209 HAV", times[2], 60); - chem3080.setEnrolledStudentCount(18); - Course chem4071 = new Course("Jonathan S Owen", "320 HAV", "8:40-9:55", 42); - chem4071.setEnrolledStudentCount(29); - Course chem4102 = new Course("Dalibor Sames", "320 HAV", times[2], 28); - chem4102.setEnrolledStudentCount(27); - - courses = new HashMap<>(); - courses.put("1403", chem1403); - courses.put("1500", chem1500); - courses.put("2045", chem2045); - courses.put("2444", chem2444); - courses.put("2494", chem2494); - courses.put("3080", chem3080); - courses.put("4071", chem4071); - courses.put("4102", chem4102); - - Department chem = new Department("CHEM", courses, "Laura J. Kaufman", 250); - mapping.put("CHEM", chem); - - //data for phys dept - Course phys1001 = new Course("Szabolcs Marka", "301 PUP", times[3], 150); - phys1001.setEnrolledStudentCount(131); - Course phys1201 = new Course("Eric Raymer", "428 PUP", times[3], 145); - phys1201.setEnrolledStudentCount(130); - Course phys1602 = new Course("Kerstin M Perez", "428 PUP", times[2], 140); - phys1602.setEnrolledStudentCount(77); - Course phys2802 = new Course("Yury Levin", "329 PUP", "10:10-12:00", 60); - phys2802.setEnrolledStudentCount(23); - Course phys3008 = new Course("William A Zajc", "329 PUP", times[2], 75); - phys3008.setEnrolledStudentCount(60); - Course phys4003 = new Course("Frederik Denef", "214 PUP", times[1], 50); - phys4003.setEnrolledStudentCount(19); - Course phys4018 = new Course("James W McIver", "307 PUP", times[3], 30); - phys4018.setEnrolledStudentCount(18); - Course phys4040 = new Course("James C Hill", "214 PUP", times[1], 50); - phys4040.setEnrolledStudentCount(31); - - courses = new HashMap<>(); - courses.put("2802", phys2802); - courses.put("3008", phys3008); - courses.put("4003", phys4003); - courses.put("4018", phys4018); - courses.put("4040", phys4040); - courses.put("1602", phys1602); - courses.put("1001", phys1001); - courses.put("1201", phys1201); - - Department phys = new Department("PHYS", courses, "Dmitri N. Basov", 43); - mapping.put("PHYS", phys); - - //data for elen dept - Course elen1201 = new Course("David G Vallancourt", "301 PUP", times[1], 120); - elen1201.setEnrolledStudentCount(108); - Course elen3082 = new Course("Kenneth Shepard", "1205 MUDD", "4:10-6:40", 32); - elen3082.setEnrolledStudentCount(30); - Course elen3331 = new Course("David G Vallancourt", "203 MATH", times[0], 80); - elen3331.setEnrolledStudentCount(54); - Course elen3401 = new Course("Keren Bergman", "829 MUDD", times[3], 40); - elen3401.setEnrolledStudentCount(25); - Course elen3701 = new Course("Irving Kalet", "333 URIS", times[3], 50); - elen3701.setEnrolledStudentCount(24); - Course elen4510 = new Course("Mohamed Kamaludeen", "903 SSW", "7:00-9:30", 30); - elen4510.setEnrolledStudentCount(22); - Course elen4702 = new Course("Alexei Ashikhmin", "332 URIS", "7:00-9:30", 50); - elen4702.setEnrolledStudentCount(5); - Course elen4830 = new Course("Christine P Hendon", "633 MUDD", "10:10-12:40", 60); - elen4830.setEnrolledStudentCount(22); - - courses = new HashMap<>(); - courses.put("1201", elen1201); - courses.put("3082", elen3082); - courses.put("3331", elen3331); - courses.put("3401", elen3401); - courses.put("3701", elen3701); - courses.put("4510", elen4510); - courses.put("4702", elen4702); - courses.put("4830", elen4830); - - Department elen = new Department("ELEN", courses, "Ioannis Kymissis", 250); - mapping.put("ELEN", elen); - - //data for psyc dept - Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200); - psyc1001.setEnrolledStudentCount(191); - Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45); - psyc1610.setEnrolledStudentCount(42); - Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125); - psyc2235.setEnrolledStudentCount(128); - Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60); - psyc2620.setEnrolledStudentCount(55); - Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15); - psyc3212.setEnrolledStudentCount(15); - Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12); - psyc3445.setEnrolledStudentCount(12); - Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18); - psyc4236.setEnrolledStudentCount(17); - Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15); - psyc4493.setEnrolledStudentCount(9); - - courses = new HashMap<>(); - courses.put("1001", psyc1001); - courses.put("1610", psyc1610); - courses.put("2235", psyc2235); - courses.put("2620", psyc2620); - courses.put("3212", psyc3212); - courses.put("3445", psyc3445); - courses.put("4236", psyc4236); - courses.put("4493", psyc4493); - - Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437); - mapping.put("PSYC", psyc); - - myFileDatabase.setMapping(mapping); - } - - /** - * This contains all the overheading teardown logic, it will - * mainly be focused on saving all the created user data to a - * file, so it will be ready for the next setup. - */ - @PreDestroy - public void onTermination() { - System.out.println("Termination"); - if (saveData) { - myFileDatabase.saveContentsToFile(); - } - } - - - //Database Instance - public static MyFileDatabase myFileDatabase; - private static boolean saveData = true; + /** + * This contains all the setup logic, it will mainly be focused + * on loading up and creating an instance of the database based + * off a saved file or will create a fresh database if the file + * is not present. + * + * @param args A {@code String[]} of any potential runtime args + */ + public void run(String[] args) { + for (String arg : args) { + if (arg.equals("setup")) { + myFileDatabase = new MyFileDatabase(1, "./data.txt"); + resetDataFile(); + System.out.println("System Setup"); + return; + } + } + myFileDatabase = new MyFileDatabase(0, "./data.txt"); + System.out.println("Start up"); + } + + /** + * Overrides the database reference, used when testing. + * + * @param testData A {@code MyFileDatabase} object referencing test data. + */ + public static void overrideDatabase(MyFileDatabase testData) { + myFileDatabase = testData; + saveData = false; + } + + /** + * Allows for data to be reset in event of errors. + */ + public void resetDataFile() { + String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"}; + String[] locations = {"417 IAB", "309 HAV", "301 URIS"}; + + //data for coms dept + Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400); + coms1004.setEnrolledStudentCount(249); + Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250); + coms3134.setEnrolledStudentCount(242); + Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400); + coms3157.setEnrolledStudentCount(311); + Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250); + coms3203.setEnrolledStudentCount(215); + Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150); + coms3261.setEnrolledStudentCount(140); + Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125); + coms3251.setEnrolledStudentCount(99); + Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300); + coms3827.setEnrolledStudentCount(283); + Course coms4156 = new Course("Gail Kaiser", "501 NWC", times[2], 120); + coms4156.setEnrolledStudentCount(109); + HashMap courses = new HashMap<>(); + courses.put("1004", coms1004); + courses.put("3134", coms3134); + courses.put("3157", coms3157); + courses.put("3203", coms3203); + courses.put("3261", coms3261); + courses.put("3251", coms3251); + courses.put("3827", coms3827); + courses.put("4156", coms4156); + Department compSci = new Department("COMS", courses, "Luca Carloni", 2700); + HashMap mapping = new HashMap<>(); + mapping.put("COMS", compSci); + + //data for econ dept + Course econ1105 = new Course("Waseem Noor", locations[1], times[3], 210); + econ1105.setEnrolledStudentCount(187); + Course econ2257 = new Course("Tamrat Gashaw", "428 PUP", times[2], 125); + econ2257.setEnrolledStudentCount(63); + Course econ3211 = new Course("Murat Yilmaz", "310 FAY", times[1], 96); + econ3211.setEnrolledStudentCount(81); + Course econ3213 = new Course("Miles Leahey", "702 HAM", times[1], 86); + econ3213.setEnrolledStudentCount(77); + Course econ3412 = new Course("Thomas Piskula", "702 HAM", times[0], 86); + econ3412.setEnrolledStudentCount(81); + Course econ4415 = new Course("Evan D Sadler", locations[1], times[2], 110); + econ4415.setEnrolledStudentCount(63); + Course econ4710 = new Course("Matthieu Gomez", "517 HAM", "8:40-9:55", 86); + econ4710.setEnrolledStudentCount(37); + Course econ4840 = new Course("Mark Dean", "142 URIS", times[3], 108); + econ4840.setEnrolledStudentCount(67); + + courses = new HashMap<>(); + courses.put("1105", econ1105); + courses.put("2257", econ2257); + courses.put("3211", econ3211); + courses.put("3213", econ3213); + courses.put("3412", econ3412); + courses.put("4415", econ4415); + courses.put("4710", econ4710); + courses.put("4840", econ4840); + + Department econ = new Department("ECON", courses, "Michael Woodford", 2345); + mapping.put("ECON", econ); + + //data for ieor dept + Course ieor2500 = new Course("Uday Menon", "627 MUDD", times[0], 50); + ieor2500.setEnrolledStudentCount(52); + Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73); + ieor3404.setEnrolledStudentCount(80); + Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96); + ieor3658.setEnrolledStudentCount(87); + Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110); + ieor4102.setEnrolledStudentCount(92); + Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150); + ieor4106.setEnrolledStudentCount(161); + Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80); + ieor4405.setEnrolledStudentCount(19); + Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150); + ieor4511.setEnrolledStudentCount(50); + Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60); + ieor4540.setEnrolledStudentCount(33); + + courses = new HashMap<>(); + courses.put("2500", ieor2500); + courses.put("3404", ieor3404); + courses.put("3658", ieor3658); + courses.put("4102", ieor4102); + courses.put("4106", ieor4106); + courses.put("4405", ieor4405); + courses.put("4511", ieor4511); + courses.put("4540", ieor4540); + + Department ieor = new Department("IEOR", courses, "Jay Sethuraman", 67); + mapping.put("IEOR", ieor); + + //data for chem dept + Course chem1403 = new Course("Ruben M Savizky", locations[1], "6:10-7:25", 120); + chem1403.setEnrolledStudentCount(100); + Course chem1500 = new Course("Joseph C Ulichny", "302 HAV", "6:10-9:50", 46); + chem1500.setEnrolledStudentCount(50); + Course chem2045 = new Course("Luis M Campos", "209 HAV", "1:10-2:25", 50); + chem2045.setEnrolledStudentCount(29); + Course chem2444 = new Course("Christopher Eckdahl", locations[1], times[0], 150); + chem2444.setEnrolledStudentCount(150); + Course chem2494 = new Course("Talha Siddiqui", "202 HAV", "1:10-5:00", 24); + chem2494.setEnrolledStudentCount(18); + Course chem3080 = new Course("Milan Delor", "209 HAV", times[2], 60); + chem3080.setEnrolledStudentCount(18); + Course chem4071 = new Course("Jonathan S Owen", "320 HAV", "8:40-9:55", 42); + chem4071.setEnrolledStudentCount(29); + Course chem4102 = new Course("Dalibor Sames", "320 HAV", times[2], 28); + chem4102.setEnrolledStudentCount(27); + + courses = new HashMap<>(); + courses.put("1403", chem1403); + courses.put("1500", chem1500); + courses.put("2045", chem2045); + courses.put("2444", chem2444); + courses.put("2494", chem2494); + courses.put("3080", chem3080); + courses.put("4071", chem4071); + courses.put("4102", chem4102); + + Department chem = new Department("CHEM", courses, "Laura J. Kaufman", 250); + mapping.put("CHEM", chem); + + //data for phys dept + Course phys1001 = new Course("Szabolcs Marka", "301 PUP", times[3], 150); + phys1001.setEnrolledStudentCount(131); + Course phys1201 = new Course("Eric Raymer", "428 PUP", times[3], 145); + phys1201.setEnrolledStudentCount(130); + Course phys1602 = new Course("Kerstin M Perez", "428 PUP", times[2], 140); + phys1602.setEnrolledStudentCount(77); + Course phys2802 = new Course("Yury Levin", "329 PUP", "10:10-12:00", 60); + phys2802.setEnrolledStudentCount(23); + Course phys3008 = new Course("William A Zajc", "329 PUP", times[2], 75); + phys3008.setEnrolledStudentCount(60); + Course phys4003 = new Course("Frederik Denef", "214 PUP", times[1], 50); + phys4003.setEnrolledStudentCount(19); + Course phys4018 = new Course("James W McIver", "307 PUP", times[3], 30); + phys4018.setEnrolledStudentCount(18); + Course phys4040 = new Course("James C Hill", "214 PUP", times[1], 50); + phys4040.setEnrolledStudentCount(31); + + courses = new HashMap<>(); + courses.put("2802", phys2802); + courses.put("3008", phys3008); + courses.put("4003", phys4003); + courses.put("4018", phys4018); + courses.put("4040", phys4040); + courses.put("1602", phys1602); + courses.put("1001", phys1001); + courses.put("1201", phys1201); + + Department phys = new Department("PHYS", courses, "Dmitri N. Basov", 43); + mapping.put("PHYS", phys); + + //data for elen dept + Course elen1201 = new Course("David G Vallancourt", "301 PUP", times[1], 120); + elen1201.setEnrolledStudentCount(108); + Course elen3082 = new Course("Kenneth Shepard", "1205 MUDD", "4:10-6:40", 32); + elen3082.setEnrolledStudentCount(30); + Course elen3331 = new Course("David G Vallancourt", "203 MATH", times[0], 80); + elen3331.setEnrolledStudentCount(54); + Course elen3401 = new Course("Keren Bergman", "829 MUDD", times[3], 40); + elen3401.setEnrolledStudentCount(25); + Course elen3701 = new Course("Irving Kalet", "333 URIS", times[3], 50); + elen3701.setEnrolledStudentCount(24); + Course elen4510 = new Course("Mohamed Kamaludeen", "903 SSW", "7:00-9:30", 30); + elen4510.setEnrolledStudentCount(22); + Course elen4702 = new Course("Alexei Ashikhmin", "332 URIS", "7:00-9:30", 50); + elen4702.setEnrolledStudentCount(5); + Course elen4830 = new Course("Christine P Hendon", "633 MUDD", "10:10-12:40", 60); + elen4830.setEnrolledStudentCount(22); + + courses = new HashMap<>(); + courses.put("1201", elen1201); + courses.put("3082", elen3082); + courses.put("3331", elen3331); + courses.put("3401", elen3401); + courses.put("3701", elen3701); + courses.put("4510", elen4510); + courses.put("4702", elen4702); + courses.put("4830", elen4830); + + Department elen = new Department("ELEN", courses, "Ioannis Kymissis", 250); + mapping.put("ELEN", elen); + + //data for psyc dept + Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200); + psyc1001.setEnrolledStudentCount(191); + Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45); + psyc1610.setEnrolledStudentCount(42); + Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125); + psyc2235.setEnrolledStudentCount(128); + Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60); + psyc2620.setEnrolledStudentCount(55); + Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15); + psyc3212.setEnrolledStudentCount(15); + Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12); + psyc3445.setEnrolledStudentCount(12); + Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18); + psyc4236.setEnrolledStudentCount(17); + Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15); + psyc4493.setEnrolledStudentCount(9); + + courses = new HashMap<>(); + courses.put("1001", psyc1001); + courses.put("1610", psyc1610); + courses.put("2235", psyc2235); + courses.put("2620", psyc2620); + courses.put("3212", psyc3212); + courses.put("3445", psyc3445); + courses.put("4236", psyc4236); + courses.put("4493", psyc4493); + + Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437); + mapping.put("PSYC", psyc); + + myFileDatabase.setMapping(mapping); + } + + /** + * This contains all the overheading teardown logic, it will + * mainly be focused on saving all the created user data to a + * file, so it will be ready for the next setup. + */ + @PreDestroy + public void onTermination() { + System.out.println("Termination"); + if (saveData) { + myFileDatabase.saveContentsToFile(); + } + } + + + //Database Instance + public static MyFileDatabase myFileDatabase; + private static boolean saveData = true; } diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java index 09f504dc..26718bac 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java @@ -38,10 +38,10 @@ public ResponseEntity retrieveDepartment(@RequestParam(value = "deptCode") St departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); if (!departmentMapping.containsKey(deptCode.toUpperCase())) { - return new ResponseEntity<>("Department Not Found", HttpStatus.OK); + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); } else { return new ResponseEntity<>(departmentMapping.get(deptCode.toUpperCase()).toString(), - HttpStatus.NOT_FOUND); + HttpStatus.OK); } } catch (Exception e) { @@ -64,7 +64,8 @@ public ResponseEntity retrieveDepartment(@RequestParam(value = "deptCode") St * proper response. */ @GetMapping(value = "/retrieveCourse", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity retrieveCourse(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity retrieveCourse(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; if (doesDepartmentExists) { @@ -77,7 +78,7 @@ public ResponseEntity retrieveCourse(@RequestParam(value = "deptCode") String return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); } else { return new ResponseEntity<>(coursesMapping.get(Integer.toString(courseCode)).toString(), - HttpStatus.FORBIDDEN); + HttpStatus.OK); } } @@ -101,7 +102,8 @@ public ResponseEntity retrieveCourse(@RequestParam(value = "deptCode") String * response. */ @GetMapping(value = "/isCourseFull", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity isCourseFull(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity isCourseFull(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -140,10 +142,10 @@ public ResponseEntity getMajorCtFromDept(@RequestParam(value = "deptCode") St if (doesDepartmentExists) { HashMap departmentMapping; departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); - return new ResponseEntity<>("There are: " + -departmentMapping.get(deptCode) - .getNumberOfMajors() + " majors in the department", HttpStatus.OK); + return new ResponseEntity<>("There are: " + Integer.toString(departmentMapping + .get(deptCode).getNumberOfMajors()) + " majors in the department", HttpStatus.OK); } - return new ResponseEntity<>("Department Not Found", HttpStatus.FORBIDDEN); + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); } catch (Exception e) { return handleException(e); } @@ -189,7 +191,8 @@ public ResponseEntity identifyDeptChair(@RequestParam(value = "deptCode") Str * proper response. */ @GetMapping(value = "/findCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity findCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity findCourseLocation(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -226,7 +229,8 @@ public ResponseEntity findCourseLocation(@RequestParam(value = "deptCode") St * response. */ @GetMapping(value = "/findCourseInstructor", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity findCourseInstructor(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity findCourseInstructor(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -263,7 +267,8 @@ public ResponseEntity findCourseInstructor(@RequestParam(value = "deptCode") * indicating the proper response. */ @GetMapping(value = "/findCourseTime", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity findCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity findCourseTime(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -275,7 +280,7 @@ public ResponseEntity findCourseTime(@RequestParam(value = "deptCode") String coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); - return new ResponseEntity<>("The course meets at: " + "some time ", + return new ResponseEntity<>("The course meets at: " + requestedCourse.getCourseTimeSlot(), HttpStatus.OK); } else { return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); @@ -351,7 +356,8 @@ public ResponseEntity removeMajorFromDept(@RequestParam(value = "deptCode") S * code in tune with what has happened. */ @PatchMapping(value = "/dropStudentFromCourse", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity dropStudent(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + public ResponseEntity dropStudent(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -368,7 +374,8 @@ public ResponseEntity dropStudent(@RequestParam(value = "deptCode") String de if (isStudentDropped) { return new ResponseEntity<>("Student has been dropped.", HttpStatus.OK); } else { - return new ResponseEntity<>("Student has not been dropped.", HttpStatus.BAD_REQUEST); + return new ResponseEntity<>("No student in this course", + HttpStatus.BAD_REQUEST); //Student has not been dropped. } } else { return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); @@ -378,9 +385,23 @@ public ResponseEntity dropStudent(@RequestParam(value = "deptCode") String de } } - + /** + * Attempts to update enrollment count of the specified course. + * + * @param deptCode A {@code String} representing the department. + * + * @param courseCode A {@code int} representing the course within the department. + * + * @param count A {@code int} representing the enrollment count of the course. + * + * @return A {@code ResponseEntity} object containing an HTTP 200 + * response with an appropriate message or the proper status + * code in tune with what has happened. + */ @PatchMapping(value = "/setEnrollmentCount", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity setEnrollmentCount(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "count") int count) { + public ResponseEntity setEnrollmentCount(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode, + @RequestParam(value = "count") int count) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -415,7 +436,9 @@ public ResponseEntity setEnrollmentCount(@RequestParam(value = "deptCode") St * successful, or an error message if the course is not found */ @PatchMapping(value = "/changeCourseTime", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity changeCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "time") String time) { + public ResponseEntity changeCourseTime(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode, + @RequestParam(value = "time") String time) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -451,7 +474,9 @@ public ResponseEntity changeCourseTime(@RequestParam(value = "deptCode") Stri * successful, or an error message if the course is not found */ @PatchMapping(value = "/changeCourseTeacher", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "teacher") String teacher) { + public ResponseEntity changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode, + @RequestParam(value = "teacher") String teacher) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; @@ -473,9 +498,23 @@ public ResponseEntity changeCourseTeacher(@RequestParam(value = "deptCode") S } } - + /** + * Endpoint for changing the location of a course. + * This method handles PATCH requests to change the location of a course identified by + * department code and course code. If the course exists, its instructor is updated to the + * provided instructor. + * + * @param deptCode the code of the department containing the course + * @param courseCode the code of the course to change the instructor for + * @param location the new location for the course + * + * @return a ResponseEntity with a success message if the operation is + * successful, or an error message if the course is not found + */ @PatchMapping(value = "/changeCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity changeCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "location") String location) { + public ResponseEntity changeCourseLocation(@RequestParam(value = "deptCode") String deptCode, + @RequestParam(value = "courseCode") int courseCode, + @RequestParam(value = "location") String location) { try { boolean doesCourseExists; doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java index 4edd00f9..1382494d 100644 --- a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java +++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java @@ -12,16 +12,113 @@ public class CourseUnitTests { @BeforeAll public static void setupCourseForTesting() { - testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250); + testCourse = new Course("Gail Kaiser", "501 NWC", + "10:10-11:25", 120); + //testCourse.setEnrolledStudentCount(110); + } + + @Test + public void dropStudentTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + boolean res = testCourse.dropStudent(); + assertEquals(false, res); + } + + @Test + public void enrollStudentTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + boolean res = testCourse.enrollStudent(); + assertEquals(true, res); + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 0); + assertEquals(false, testCourse.enrollStudent()); + } + + @Test + public void getCourseLocationTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + String res = testCourse.getCourseLocation(); + assertEquals("501 NWC", res); } + @Test + public void getInstructorNameTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + String res = testCourse.getInstructorName(); + assertEquals("Gail Kaiser", res); + } + + @Test + public void getCourseTimeSlotTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + String res = testCourse.getCourseTimeSlot(); + assertEquals("10:10-11:25", res); + } + + @Test + public void reassignInstructorTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + testCourse.reassignInstructor("TA"); + String res = testCourse.getInstructorName(); + assertEquals("TA", res); + } @Test public void toStringTest() { - String expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55"; + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + String expectedResult = + "\nInstructor: Gail Kaiser; Location: 501 NWC; Time: 10:10-11:25"; assertEquals(expectedResult, testCourse.toString()); } + @Test + public void reassignLocationTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + testCourse.reassignLocation("Online"); + String res = testCourse.getCourseLocation(); + assertEquals("Online", res); + } + + @Test + public void reassignTimeTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + testCourse.reassignTime("9:10-10:25"); + String res = testCourse.getCourseTimeSlot(); + assertEquals("9:10-10:25", res); + } + + @Test + public void isCourseFullTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + assertEquals(false, testCourse.isCourseFull()); + testCourse.setEnrolledStudentCount(120); + assertEquals(true, testCourse.isCourseFull()); + testCourse.dropStudent(); + assertEquals(false, testCourse.isCourseFull()); + testCourse.enrollStudent(); + assertEquals(true, testCourse.isCourseFull()); + } + + @Test + public void setEnrolledStudentCountTest() { + testCourse = new Course("Gail Kaiser", + "501 NWC", "10:10-11:25", 120); + testCourse.setEnrolledStudentCount(1000); + assertEquals(false, testCourse.enrollStudent()); + } + + + /** The test course instance used for testing. */ public static Course testCourse; } diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java new file mode 100644 index 00000000..8c91d2c0 --- /dev/null +++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java @@ -0,0 +1,123 @@ +package dev.coms4156.project.individualproject; + +import org.junit.jupiter.api.*; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.HashMap; + +@SpringBootTest +@ContextConfiguration + +public class DepartmentUnitTests { + @BeforeAll + public static void setupDepartmentForTesting() { + String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"}; + String[] locations = {"417 IAB", "309 HAV", "301 URIS"}; + + //data for coms dept + Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400); + coms1004.setEnrolledStudentCount(249); + Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250); + coms3134.setEnrolledStudentCount(242); + Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400); + coms3157.setEnrolledStudentCount(311); + Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250); + coms3203.setEnrolledStudentCount(215); + Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150); + coms3261.setEnrolledStudentCount(140); + Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125); + coms3251.setEnrolledStudentCount(99); + Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300); + coms3827.setEnrolledStudentCount(283); + courses = new HashMap<>(); + courses.put("1004", coms1004); + courses.put("3134", coms3134); + courses.put("3157", coms3157); + courses.put("3203", coms3203); + courses.put("3261", coms3261); + courses.put("3251", coms3251); + courses.put("3827", coms3827); + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + } + + + @Test + public void numberOfMajorsTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + assertEquals(2700, testDepartment.getNumberOfMajors()); + } + + @Test + public void getDepartmentChairTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + assertEquals("Luca Carloni", testDepartment.getDepartmentChair()); + } + + @Test + public void getCourseSelectionTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + assertEquals(courses, testDepartment.getCourseSelection()); + } + + @Test + public void addPersonToMajorTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + testDepartment.addPersonToMajor(); + assertEquals(2701, testDepartment.getNumberOfMajors()); + } + + @Test + public void dropPersonFromMajorTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + testDepartment.dropPersonFromMajor(); + assertEquals(2699, testDepartment.getNumberOfMajors()); + testDepartment= new Department("EMPTY", null, "None", 0); + testDepartment.dropPersonFromMajor(); + assertEquals(0, testDepartment.getNumberOfMajors()); + } + + @Test + public void addCourseTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + testDepartment.addCourse(null, null); + Course coms4156 = new Course("Gail Kaiser", "501 NWC", "10:10-11:25", 120); + coms4156.setEnrolledStudentCount(109); + testDepartment.addCourse("4156", coms4156); + assertEquals(coms4156, testDepartment.getCourseSelection().get("4156")); + } + + @Test + public void createCourseTest() { + testDepartment= new Department("COMS", courses, "Luca Carloni", 2700); + testDepartment.createCourse("4156","Gail Kaiser", "501 NWC", "10:10-11:25", 120); + Course coms4156 = new Course("Gail Kaiser", "501 NWC", "10:10-11:25", 120); + coms4156.setEnrolledStudentCount(109); + assertEquals(coms4156.toString(), testDepartment.getCourseSelection().get("4156").toString()); + } + + @Test + public void toStringTest() { + HashMap computerCourses = new HashMap<>(); + Course coms4156 = new Course("Gail Kaiser", "501 NWC", "10:10-11:25", 120); + Course coms3827 = new Course("Daniel Rubenstein", "207 Math", "10:10-11:25", 300); + computerCourses.put("4156",coms4156); + computerCourses.put("3827",coms3827); + testDepartment= new Department("COMS", computerCourses, "Luca Carloni", 2700); + String res = "Department: COMS\n" + "courses offered: \n" + "3827: \n" + + "Instructor: Daniel Rubenstein; Location: 207 Math; Time: 10:10-11:25\n" + + "4156: \n" + "Instructor: Gail Kaiser; Location: 501 NWC; Time: 10:10-11:25"; + assertEquals(res, testDepartment.toString()); + } + + + + + + /** The test instance used for testing. */ + public static Department testDepartment; + public static HashMap courses; + +} diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RCUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RCUnitTests.java new file mode 100644 index 00000000..56c1678c --- /dev/null +++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RCUnitTests.java @@ -0,0 +1,189 @@ +package dev.coms4156.project.individualproject; + +import org.junit.jupiter.api.*; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.HashMap; + +@SpringBootTest +@ContextConfiguration + + + + +public class RCUnitTests { + @BeforeAll + public static void setupRCForTesting() { + rc = new RouteController(); + dept = "nosuchdept"; + courseId1 = 0000; + coms = "COMS"; + coms4156=4156; + SpringApplication.run(IndividualProjectApplication.class, "setup"); + departmentMapping=IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + } + + @Test + public void indexTest() { + String expected = "Welcome, in order to make an API call direct your browser or Postman to an endpoint " + + "\n\n This can be done using the following format: \n\n http:127.0.0" + + ".1:8080/endpoint?arg=value"; + assertEquals(expected, rc.index()); + } + + @Test + public void retrieveDepartmentTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.retrieveDepartment(dept)); + assertEquals(new ResponseEntity<>(departmentMapping.get(coms.toUpperCase()).toString(), + HttpStatus.OK), rc.retrieveDepartment(coms)); + assertEquals(new ResponseEntity<>("An Error has occurred", HttpStatus.OK), rc.retrieveDepartment(null)); + } + + @Test + public void retrieveCourseTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.retrieveCourse(dept,courseId1)); + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), rc.retrieveCourse(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>(coursesMapping.get(Integer.toString(coms4156)).toString(), HttpStatus.OK), + rc.retrieveCourse(coms,coms4156)); + } + + @Test + public void isCourseFullTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), rc.isCourseFull(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>(false, HttpStatus.OK), + rc.isCourseFull(coms,coms4156)); + } + + @Test + public void getMajorCtFromDeptTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.getMajorCtFromDept(dept)); + assertEquals(new ResponseEntity<>("There are: " + Integer.toString(departmentMapping + .get(coms).getNumberOfMajors()) + " majors in the department", HttpStatus.OK),rc.getMajorCtFromDept(coms)); + } + + @Test + public void identifyDeptChairTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.identifyDeptChair(dept)); + assertEquals(new ResponseEntity<>("Luca Carloni" + " is " + + "the department chair.", HttpStatus.OK),rc.identifyDeptChair(coms)); + } + + @Test + public void findCourseLocationTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseLocation(dept,courseId1)); + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseLocation(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("501 NWC" + " is where the course " + + "is located.", HttpStatus.OK), + rc.findCourseLocation(coms,coms4156)); + } + + @Test + public void findCourseInstructorTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseInstructor(dept,courseId1)); + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseInstructor(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Gail Kaiser" + + " is the instructor for the course.", HttpStatus.OK), + rc.findCourseInstructor(coms,coms4156)); + } + + @Test + public void findCourseTimeTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseTime(dept,courseId1)); + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.findCourseTime(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("The course meets at: " + "10:10-11:25", HttpStatus.OK), + rc.findCourseTime(coms,coms4156)); + } + + @Test + public void addMajorToDeptTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.addMajorToDept(dept)); + assertEquals(new ResponseEntity<>("Attribute was updated successfully", HttpStatus.OK), + rc.addMajorToDept(coms)); + } + + @Test + public void removeMajorFromDeptTest() { + assertEquals(new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND), rc.removeMajorFromDept(dept)); + assertEquals(new ResponseEntity<>("Attribute was updated or is at minimum", HttpStatus.OK), + rc.removeMajorFromDept(coms)); + } + + @Test + public void dropStudentTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.dropStudent(dept,courseId1)); + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.dropStudent(coms,courseId1)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Student has been dropped.", HttpStatus.OK), + rc.dropStudent(coms,coms4156)); + } + + @Test + public void setEnrollmentCountTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.setEnrollmentCount(dept,courseId1,100)); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK), + rc.setEnrollmentCount(coms,coms4156,10)); + rc.setEnrollmentCount(coms,coms4156,109); + } + + @Test + public void changeCourseTimeTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.changeCourseTime(dept,courseId1,"10:10-11:25")); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK), + rc.changeCourseTime(coms,coms4156,"9:10-10:25")); + rc.changeCourseTime(coms,coms4156,"10:10-11:25"); + } + + @Test + public void changeCourseTeacherTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.changeCourseTeacher(dept,courseId1,"TA")); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK), + rc.changeCourseTeacher(coms,coms4156,"TA")); + rc.changeCourseTeacher(coms,coms4156,"Gail Kaiser"); + } + + @Test + public void changeCourseLocationTest() { + assertEquals(new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND), + rc.changeCourseLocation(dept,courseId1,"Online")); + coursesMapping = departmentMapping.get(coms.toUpperCase()).getCourseSelection(); + assertEquals(new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK), + rc.changeCourseLocation(coms,coms4156,"Online")); + rc.changeCourseLocation(coms,coms4156,"501 NWC"); + } + + + + /** The test instance used for testing. */ + public static RouteController rc; + public static HashMap departmentMapping; + public static HashMap coursesMapping; + public static String dept; + public static int courseId1; + public static String coms; + public static int coms4156; +} diff --git a/data.txt b/data.txt new file mode 100644 index 00000000..fafc4f3b Binary files /dev/null and b/data.txt differ