Search in sources :

Example 1 with StudentAttributesFactory

use of teammates.common.datatransfer.StudentAttributesFactory in project teammates by TEAMMATES.

the class StudentsLogic method createStudents.

/**
 * Builds {@code studentList} from user input {@code lines}. All empty lines or lines with only white spaces will
 * be skipped.
 *
 * @param lines the enrollment lines entered by the instructor.
 * @throws EnrollException if some of the student instances created are invalid. The exception message contains
 *         invalidity info for all invalid student instances in HTML format.
 */
public List<StudentAttributes> createStudents(String lines, String courseId) throws EnrollException {
    List<String> invalidityInfo = new ArrayList<>();
    String[] linesArray = lines.split(System.lineSeparator());
    List<StudentAttributes> studentList = new ArrayList<>();
    StudentAttributesFactory saf = new StudentAttributesFactory(linesArray[0]);
    for (int i = 1; i < linesArray.length; i++) {
        String line = linesArray[i];
        String sanitizedLine = SanitizationHelper.sanitizeForHtml(line);
        if (StringHelper.isWhiteSpace(line)) {
            continue;
        }
        try {
            StudentAttributes student = saf.makeStudent(line, courseId);
            if (!student.isValid()) {
                invalidityInfo.add(invalidStudentInfo(sanitizedLine, student));
            }
            int duplicateEmailIndex = getDuplicateEmailIndex(student.email, studentList);
            if (duplicateEmailIndex != -1) {
                invalidityInfo.add(duplicateEmailInfo(sanitizedLine, linesArray[duplicateEmailIndex + 1]));
            }
            studentList.add(student);
        } catch (EnrollException e) {
            invalidityInfo.add(enrollExceptionInfo(sanitizedLine, e.getMessage()));
        }
    }
    if (!invalidityInfo.isEmpty()) {
        throw new EnrollException(StringHelper.toString(invalidityInfo, "<br>"));
    }
    return studentList;
}
Also used : EnrollException(teammates.common.exception.EnrollException) ArrayList(java.util.ArrayList) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 2 with StudentAttributesFactory

use of teammates.common.datatransfer.StudentAttributesFactory 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 3 with StudentAttributesFactory

use of teammates.common.datatransfer.StudentAttributesFactory in project teammates by TEAMMATES.

the class StudentsLogicTest method testEnrollLinesChecking.

