diff --git a/IndividualProject/data.txt b/IndividualProject/data.txt
new file mode 100644
index 00000000..99f11c15
Binary files /dev/null and b/IndividualProject/data.txt differ
diff --git a/IndividualProject/pom.xml b/IndividualProject/pom.xml
index 6d87d4c9..7a9a17ac 100644
--- a/IndividualProject/pom.xml
+++ b/IndividualProject/pom.xml
@@ -27,6 +27,12 @@
spring-boot-starter-test
test
+
+
+ org.mockito
+ mockito-core
+ test
+
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 6b76c1a7..343d6742 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java
@@ -61,12 +61,33 @@ public String getCourseTimeSlot() {
return this.courseTimeSlot;
}
+ public int getEnrolledStudentCount() {
+ return this.enrolledStudentCount;
+ }
+
public String toString() {
return "\nInstructor: " + instructorName + "; Location: "
+ courseLocation + "; Time: " + courseTimeSlot;
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ Course course = (Course) obj;
+ return this.courseLocation.equals(course.getCourseLocation()) &&
+ this.courseTimeSlot.equals(course.getCourseTimeSlot()) &&
+ this.enrolledStudentCount == course.getEnrolledStudentCount() &&
+ this.instructorName.equals(course.getInstructorName()) &&
+ this.enrollmentCapacity == course.getEnrolledStudentCount();
+ }
public void reassignInstructor(String newInstructorName) {
this.instructorName = newInstructorName;
@@ -87,11 +108,11 @@ public void setEnrolledStudentCount(int count) {
this.enrolledStudentCount = count;
}
-
public boolean isCourseFull() {
return enrollmentCapacity > enrolledStudentCount;
}
+
@Serial
private static final long serialVersionUID = 123456L;
private final int enrollmentCapacity;
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 c98ee691..8efca3ad 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java
@@ -110,6 +110,20 @@ public String toString() {
return "result.toString()";
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ Department dept = (Department) obj;
+ return this.toString().equals(dept.toString());
+ }
+
@Serial
private static final long serialVersionUID = 234567L;
private HashMap courses;
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 717814e9..0e7cb775 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java
@@ -296,7 +296,6 @@ public void onTermination() {
}
}
-
//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 c227304e..b4adcf27 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java
@@ -543,7 +543,7 @@ public ResponseEntity> changeCourseLocation(@RequestParam(value = "deptCode")
private ResponseEntity> handleException(Exception e) {
System.out.println(e.toString());
- return new ResponseEntity<>("An Error has occurred", HttpStatus.OK);
+ return new ResponseEntity<>("An Error has occurred", HttpStatus.INTERNAL_SERVER_ERROR);
}
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 b79969ec..1d0cb886 100644
--- a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java
@@ -1,25 +1,54 @@
package dev.coms4156.project.individualproject;
import static org.junit.jupiter.api.Assertions.assertEquals;
-
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
-
/**
- * This class contains unit tests for the course class.
+ * This class contains unit tests for the Course class.
*/
@SpringBootTest
@ContextConfiguration
public class CourseUnitTests {
-
- @BeforeAll
- public static void setupCourseForTesting() {
+ @BeforeEach
+ public void setupCourseForTesting() {
testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
}
+ @Test
+ public void getEnrolledStudentCountTest(){
+ assertEquals(0, testCourse.getEnrolledStudentCount());
+ }
+
+ @Test
+ public void enrollStudentTest() {
+ testCourse.enrollStudent();
+ assertEquals(1, testCourse.getEnrolledStudentCount());
+ }
+
+ @Test
+ public void enrollFailTest() {
+ testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 0);
+ testCourse.enrollStudent();
+ assertEquals(0, testCourse.getEnrolledStudentCount());
+ }
+
+ @Test
+ public void setEnrolledStudentCountTest() {
+ testCourse.setEnrolledStudentCount(10);
+ assertEquals(10, testCourse.getEnrolledStudentCount());
+ }
+
+ @Test
+ public void setEnrolledStudentCountFailTest() {
+ testCourse.setEnrolledStudentCount(251);
+ assertEquals(0, testCourse.getEnrolledStudentCount());
+ }
@Test
public void toStringTest() {
@@ -27,6 +56,60 @@ public void toStringTest() {
assertEquals(expectedResult, testCourse.toString());
}
+ @Test
+ public void getCourseLocationTest() {
+ String expectedResult = "417 IAB";
+ assertEquals(expectedResult, testCourse.getCourseLocation());
+ }
+
+ @Test
+ public void getCourseTimeSlotTest() {
+ String expectedResult = "11:40-12:55";
+ assertEquals(expectedResult, testCourse.getCourseTimeSlot());
+ }
+
+ @Test
+ public void getInstructorNameTest() {
+ String expectedResult = "Griffin Newbold";
+ assertEquals(expectedResult, testCourse.getInstructorName());
+ }
+
+ @Test
+ public void reassignInstructorTest() {
+ testCourse.reassignInstructor("Suwei Ma");
+ assertEquals("Suwei Ma", testCourse.getInstructorName());
+ }
+
+ @Test
+ public void reassignLocationTest() {
+ testCourse.reassignLocation("418 IAB");
+ assertEquals("418 IAB", testCourse.getCourseLocation());
+ }
+
+ @Test
+ public void reassignTimeTest() {
+ testCourse.reassignTime("11:50-1:05");
+ assertEquals("11:50-1.05", testCourse.getCourseTimeSlot());
+ }
+
+ @Test
+ public void isCourseFullTest() {
+ testCourse.setEnrolledStudentCount(250);
+ assertTrue(testCourse.isCourseFull());
+ }
+
+ @Test
+ public void CourseNotFullTest() {
+ testCourse.setEnrolledStudentCount(0);
+ assertFalse(testCourse.isCourseFull());
+ }
+
+ @Test
+ public void equalsTest() {
+ Course testCourse_new = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
+ testCourse_new.setEnrolledStudentCount(1);
+ assertEquals(testCourse, testCourse_new);
+ }
/** 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..8d324803
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java
@@ -0,0 +1,86 @@
+package dev.coms4156.project.individualproject;
+
+import java.util.HashMap;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+
+
+/**
+ * This class contains unit tests for the Department class.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class DepartmentUnitTests {
+
+ @BeforeEach
+ public void setupDepartmentForTesting() {
+ Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
+ HashMap courses = new HashMap<>();
+ courses.put("4118", coms4118);
+ testDepartment = new Department("COMS", courses, "Department Chair", 2);
+ }
+
+ @Test
+ public void getNumberOfMajorsTest() {
+ assertEquals(2, testDepartment.getNumberOfMajors());
+ }
+
+ @Test
+ public void getDepartmentChairTest() {
+ assertEquals("Department Chair", testDepartment.getDepartmentChair());
+ }
+
+ @Test
+ public void getCourseSelectionTest() {
+ Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
+ HashMap courses = new HashMap<>();
+ courses.put("4118", coms4118);
+ assertEquals(courses, testDepartment.getCourseSelection());
+ }
+
+ @Test
+ public void addPersonToMajorTest() {
+ testDepartment.addPersonToMajor();
+ assertEquals(3, testDepartment.getNumberOfMajors());
+ }
+
+ @Test
+ public void dropPersonFromMajorTest() {
+ testDepartment.dropPersonFromMajor();
+ assertEquals(1, testDepartment.getNumberOfMajors());
+ }
+
+ @Test
+ public void createCourseTest() {
+ testDepartment.createCourse("4156", "Gail Kaizer", "Remote", "10:10-11:25", 50);
+ HashMap courses = testDepartment.getCourseSelection();
+ Course testCourse = new Course("Gail Kaizer", "Remote", "10:10-11:25", 50);
+ assertEquals(courses.get("COMS4156"), testCourse);
+ }
+
+ @Test
+ public void toStringTest() {
+ Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
+ String str = "4118 :" + coms4118.toString() + "\n";
+ assertEquals(str, testDepartment.toString());
+ }
+
+ @Test
+ public void equalsTest(){
+ Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
+ HashMap courses = new HashMap<>();
+ courses.put("4118", coms4118);
+ Department testEquals = new Department("COMS", courses, "Department Chair", 2);
+ assertEquals(testDepartment, testEquals);
+ }
+
+ /** The test department instance used for testing. */
+ public static Department testDepartment;
+}
+
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationUnitTests.java
new file mode 100644
index 00000000..a1bf7132
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationUnitTests.java
@@ -0,0 +1,297 @@
+package dev.coms4156.project.individualproject;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+
+/**
+ * This class contains unit tests for the IndividualProjectApplication class.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class IndividualProjectApplicationUnitTests {
+
+ @BeforeAll
+ public static void setupBeforeTests() {
+ 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);
+ mapping = new HashMap<>();
+ mapping.put("COMS", compSci);
+ mapping_small = new HashMap<>();
+ mapping_small.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);
+ }
+
+ @Test
+ public void checkRunSetup() {
+ IndividualProjectApplication ipa = new IndividualProjectApplication();
+ String[] setuparray = {"setup"};
+ ipa.run(setuparray);
+ assertEquals(IndividualProjectApplication.myFileDatabase.getDepartmentMapping(), mapping);
+ }
+
+ @Test
+ public void checkMainAndRunEmpty() {
+ String[] emptyarray = {};
+ IndividualProjectApplication.main(emptyarray);
+ assertEquals(IndividualProjectApplication.myFileDatabase.getDepartmentMapping(), mapping);
+ }
+
+ @Test
+ public void checkOverrideDatabase() {
+ MyFileDatabase testDatabase = new MyFileDatabase(1, "./temp.txt");
+ testDatabase.setMapping(mapping_small);
+ IndividualProjectApplication.overrideDatabase(testDatabase);
+ assertEquals(IndividualProjectApplication.myFileDatabase.getDepartmentMapping(), mapping_small);
+ }
+
+ @Test
+ public void checkOnTerminate() {
+ IndividualProjectApplication ipa = new IndividualProjectApplication();
+ Object obj = null;
+ MyFileDatabase testDatabase = new MyFileDatabase(1, "./temp.txt");
+ testDatabase.setMapping(mapping_small);
+ IndividualProjectApplication.overrideDatabase(testDatabase);
+ ipa.onTermination();
+ try (ObjectInputStream in = new ObjectInputStream(new FileInputStream("./temp.txt"))) {
+ obj = in.readObject();
+ if (!(obj instanceof HashMap)) {
+ fail();
+ }
+ } catch (IOException | ClassNotFoundException e) {
+ fail();
+ }
+ assertEquals(IndividualProjectApplication.myFileDatabase.getDepartmentMapping(), obj);
+ }
+
+ public static HashMap mapping;
+ public static HashMap mapping_small;
+}
+
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java
new file mode 100644
index 00000000..e51c3656
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java
@@ -0,0 +1,288 @@
+package dev.coms4156.project.individualproject;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+
+
+/**
+ * This class contains unit tests for the MyFileDatabase class.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class MyFileDatabaseUnitTests {
+ @BeforeEach
+ public void setupDatabaseForTesting() {
+ testDatabase = new MyFileDatabase(0, "./data.txt");
+ 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);
+ 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);
+ }
+
+ @Test
+ public void deSerializeObjectFromFileTest() {
+ assertEquals(mapping, testDatabase.getDepartmentMapping());
+ }
+
+ @Test
+ public void toStringTest() {
+ StringBuilder result = new StringBuilder();
+ for (Map.Entry entry : mapping.entrySet()) {
+ String key = entry.getKey();
+ Department value = entry.getValue();
+ result.append("For the ").append(key).append(" department: \n").append(value.toString());
+ }
+ assertEquals(result.toString(), testDatabase.toString());
+ }
+
+ @Test
+ public void setMappingTest() {
+ HashMap tempmapping = new HashMap<>();
+ HashMap courses = new HashMap<>();
+ Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200);
+ courses.put("1001", psyc1001);
+ Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437);
+ tempmapping.put("PSYC", psyc);
+ testDatabase.setMapping(tempmapping);
+ assertEquals(tempmapping, testDatabase.getDepartmentMapping());
+ }
+
+ @Test
+ public void saveContentsToFileTest() {
+ testDatabase = new MyFileDatabase(1, "./test_data.txt");
+ testDatabase.setMapping(mapping);
+ testDatabase.saveContentsToFile();
+ testDatabase.deSerializeObjectFromFile();
+ assertEquals(mapping, testDatabase.getDepartmentMapping());
+ }
+
+
+ /** The test department instance used for testing and reference mapping. */
+ public static MyFileDatabase testDatabase;
+ public static HashMap mapping;
+}
+
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java
new file mode 100644
index 00000000..d46a843a
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java
@@ -0,0 +1,459 @@
+package dev.coms4156.project.individualproject;
+
+import java.util.HashMap;
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.mockito.Mockito.when;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+
+/**
+ * This class contains unit tests for the RouteController class.
+ */
+@WebMvcTest(RouteController.class)
+@AutoConfigureMockMvc
+public class RouteControllerUnitTests {
+ public static MyFileDatabase realDatabase;
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ public MyFileDatabase testDatabase;
+ public HashMap testMapping;
+
+ @BeforeAll
+ public static void saveRealDatabase() {
+ realDatabase = IndividualProjectApplication.myFileDatabase; //we need to save this reference
+ }
+
+ @AfterAll
+ public static void loadRealDatabase() {
+ IndividualProjectApplication.myFileDatabase = realDatabase; //so that we can load it here once testing is over
+ }
+
+ @BeforeEach
+ public void setupTestDatabases() {
+ 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);
+ testMapping = new HashMap<>();
+ testMapping.put("COMS", compSci);
+ testDatabase.setMapping(testMapping);
+ IndividualProjectApplication.myFileDatabase = testDatabase;
+ }
+
+ @Test
+ public void WelcomeTestSlash() throws Exception {
+ mockMvc.perform(get("/")).andExpect(status().isOk())
+ .andExpect(content().string("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"));
+ }
+
+ @Test
+ public void WelcomeTestIndex() throws Exception {
+ mockMvc.perform(get("/index")).andExpect(status().isOk())
+ .andExpect(content().string("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"));
+ }
+
+ @Test
+ public void WelcomeTestHome() throws Exception {
+ mockMvc.perform(get("/home")).andExpect(status().isOk())
+ .andExpect(content().string("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"));
+ }
+
+ @Test
+ public void retrieveDeptTest() throws Exception {
+ 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);
+ mockMvc.perform(get("/retrieveDept")
+ .param("deptCode", "COMS")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(compSci.toString()));
+ }
+
+ @Test
+ public void retrieveDeptTestFail() throws Exception {
+ mockMvc.perform(get("/retrieveDept")
+ .param("deptCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void retrieveCourseTest() throws Exception {
+ 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);
+ mockMvc.perform(get("/retrieveCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(coms1004.toString()));
+ }
+
+ @Test
+ public void retrieveCourseTestFailCourse() throws Exception {
+ mockMvc.perform(get("/retrieveCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void retrieveCourseTestFailDept() throws Exception {
+ mockMvc.perform(get("/retrieveCourse")
+ .param("deptCode", "404")
+ .param("courseCode", "NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void courseFullTest() throws Exception {
+ mockMvc.perform(get("/isCourseFull")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("false"));
+ }
+
+ @Test
+ public void courseFullTestFail() throws Exception {
+ mockMvc.perform(get("/isCourseFull")
+ .param("deptCode", "404")
+ .param("courseCode", "NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void getMajorCtFromDeptTest() throws Exception {
+ mockMvc.perform(get("/getMajorCountFromDept")
+ .param("deptCode", "COMS")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("There are 2700 majors in the department"));
+ }
+
+ @Test
+ public void getMajorCtFromDeptTestFail() throws Exception {
+ mockMvc.perform(get("/getMajorCountFromDept")
+ .param("deptCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void identifyDeptChairTest() throws Exception {
+ mockMvc.perform(get("/idDeptChair")
+ .param("deptCode", "COMS")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Luca Carloni is the department chair."));
+ }
+
+ @Test
+ public void identifyDeptChairTestFail() throws Exception {
+ mockMvc.perform(get("/idDeptChair")
+ .param("deptCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void findCourseLocationTest() throws Exception {
+ mockMvc.perform(get("/findCourseLocation")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("417 IAB is where the course is located."));
+ }
+
+ @Test
+ public void findCourseLocationTestFail() throws Exception {
+ mockMvc.perform(get("/findCourseLocation")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void findCourseInstructorTest() throws Exception {
+ mockMvc.perform(get("/findCourseInstructor")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Adam Cannon is the instructor for the course."));
+ }
+
+ @Test
+ public void findCourseInstructorTestFail() throws Exception {
+ mockMvc.perform(get("/findCourseInstructor")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void findCourseTimeTest() throws Exception {
+ mockMvc.perform(get("/findCourseTime")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("The course meets at 11:40-12:55."));
+ }
+
+ @Test
+ public void findCourseTimeTestFail() throws Exception {
+ mockMvc.perform(get("/findCourseTime")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void addMajorToDeptTest() throws Exception {
+ mockMvc.perform(get("/addMajorToDept")
+ .param("deptCode", "COMS")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attribute was updated successfully"));
+ }
+
+ @Test
+ public void addMajorToDeptTestFail() throws Exception {
+ mockMvc.perform(get("/addMajorToDept")
+ .param("deptCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void removeMajorFromDeptTest() throws Exception {
+ mockMvc.perform(get("/removeMajorFromDept")
+ .param("deptCode", "COMS")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attribute was updated or is at minimum"));
+ }
+
+ @Test
+ public void removeMajorFromDeptTestFail() throws Exception {
+ mockMvc.perform(get("/removeMajorFromDept")
+ .param("deptCode", "404NotFound")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void dropStudentFromCourseTest() throws Exception {
+ mockMvc.perform(get("/dropStudentFromCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Student has been dropped."));
+ }
+
+ @Test
+ public void dropStudentFromCourseTestFail() throws Exception {
+ Course testCourse = testMapping.get("COMS").getCourseSelection().get("1004");
+ testCourse.setEnrolledStudentCount(0);
+ mockMvc.perform(get("/dropStudentFromCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isBadRequest())
+ .andExpect(content().string("Student has not been dropped."));
+ }
+
+ @Test
+ public void dropStudentFromCourseTestFail404() throws Exception {
+ mockMvc.perform(get("/dropStudentFromCourse")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found."));
+ }
+
+ @Test
+ public void setEnrollmentCountTest() throws Exception {
+ mockMvc.perform(get("/setEnrollmentCount")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .param("count", "100")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attributed was updated successfully."));
+ }
+
+ @Test
+ public void setEnrollmentCountTestFail() throws Exception {
+ mockMvc.perform(get("/setEnrollmentCount")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .param("count", "100")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found."));
+ }
+
+ @Test
+ public void changeCourseTeacherTest() throws Exception {
+ mockMvc.perform(get("/changeCourseTeacher")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .param("teacher", "Suwei Ma")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attributed was updated successfully."));
+ }
+
+ @Test
+ public void changeCourseTeacherTestFail() throws Exception {
+ mockMvc.perform(get("/changeCourseTeacher")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .param("teacher", "Suwei Ma")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found."));
+ }
+
+ @Test
+ public void changeCourseLocationTest() throws Exception {
+ mockMvc.perform(get("/changeCourseTeacher")
+ .param("deptCode", "COMS")
+ .param("courseCode", "1004")
+ .param("teacher", "418 IAB")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attributed was updated successfully."));
+ }
+
+ @Test
+ public void changeCourseLocationTestFail() throws Exception {
+ mockMvc.perform(get("/changeCourseTeacher")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .param("teacher", "418 IAB")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found."));
+ }
+
+ @Test
+ public void handleExceptionTest() throws Exception {
+ when(testDatabase.getDepartmentMapping()).thenThrow(new RuntimeException("TestException"));
+ mockMvc.perform(get("/changeCourseTeacher")
+ .param("deptCode", "404")
+ .param("courseCode", "Not Found")
+ .param("teacher", "Suwei Ma")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isInternalServerError())
+ .andExpect(content().string("An Error has occurred"));
+ }
+}
+