public void testCreateCourse() throws Exception { /*Explanation: * The SUT (i.e. CoursesLogic::createCourse) has only 1 path. Therefore, we * should typically have 1 test cases here. */ ______TS("typical case"); CourseAttributes c = new CourseAttributes(); c.id = "Computing101-fresh"; c.name = "Basic Computing"; coursesLogic.createCourse(c.id, c.name); TestHelper.verifyPresentInDatastore(c); coursesLogic.deleteCourseCascade(c.id); ______TS("Null parameter"); try { coursesLogic.createCourse(null, c.name); signalFailureToDetectException(); } catch (AssertionError e) { assertEquals("Non-null value expected", e.getMessage()); } }
public void testGetCoursesSummaryWithoutStatsForInstructor() throws Exception { ______TS("Typical case"); HashMap<String, CourseSummaryBundle> courseListForInstructor = coursesLogic.getCoursesSummaryWithoutStatsForInstructor("idOfInstructor3"); assertEquals(2, courseListForInstructor.size()); String course1Id = "idOfTypicalCourse1"; // course with 2 evaluations ArrayList<EvaluationAttributes> course1Evals = courseListForInstructor.get(course1Id).evaluations; String course1EvalsAttributes = ""; for (EvaluationAttributes evalAttr : course1Evals) { course1EvalsAttributes = course1EvalsAttributes + Utils.getTeammatesGson().toJson(evalAttr) + Const.EOL; } int numberOfEvalsInCourse1 = course1Evals.size(); assertEquals(course1EvalsAttributes, 2, numberOfEvalsInCourse1); assertEquals(course1Id, course1Evals.get(0).courseId); TestHelper.verifyEvaluationInfoExistsInAttributeList( dataBundle.evaluations.get("evaluation1InCourse1"), course1Evals); TestHelper.verifyEvaluationInfoExistsInAttributeList( dataBundle.evaluations.get("evaluation2InCourse1"), course1Evals); // course with 1 evaluation assertEquals(course1Id, course1Evals.get(1).courseId); ArrayList<EvaluationAttributes> course2Evals = courseListForInstructor.get("idOfTypicalCourse2").evaluations; assertEquals(1, course2Evals.size()); TestHelper.verifyEvaluationInfoExistsInAttributeList( dataBundle.evaluations.get("evaluation1InCourse2"), course2Evals); ______TS("Instructor has a course with 0 evaluations"); courseListForInstructor = coursesLogic.getCoursesSummaryWithoutStatsForInstructor("idOfInstructor4"); assertEquals(1, courseListForInstructor.size()); assertEquals(0, courseListForInstructor.get("idOfCourseNoEvals").evaluations.size()); ______TS("Instructor with 0 courses"); courseListForInstructor = coursesLogic.getCoursesSummaryWithoutStatsForInstructor("instructorWithoutCourses"); assertEquals(0, courseListForInstructor.size()); ______TS("Non-existent instructor"); try { coursesLogic.getCoursesSummaryWithoutStatsForInstructor("non-existent-instructor"); signalFailureToDetectException(); } catch (EntityDoesNotExistException e) { AssertHelper.assertContains("does not exist", e.getMessage()); } ______TS("Null parameter"); try { coursesLogic.getCoursesSummaryWithoutStatsForInstructor(null); signalFailureToDetectException(); } catch (AssertionError e) { assertEquals("Supplied parameter was null\n", e.getMessage()); } }
public void testGetCourseDetailsListForStudent() throws Exception { ______TS("student having multiple evaluations in multiple courses"); CourseAttributes expectedCourse1 = dataBundle.courses.get("typicalCourse1"); CourseAttributes expectedCourse2 = dataBundle.courses.get("typicalCourse2"); EvaluationAttributes expectedEval1InCourse1 = dataBundle.evaluations.get("evaluation1InCourse1"); EvaluationAttributes expectedEval2InCourse1 = dataBundle.evaluations.get("evaluation2InCourse1"); EvaluationAttributes expectedEval1InCourse2 = dataBundle.evaluations.get("evaluation1InCourse2"); // This student is in both course 1 and 2 StudentAttributes studentInBothCourses = dataBundle.students.get("student2InCourse1"); // Make sure all evaluations in course1 are visible (i.e., not AWAITING) expectedEval1InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-2); expectedEval1InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(-1); expectedEval1InCourse1.published = false; assertEquals(EvalStatus.CLOSED, expectedEval1InCourse1.getStatus()); BackDoorLogic backDoorLogic = new BackDoorLogic(); backDoorLogic.updateEvaluation(expectedEval1InCourse1); expectedEval2InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-1); expectedEval2InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(1); assertEquals(EvalStatus.OPEN, expectedEval2InCourse1.getStatus()); backDoorLogic.updateEvaluation(expectedEval2InCourse1); // Make sure all evaluations in course2 are still AWAITING expectedEval1InCourse2.startTime = TimeHelper.getDateOffsetToCurrentTime(1); expectedEval1InCourse2.endTime = TimeHelper.getDateOffsetToCurrentTime(2); expectedEval1InCourse2.activated = false; assertEquals(EvalStatus.AWAITING, expectedEval1InCourse2.getStatus()); backDoorLogic.updateEvaluation(expectedEval1InCourse2); // Get course details for student List<CourseDetailsBundle> courseList = coursesLogic.getCourseDetailsListForStudent(studentInBothCourses.googleId); // Verify number of courses received assertEquals(2, courseList.size()); // Verify details of course 1 (note: index of course 1 is not 0) CourseDetailsBundle actualCourse1 = courseList.get(1); assertEquals(expectedCourse1.id, actualCourse1.course.id); assertEquals(expectedCourse1.name, actualCourse1.course.name); assertEquals(2, actualCourse1.evaluations.size()); // Verify details of evaluation 1 in course 1 EvaluationAttributes actualEval1InCourse1 = actualCourse1.evaluations.get(1).evaluation; TestHelper.verifySameEvaluationData(expectedEval1InCourse1, actualEval1InCourse1); // Verify some details of evaluation 2 in course 1 EvaluationAttributes actualEval2InCourse1 = actualCourse1.evaluations.get(0).evaluation; TestHelper.verifySameEvaluationData(expectedEval2InCourse1, actualEval2InCourse1); // For course 2, verify no evaluations returned (because the evaluation // in this course is still AWAITING. CourseDetailsBundle actualCourse2 = courseList.get(0); assertEquals(expectedCourse2.id, actualCourse2.course.id); assertEquals(expectedCourse2.name, actualCourse2.course.name); assertEquals(0, actualCourse2.evaluations.size()); ______TS("student in a course with no evaluations"); StudentAttributes studentWithNoEvaluations = dataBundle.students.get("student1InCourse2"); courseList = coursesLogic.getCourseDetailsListForStudent(studentWithNoEvaluations.googleId); assertEquals(1, courseList.size()); assertEquals(0, courseList.get(0).evaluations.size()); // student with no courses is not applicable ______TS("non-existent student"); try { coursesLogic.getCourseDetailsListForStudent("non-existent-student"); signalFailureToDetectException(); } catch (EntityDoesNotExistException e) { AssertHelper.assertContains("does not exist", e.getMessage()); } ______TS("null parameter"); try { coursesLogic.getCourseDetailsListForStudent(null); signalFailureToDetectException(); } catch (AssertionError e) { assertEquals("Supplied parameter was null\n", e.getMessage()); } }
public void testDeleteCourse() throws Exception { ______TS("typical case"); CourseAttributes course1OfInstructor = dataBundle.courses.get("typicalCourse1"); StudentAttributes studentInCourse = dataBundle.students.get("student1InCourse1"); // Ensure there are entities in the datastore under this course assertTrue(StudentsLogic.inst().getStudentsForCourse(course1OfInstructor.id).size() != 0); TestHelper.verifyPresentInDatastore(course1OfInstructor); TestHelper.verifyPresentInDatastore(studentInCourse); TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor1OfCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor3OfCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.students.get("student1InCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.students.get("student5InCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1")); TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1")); assertEquals(course1OfInstructor.id, studentInCourse.course); coursesLogic.deleteCourseCascade(course1OfInstructor.id); // Ensure the course and related entities are deleted TestHelper.verifyAbsentInDatastore(course1OfInstructor); TestHelper.verifyAbsentInDatastore(studentInCourse); TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor1OfCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor3OfCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student1InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student5InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1")); TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI1C1toS1C1")); TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment2FromI1C1toS1C1")); TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI3C1toS2C1")); ArrayList<SubmissionAttributes> submissionsOfCourse = new ArrayList<SubmissionAttributes>(dataBundle.submissions.values()); for (SubmissionAttributes s : submissionsOfCourse) { if (s.course.equals(course1OfInstructor.id)) { TestHelper.verifyAbsentInDatastore(s); } } ______TS("non-existent"); // try to delete again. Should fail silently. coursesLogic.deleteCourseCascade(course1OfInstructor.id); ______TS("null parameter"); try { coursesLogic.deleteCourseCascade(null); signalFailureToDetectException(); } catch (AssertionError e) { assertEquals("Supplied parameter was null\n", e.getMessage()); } }
public void testCreateCourseAndInstructor() throws Exception { /* Explanation: SUT has 5 paths. They are, * path 1 - exit because the account doesn't' exist. * path 2 - exit because the account exists but doesn't have instructor privileges. * path 3 - exit because course creation failed. * path 4 - exit because instructor creation failed. * path 5 - success. * Accordingly, we have 5 test cases. */ ______TS("fails: account doesn't exist"); CourseAttributes c = new CourseAttributes(); c.id = "fresh-course-tccai"; c.name = "Fresh course for tccai"; @SuppressWarnings("deprecation") InstructorAttributes i = new InstructorAttributes( "instructor-for-tccai", c.id, "Instructor for tccai", "*****@*****.**"); try { coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); signalFailureToDetectException(); } catch (AssertionError e) { AssertHelper.assertContains("for a non-existent instructor", e.getMessage()); } TestHelper.verifyAbsentInDatastore(c); TestHelper.verifyAbsentInDatastore(i); ______TS("fails: account doesn't have instructor privileges"); AccountAttributes a = new AccountAttributes(); a.googleId = i.googleId; a.name = i.name; a.email = i.email; a.institute = "TEAMMATES Test Institute 5"; a.isInstructor = false; a.studentProfile = new StudentProfileAttributes(); a.studentProfile.googleId = i.googleId; accountsDb.createAccount(a); try { coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); signalFailureToDetectException(); } catch (AssertionError e) { AssertHelper.assertContains("doesn't have instructor privileges", e.getMessage()); } TestHelper.verifyAbsentInDatastore(c); TestHelper.verifyAbsentInDatastore(i); ______TS("fails: error during course creation"); a.isInstructor = true; accountsDb.updateAccount(a); c.id = "invalid id"; try { coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); signalFailureToDetectException(); } catch (InvalidParametersException e) { AssertHelper.assertContains("not acceptable to TEAMMATES as a Course ID", e.getMessage()); } TestHelper.verifyAbsentInDatastore(c); TestHelper.verifyAbsentInDatastore(i); ______TS("fails: error during instructor creation due to duplicate instructor"); c.id = "fresh-course-tccai"; instructorsDb.createEntity(i); // create a duplicate instructor try { coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); signalFailureToDetectException(); } catch (AssertionError e) { AssertHelper.assertContains( "Unexpected exception while trying to create instructor for a new course", e.getMessage()); } TestHelper.verifyAbsentInDatastore(c); ______TS("fails: error during instructor creation due to invalid parameters"); i.email = "ins.for.iccai.gmail.tmt"; try { coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); signalFailureToDetectException(); } catch (AssertionError e) { AssertHelper.assertContains( "Unexpected exception while trying to create instructor for a new course", e.getMessage()); } TestHelper.verifyAbsentInDatastore(c); ______TS("success: typical case"); i.email = "*****@*****.**"; // remove the duplicate instructor object from the datastore. instructorsDb.deleteInstructor(i.courseId, i.email); coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name); TestHelper.verifyPresentInDatastore(c); TestHelper.verifyPresentInDatastore(i); ______TS("Null parameter"); try { coursesLogic.createCourseAndInstructor(null, c.id, c.name); signalFailureToDetectException(); } catch (AssertionError e) { assertEquals("Supplied parameter was null\n", e.getMessage()); } }