private void testEnrollLinesChecking() throws Exception {
    String info;
    String enrollLines;
    String courseId = "CourseID";
    coursesLogic.createCourse(courseId, "CourseName", "UTC");
    String invalidInfoString = null;
    String expectedInvalidInfoString;
    List<String> expectedInvalidInfoList = new ArrayList<>();
    ______TS("enrollLines with invalid parameters");
    String invalidTeamName = StringHelperExtension.generateStringOfLength(FieldValidator.TEAM_NAME_MAX_LENGTH + 1);
    String invalidStudentName = StringHelperExtension.generateStringOfLength(FieldValidator.PERSON_NAME_MAX_LENGTH + 1);
    String headerLine = "Team | Name | Email";
    String lineWithInvalidTeamName = invalidTeamName + "| John | john@email.tmt";
    String lineWithInvalidStudentName = "Team 1 |" + invalidStudentName + "| student@email.tmt";
    String lineWithInvalidEmail = "Team 1 | James |" + "James_invalid_email.tmt";
    String lineWithInvalidStudentNameAndEmail = "Team 2 |" + invalidStudentName + "|" + "student_invalid_email.tmt";
    String lineWithInvalidTeamNameAndEmail = invalidTeamName + "| Paul |" + "Paul_invalid_email.tmt";
    String lineWithInvalidTeamNameAndStudentNameAndEmail = invalidTeamName + "|" + invalidStudentName + "|" + "invalid_email.tmt";
    enrollLines = headerLine + System.lineSeparator() + lineWithInvalidTeamName + System.lineSeparator() + lineWithInvalidStudentName + System.lineSeparator() + lineWithInvalidEmail + System.lineSeparator() + lineWithInvalidStudentNameAndEmail + System.lineSeparator() + lineWithInvalidTeamNameAndEmail + System.lineSeparator() + lineWithInvalidTeamNameAndStudentNameAndEmail;
    invalidInfoString = getExceptionMessageOnCreatingStudentsList(enrollLines, courseId);
    StudentAttributesFactory saf = new StudentAttributesFactory(headerLine);
    expectedInvalidInfoList.clear();
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidTeamName, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidTeamName, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidStudentName, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidStudentName, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidEmail, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidEmail, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidStudentNameAndEmail, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidStudentNameAndEmail, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidTeamNameAndEmail, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidTeamNameAndEmail, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidTeamNameAndStudentNameAndEmail, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidTeamNameAndStudentNameAndEmail, info));
    expectedInvalidInfoString = StringHelper.toString(expectedInvalidInfoList, "<br>");
    assertEquals(expectedInvalidInfoString, invalidInfoString);
    ______TS("enrollLines with too few");
    String lineWithNoEmailInput = "Team 4 | StudentWithNoEmailInput";
    String lineWithExtraParameters = "Team 4 | StudentWithExtraParameters | " + " studentWithExtraParameters@email.tmt | comment | extra_parameter";
    enrollLines = headerLine + System.lineSeparator() + lineWithNoEmailInput + System.lineSeparator() + lineWithExtraParameters;
    invalidInfoString = getExceptionMessageOnCreatingStudentsList(enrollLines, courseId);
    expectedInvalidInfoList.clear();
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithNoEmailInput, StudentAttributesFactory.ERROR_ENROLL_LINE_TOOFEWPARTS));
    expectedInvalidInfoString = StringHelper.toString(expectedInvalidInfoList, "<br>");
    assertEquals(expectedInvalidInfoString, invalidInfoString);
    ______TS("enrollLines with some empty fields");
    String lineWithTeamNameEmpty = " | StudentWithTeamFieldEmpty | student@email.tmt";
    String lineWithStudentNameEmpty = "Team 5 |  | no_name@email.tmt";
    String lineWithEmailEmpty = "Team 5 | StudentWithEmailFieldEmpty | |";
    enrollLines = headerLine + System.lineSeparator() + lineWithTeamNameEmpty + System.lineSeparator() + lineWithStudentNameEmpty + System.lineSeparator() + lineWithEmailEmpty;
    invalidInfoString = getExceptionMessageOnCreatingStudentsList(enrollLines, courseId);
    expectedInvalidInfoList.clear();
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithTeamNameEmpty, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithTeamNameEmpty, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithStudentNameEmpty, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithStudentNameEmpty, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithEmailEmpty, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithEmailEmpty, info));
    expectedInvalidInfoString = StringHelper.toString(expectedInvalidInfoList, "<br>");
    assertEquals(expectedInvalidInfoString, invalidInfoString);
    ______TS("enrollLines with correct input");
    headerLine = "Team | Name | Email | Comment";
    String lineWithCorrectInput = "Team 3 | Mary | mary@email.tmt";
    String lineWithCorrectInputWithComment = "Team 4 | Benjamin | benjamin@email.tmt | Foreign student";
    enrollLines = headerLine + System.lineSeparator() + lineWithCorrectInput + System.lineSeparator() + lineWithCorrectInputWithComment;
    // No exception is supposed be thrown here. Test will fail if Enrollment Exception is thrown
    studentsLogic.createStudents(enrollLines, courseId);
    ______TS("enrollLines with only whitespaces");
    // not tested as enroll lines must be trimmed before passing to the method
    ______TS("enrollLines with duplicate emails");
    enrollLines = headerLine + System.lineSeparator() + lineWithCorrectInput + System.lineSeparator() + lineWithCorrectInput;
    invalidInfoString = getExceptionMessageOnCreatingStudentsList(enrollLines, courseId);
    expectedInvalidInfoString = "Same email address as the student in line \"" + lineWithCorrectInput + "\"";
    AssertHelper.assertContains(expectedInvalidInfoString, invalidInfoString);
    ______TS("enrollLines with a mix of all above cases");
    enrollLines = headerLine + System.lineSeparator() + lineWithInvalidTeamName + System.lineSeparator() + lineWithInvalidTeamNameAndStudentNameAndEmail + System.lineSeparator() + lineWithExtraParameters + System.lineSeparator() + lineWithTeamNameEmpty + System.lineSeparator() + lineWithCorrectInput + System.lineSeparator() + "\t";
    invalidInfoString = getExceptionMessageOnCreatingStudentsList(enrollLines, courseId);
    expectedInvalidInfoList.clear();
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidTeamName, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidTeamName, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithInvalidTeamNameAndStudentNameAndEmail, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithInvalidTeamNameAndStudentNameAndEmail, info));
    info = StringHelper.toString(SanitizationHelper.sanitizeForHtml(saf.makeStudent(lineWithTeamNameEmpty, courseId).getInvalidityInfo()), "<br>" + Const.StatusMessages.ENROLL_LINES_PROBLEM_DETAIL_PREFIX + " ");
    expectedInvalidInfoList.add(String.format(Const.StatusMessages.ENROLL_LINES_PROBLEM, lineWithTeamNameEmpty, info));
    expectedInvalidInfoString = StringHelper.toString(expectedInvalidInfoList, "<br>");
    assertEquals(expectedInvalidInfoString, invalidInfoString);
}
Also used : ArrayList(java.util.ArrayList) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory)

