Search in sources :

Example 51 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class StudentsLogicTest method testEnrollStudents.

private void testEnrollStudents() throws Exception {
    String instructorId = "instructorForEnrollTesting";
    String courseIdForEnrollTest = "courseForEnrollTest";
    String instructorEmail = "instructor@email.tmt";
    StudentProfileAttributes profileAttributes = StudentProfileAttributes.builder(instructorId).withShortName("Ins1").withGender("male").build();
    AccountAttributes accountToAdd = AccountAttributes.builder().withGoogleId(instructorId).withName("Instructor 1").withEmail(instructorEmail).withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(profileAttributes).build();
    accountsLogic.createAccount(accountToAdd);
    coursesLogic.createCourseAndInstructor(instructorId, courseIdForEnrollTest, "Course for Enroll Testing", "UTC");
    FeedbackSessionsLogic fsLogic = FeedbackSessionsLogic.inst();
    FeedbackSessionAttributes fsAttr = FeedbackSessionAttributes.builder("newFeedbackSessionName", courseIdForEnrollTest, instructorEmail).withInstructions(new Text("default instructions")).withCreatedTime(Instant.now()).withStartTime(TimeHelperExtension.getInstantHoursOffsetFromNow(2)).withEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(5)).withSessionVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(1)).withResultsVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(6)).withTimeZone(ZoneId.of("Asia/Singapore")).withGracePeriodMinutes(0).withFeedbackSessionType(FeedbackSessionType.PRIVATE).withOpeningEmailEnabled(false).withClosingEmailEnabled(false).withPublishedEmailEnabled(false).build();
    fsLogic.createFeedbackSession(fsAttr);
    ______TS("all valid students, but contains blank lines and trailing spaces");
    String headerLine = "team | name | email | comment";
    String line0 = "t1   |  n1   |   e1@g  |   c1";
    String line1 = " t2|  n2|  e2@g|  c2";
    String line2 = "\u00A0t3  |n3|  e3@g|c3  ";
    String line3 = "t4|n4|  e4@g|c4";
    String line4 = "t5|  n5|e5@g  |c5";
    String lines = headerLine + System.lineSeparator() + line0 + System.lineSeparator() + line1 + System.lineSeparator() + line2 + System.lineSeparator() + "  \t \t \t \t           " + System.lineSeparator() + line3 + System.lineSeparator() + System.lineSeparator() + line4 + System.lineSeparator() + "    " + System.lineSeparator() + System.lineSeparator();
    CourseEnrollmentResult enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
    StudentAttributesFactory saf = new StudentAttributesFactory(headerLine);
    assertEquals(5, enrollResults.studentList.size());
    assertEquals(5, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    // Test enroll result
    line0 = "t1|n1|e1@g|c1";
    verifyEnrollmentResultForStudent(saf.makeStudent(line0, courseIdForEnrollTest), enrollResults.studentList.get(0), StudentUpdateStatus.NEW);
    verifyEnrollmentResultForStudent(saf.makeStudent(line1, courseIdForEnrollTest), enrollResults.studentList.get(1), StudentUpdateStatus.NEW);
    verifyEnrollmentResultForStudent(saf.makeStudent(line4, courseIdForEnrollTest), enrollResults.studentList.get(4), StudentUpdateStatus.NEW);
    CourseDetailsBundle courseDetails = coursesLogic.getCourseSummary(courseIdForEnrollTest);
    assertEquals(5, courseDetails.stats.unregisteredTotal);
    ______TS("includes a mix of unmodified, modified, and new");
    String modifiedLine2 = "t3|modified name|e3@g|c3";
    String line5 = "t6|n6|e6@g|c6";
    lines = headerLine + System.lineSeparator() + line0 + System.lineSeparator() + modifiedLine2 + System.lineSeparator() + line1 + System.lineSeparator() + line5;
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
    assertEquals(6, enrollResults.studentList.size());
    assertEquals(6, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    verifyEnrollmentResultForStudent(saf.makeStudent(line0, courseIdForEnrollTest), enrollResults.studentList.get(0), StudentUpdateStatus.UNMODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(modifiedLine2, courseIdForEnrollTest), enrollResults.studentList.get(1), StudentUpdateStatus.MODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(line1, courseIdForEnrollTest), enrollResults.studentList.get(2), StudentUpdateStatus.UNMODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(line5, courseIdForEnrollTest), enrollResults.studentList.get(3), StudentUpdateStatus.NEW);
    assertEquals(StudentUpdateStatus.NOT_IN_ENROLL_LIST, enrollResults.studentList.get(4).updateStatus);
    assertEquals(StudentUpdateStatus.NOT_IN_ENROLL_LIST, enrollResults.studentList.get(5).updateStatus);
    ______TS("includes an incorrect line");
    // no changes should be done to the database
    String incorrectLine = "incorrectly formatted line";
    lines = headerLine + System.lineSeparator() + "t7|n7|e7@g|c7" + System.lineSeparator() + incorrectLine + System.lineSeparator() + line2 + System.lineSeparator() + line3;
    try {
        enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
        signalFailureToDetectException("Did not throw exception for incorrectly formatted line");
    } catch (EnrollException e) {
        assertTrue(e.getMessage().contains(incorrectLine));
    }
    assertEquals(6, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    ______TS("null parameters");
    try {
        studentsLogic.enrollStudentsWithoutDocument("a|b|c|d", null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("same student added, modified and unmodified");
    StudentProfileAttributes studentAttributes = StudentProfileAttributes.builder("tes.instructor").withShortName("Ins 1").withGender("male").build();
    accountToAdd = AccountAttributes.builder().withGoogleId("tes.instructor").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(studentAttributes).build();
    accountsLogic.createAccount(accountToAdd);
    coursesLogic.createCourseAndInstructor("tes.instructor", "tes.course", "TES Course", "UTC");
    String line = headerLine + System.lineSeparator() + "t8|n8|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.NEW, enrollResults.studentList.get(0).updateStatus);
    line = headerLine + System.lineSeparator() + "t8|n8a|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.MODIFIED, enrollResults.studentList.get(0).updateStatus);
    line = headerLine + System.lineSeparator() + "t8|n8a|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.UNMODIFIED, enrollResults.studentList.get(0).updateStatus);
    ______TS("duplicated emails");
    String lineT9 = "t9|n9|e9@g|c9";
    String lineT10 = "t10|n10|e9@g|c10";
    lines = headerLine + System.lineSeparator() + lineT9 + System.lineSeparator() + lineT10;
    try {
        studentsLogic.enrollStudentsWithoutDocument(lines, "tes.course");
    } catch (EnrollException e) {
        assertTrue(e.getMessage().contains(lineT10));
        AssertHelper.assertContains("Same email address as the student in line \"" + lineT9 + "\"", e.getMessage());
    }
    ______TS("invalid course id");
    String enrollLines = headerLine + System.lineSeparator();
    String invalidCourseId = "invalidCourseId";
    try {
        studentsLogic.enrollStudentsWithoutDocument(enrollLines, invalidCourseId);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        ignoreExpectedException();
    }
    ______TS("empty enroll line");
    try {
        studentsLogic.enrollStudentsWithoutDocument("", courseIdForEnrollTest);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        ignoreExpectedException();
    }
    ______TS("invalidity info in enroll line");
    enrollLines = headerLine + System.lineSeparator() + "invalidline0\ninvalidline1\n";
    try {
        studentsLogic.enrollStudentsWithoutDocument(enrollLines, courseIdForEnrollTest);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        ignoreExpectedException();
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EnrollException(teammates.common.exception.EnrollException) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) FeedbackSessionsLogic(teammates.logic.core.FeedbackSessionsLogic) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) Text(com.google.appengine.api.datastore.Text) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 52 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class StudentsLogicTest method testupdateStudentCascadeWithoutDocument.

private void testupdateStudentCascadeWithoutDocument() throws Exception {
    ______TS("typical edit");
    StudentAttributes student4InCourse1 = dataBundle.students.get("student4InCourse1");
    verifyPresentInDatastore(student4InCourse1);
    String originalEmail = student4InCourse1.email;
    student4InCourse1 = studentsLogic.getStudentForEmail(student4InCourse1.course, student4InCourse1.email);
    student4InCourse1.name = student4InCourse1.name + "y";
    student4InCourse1.googleId = student4InCourse1.googleId + "y";
    student4InCourse1.comments = student4InCourse1.comments + "y";
    student4InCourse1.email = student4InCourse1.email + "y";
    student4InCourse1.section = "Section 2";
    // move to a different team
    student4InCourse1.team = "Team 1.2";
    studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, student4InCourse1);
    StudentAttributes updatedStudent4InCourse1 = studentsLogic.getStudentForEmail(student4InCourse1.course, student4InCourse1.email);
    assertFalse(student4InCourse1.getUpdatedAt().equals(updatedStudent4InCourse1.getUpdatedAt()));
    ______TS("check for KeepExistingPolicy : change email only");
    originalEmail = student4InCourse1.email;
    String newEmail = student4InCourse1.email + "y";
    student4InCourse1.email = newEmail;
    // create an empty student and then copy course and email attributes
    StudentAttributes copyOfStudent1 = StudentAttributes.builder(student4InCourse1.course, student4InCourse1.name, newEmail).build();
    student4InCourse1.googleId = "";
    student4InCourse1.section = "None";
    studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
    verifyPresentInDatastore(student4InCourse1);
    ______TS("check for KeepExistingPolicy : change nothing");
    originalEmail = student4InCourse1.email;
    copyOfStudent1.email = null;
    studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
    verifyPresentInDatastore(copyOfStudent1);
    ______TS("non-existent student");
    try {
        studentsLogic.updateStudentCascadeWithoutDocument("non-existent@email", student4InCourse1);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals(StudentsDb.ERROR_UPDATE_NON_EXISTENT_STUDENT + student4InCourse1.course + "/" + "non-existent@email", e.getMessage());
    }
    ______TS("check for InvalidParameters");
    copyOfStudent1.email = "invalid email";
    try {
        studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(FieldValidator.REASON_INCORRECT_FORMAT, e.getMessage());
    }
// delete student from db
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 53 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class StudentsLogicTest method testGetEncryptedKeyForStudent.

private void testGetEncryptedKeyForStudent() throws Exception {
    ______TS("null parameters");
    try {
        studentsLogic.getEncryptedKeyForStudent("valid.course.id", null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("non-existent student");
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    String nonExistStudentEmail = "non@existent";
    try {
        studentsLogic.getEncryptedKeyForStudent(student1InCourse1.course, nonExistStudentEmail);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        String expectedErrorMsg = "Student does not exist: " + "[" + student1InCourse1.course + "/" + nonExistStudentEmail + "]";
        assertEquals(expectedErrorMsg, e.getMessage());
    }
    // the typical case below seems unnecessary though--it is not useful for now
    // as the method itself is too simple
    ______TS("typical case");
    String course1Id = dataBundle.courses.get("typicalCourse1").getId();
    String actualKey = studentsLogic.getEncryptedKeyForStudent(course1Id, student1InCourse1.email);
    String expectedKey = StringHelper.encrypt(studentsLogic.getStudentForCourseIdAndGoogleId(course1Id, student1InCourse1.googleId).key);
    assertEquals(expectedKey, actualKey);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 54 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testGetCourseSummariesForInstructor.

private void testGetCourseSummariesForInstructor() throws Exception {
    ______TS("Instructor with 2 courses");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor3OfCourse1");
    Map<String, CourseDetailsBundle> courseList = coursesLogic.getCourseSummariesForInstructor(instructor.googleId, false);
    assertEquals(2, courseList.size());
    for (CourseDetailsBundle cdd : courseList.values()) {
        // check if course belongs to this instructor
        assertTrue(InstructorsLogic.inst().isGoogleIdOfInstructorOfCourse(instructor.googleId, cdd.course.getId()));
    }
    ______TS("Instructor with 1 archived, 1 unarchived course");
    InstructorsLogic.inst().setArchiveStatusOfInstructor(instructor.googleId, "idOfTypicalCourse1", true);
    courseList = coursesLogic.getCourseSummariesForInstructor(instructor.googleId, true);
    assertEquals(1, courseList.size());
    InstructorsLogic.inst().setArchiveStatusOfInstructor(instructor.googleId, "idOfTypicalCourse1", false);
    ______TS("Instructor with 0 courses");
    courseList = coursesLogic.getCourseSummariesForInstructor("instructorWithoutCourses", false);
    assertEquals(0, courseList.size());
    ______TS("Non-existent instructor");
    try {
        coursesLogic.getCourseSummariesForInstructor("non-existent-instructor", false);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("Null parameter");
    try {
        coursesLogic.getCourseSummariesForInstructor(null, false);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 55 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testGetCourseStudentListAsCsv.

private void testGetCourseStudentListAsCsv() throws Exception {
    ______TS("Typical case: course with section");
    InstructorAttributes instructor1OfCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    String csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    String[] expectedCsvString = { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID,\"idOfTypicalCourse1\"", "Course Name,\"Typical Course 1 with 2 Evals\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student1 In Course1</td></div>'\"\"\",\"Course1</td></div>'\"\"\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expectedCsvString, System.lineSeparator()), csvString);
    ______TS("Typical case: course without sections");
    InstructorAttributes instructor1OfCourse2 = dataBundle.instructors.get("instructor1OfCourse2");
    instructorId = instructor1OfCourse2.googleId;
    courseId = instructor1OfCourse2.courseId;
    csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    expectedCsvString = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID,\"idOfTypicalCourse2\"", "Course Name,\"Typical Course 2 with 1 Evals\"", "", "", "Team,Full Name,Last Name,Status,Email", "\"Team 2.1\",\"student1 In Course2\",\"Course2\",\"Joined\",\"student1InCourse2@gmail.tmt\"", "\"Team 2.1\",\"student2 In Course2\",\"Course2\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expectedCsvString, System.lineSeparator()), csvString);
    ______TS("Typical case: course with unregistered student");
    InstructorAttributes instructor5 = dataBundle.instructors.get("instructor5");
    instructorId = instructor5.googleId;
    courseId = instructor5.courseId;
    csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    expectedCsvString = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID,\"idOfUnregisteredCourse\"", "Course Name,\"Unregistered Course\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1\",\"student1 In unregisteredCourse\",\"unregisteredCourse\",\"Yet to join\",\"student1InUnregisteredCourse@gmail.tmt\"", "\"Section 2\",\"Team 2\",\"student2 In unregisteredCourse\",\"unregisteredCourse\",\"Yet to join\",\"student2InUnregisteredCourse@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expectedCsvString, System.lineSeparator()), csvString);
    ______TS("Failure case: non existent instructor");
    try {
        coursesLogic.getCourseStudentListAsCsv(courseId, "non-existent-instructor");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("Failure case: non existent course in the list of courses of the instructor");
    try {
        coursesLogic.getCourseStudentListAsCsv("non-existent-course", instructorId);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("Failure case: null parameter");
    try {
        coursesLogic.getCourseStudentListAsCsv(courseId, null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4