Example 4 with StudentAttributesFactory

use of teammates.common.datatransfer.StudentAttributesFactory in project teammates by TEAMMATES.

the class StudentAttributesFactoryTest method testMakeStudent.

@Test
public void testMakeStudent() throws EnrollException {
    StudentAttributesFactory saf = new StudentAttributesFactory();
    String line = null;
    String courseId = null;
    StudentAttributes studentCreated;
    ______TS("Failure case: empty row");
    line = "";
    courseId = "SAFT.courseId";
    try {
        saf.makeStudent(line, courseId);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        assertEquals(StudentAttributesFactory.ERROR_ENROLL_LINE_EMPTY, e.getMessage());
    }
    ______TS("Failure case: too few columns");
    line = "name|email";
    try {
        saf.makeStudent(line, courseId);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        assertEquals(StudentAttributesFactory.ERROR_ENROLL_LINE_TOOFEWPARTS, e.getMessage());
    }
    ______TS("Typical case: normal column order with comment");
    saf = new StudentAttributesFactory("TEAMS|Names|Email|comments");
    line = "team 1|SAFT.name|SAFT@email.com|some comment...";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.team, "team 1");
    assertEquals(studentCreated.name, "SAFT.name");
    assertEquals(studentCreated.email, "SAFT@email.com");
    assertEquals(studentCreated.comments, "some comment...");
    line = "team 2|SAFT.name2|SAFT2@email.com";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.team, "team 2");
    assertEquals(studentCreated.name, "SAFT.name2");
    assertEquals(studentCreated.email, "SAFT2@email.com");
    assertEquals(studentCreated.comments, "");
    ______TS("Typical case: different column order without comment");
    saf = new StudentAttributesFactory("Name|emails|teams");
    line = "SAFT.name|SAFT@email.com|team 1";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.team, "team 1");
    assertEquals(studentCreated.name, "SAFT.name");
    assertEquals(studentCreated.email, "SAFT@email.com");
    assertEquals(studentCreated.comments, "");
    ______TS("Typical case: different column order, contains empty columns");
    saf = new StudentAttributesFactory("email \t name \t    \t team");
    line = "SAFT@email.com \t SAFT.name \t      \t team 1";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.team, "team 1");
    assertEquals(studentCreated.name, "SAFT.name");
    assertEquals(studentCreated.email, "SAFT@email.com");
    assertEquals(studentCreated.comments, "");
    ______TS("Typical case: no header specified, assume default column order");
    saf = new StudentAttributesFactory();
    line = "section 1| team 1|SAFT.name|SAFT@email.com|comment";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.section, "section 1");
    assertEquals(studentCreated.team, "team 1");
    assertEquals(studentCreated.name, "SAFT.name");
    assertEquals(studentCreated.email, "SAFT@email.com");
    assertEquals(studentCreated.comments, "comment");
    line = "section 2| team 2|SAFT.name2|SAFT2@email.com";
    studentCreated = saf.makeStudent(line, courseId);
    assertEquals(studentCreated.section, "section 2");
    assertEquals(studentCreated.team, "team 2");
    assertEquals(studentCreated.name, "SAFT.name2");
    assertEquals(studentCreated.email, "SAFT2@email.com");
    assertEquals(studentCreated.comments, "");
}
Also used : EnrollException(teammates.common.exception.EnrollException) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Aggregations

StudentAttributesFactory (teammates.common.datatransfer.StudentAttributesFactory)4 EnrollException (teammates.common.exception.EnrollException)3 ArrayList (java.util.ArrayList)2 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)2 Text (com.google.appengine.api.datastore.Text)1 Test (org.testng.annotations.Test)1 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)1 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 FeedbackSessionsLogic (teammates.logic.core.FeedbackSessionsLogic)1