Search in sources :

Example 71 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class StudentsLogicTest method testGetStudentForEmail.

private void testGetStudentForEmail() {
    ______TS("null parameters");
    try {
        studentsLogic.getStudentForEmail(null, "valid@email.tmt");
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("non-exist student");
    String nonExistStudentEmail = "nonExist@google.tmt";
    String course1Id = dataBundle.courses.get("typicalCourse1").getId();
    assertNull(studentsLogic.getStudentForEmail(course1Id, nonExistStudentEmail));
    ______TS("typical case");
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    assertEquals(student1InCourse1.googleId, studentsLogic.getStudentForEmail(course1Id, student1InCourse1.email).googleId);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 72 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class StudentsLogicTest method testIsStudentInAnyCourse.

private void testIsStudentInAnyCourse() {
    ______TS("non-existent student");
    String nonExistStudentGoogleId = "nonExistGoogleId";
    assertFalse(studentsLogic.isStudentInAnyCourse(nonExistStudentGoogleId));
    ______TS("typical case");
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    assertTrue(studentsLogic.isStudentInAnyCourse(student1InCourse1.googleId));
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 73 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class StudentsLogicTest method testGetStudentsForGoogleId.

private void testGetStudentsForGoogleId() {
    ______TS("student in one course");
    StudentAttributes studentInCourse1 = dataBundle.students.get("student1InCourse1");
    assertEquals(1, studentsLogic.getStudentsForGoogleId(studentInCourse1.googleId).size());
    assertEquals(studentInCourse1.email, studentsLogic.getStudentsForGoogleId(studentInCourse1.googleId).get(0).email);
    assertEquals(studentInCourse1.name, studentsLogic.getStudentsForGoogleId(studentInCourse1.googleId).get(0).name);
    assertEquals(studentInCourse1.course, studentsLogic.getStudentsForGoogleId(studentInCourse1.googleId).get(0).course);
    ______TS("student in two courses");
    // this student is in two courses, course1 and course 2.
    // get list using student data from course 1
    StudentAttributes studentInTwoCoursesInCourse1 = dataBundle.students.get("student2InCourse1");
    List<StudentAttributes> listReceivedUsingStudentInCourse1 = studentsLogic.getStudentsForGoogleId(studentInTwoCoursesInCourse1.googleId);
    assertEquals(2, listReceivedUsingStudentInCourse1.size());
    // get list using student data from course 2
    StudentAttributes studentInTwoCoursesInCourse2 = dataBundle.students.get("student2InCourse2");
    List<StudentAttributes> listReceivedUsingStudentInCourse2 = studentsLogic.getStudentsForGoogleId(studentInTwoCoursesInCourse2.googleId);
    assertEquals(2, listReceivedUsingStudentInCourse2.size());
    // check the content from first list (we assume the content of the
    // second list is similar.
    listReceivedUsingStudentInCourse1.sort(Comparator.comparing(student -> student.course));
    StudentAttributes firstStudentReceived = listReceivedUsingStudentInCourse1.get(1);
    // First student received turned out to be the one from course 2
    assertEquals(studentInTwoCoursesInCourse2.email, firstStudentReceived.email);
    assertEquals(studentInTwoCoursesInCourse2.name, firstStudentReceived.name);
    assertEquals(studentInTwoCoursesInCourse2.course, firstStudentReceived.course);
    // then the second student received must be from course 1
    StudentAttributes secondStudentReceived = listReceivedUsingStudentInCourse1.get(0);
    assertEquals(studentInTwoCoursesInCourse1.email, secondStudentReceived.email);
    assertEquals(studentInTwoCoursesInCourse1.name, secondStudentReceived.name);
    assertEquals(studentInTwoCoursesInCourse1.course, secondStudentReceived.course);
    ______TS("non existent student");
    assertEquals(0, studentsLogic.getStudentsForGoogleId("non-existent").size());
    ______TS("null parameters");
    try {
        studentsLogic.getStudentsForGoogleId(null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : Const(teammates.common.util.Const) TimeHelperExtension(teammates.test.driver.TimeHelperExtension) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) EnrollException(teammates.common.exception.EnrollException) FeedbackSessionType(teammates.common.datatransfer.FeedbackSessionType) SanitizationHelper(teammates.common.util.SanitizationHelper) Test(org.testng.annotations.Test) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) ArrayList(java.util.ArrayList) JsonUtils(teammates.common.util.JsonUtils) FeedbackQuestionsLogic(teammates.logic.core.FeedbackQuestionsLogic) FeedbackResponsesLogic(teammates.logic.core.FeedbackResponsesLogic) AssertHelper(teammates.test.driver.AssertHelper) Text(com.google.appengine.api.datastore.Text) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) FeedbackSessionsLogic(teammates.logic.core.FeedbackSessionsLogic) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) StudentsDb(teammates.storage.api.StudentsDb) FieldValidator(teammates.common.util.FieldValidator) InvalidParametersException(teammates.common.exception.InvalidParametersException) AfterClass(org.testng.annotations.AfterClass) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StringHelper(teammates.common.util.StringHelper) Instant(java.time.Instant) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ZoneId(java.time.ZoneId) StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) List(java.util.List) StudentUpdateStatus(teammates.common.datatransfer.StudentUpdateStatus) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CoursesLogic(teammates.logic.core.CoursesLogic) StudentsLogic(teammates.logic.core.StudentsLogic) Comparator(java.util.Comparator) StringHelperExtension(teammates.test.driver.StringHelperExtension) AccountsLogic(teammates.logic.core.AccountsLogic) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 74 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class StudentsLogicTest method testEnrollStudent.

private void testEnrollStudent() throws Exception {
    String instructorId = "instructorForEnrollTesting";
    String instructorCourse = "courseForEnrollTesting";
    // delete leftover data, if any
    accountsLogic.deleteAccountCascade(instructorId);
    coursesLogic.deleteCourseCascade(instructorCourse);
    // create fresh test data
    accountsLogic.createAccount(AccountAttributes.builder().withGoogleId(instructorId).withName("ICET Instr Name").withEmail("instructor@icet.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(StudentProfileAttributes.builder(instructorId).withShortName("ICET").build()).build());
    coursesLogic.createCourseAndInstructor(instructorId, instructorCourse, "Course for Enroll Testing", "UTC");
    ______TS("add student into empty course");
    StudentAttributes student1 = StudentAttributes.builder(instructorCourse, "n", "e@g").withSection("sect 1").withTeam("t1").withComments("c").build();
    // check if the course is empty
    assertEquals(0, studentsLogic.getStudentsForCourse(instructorCourse).size());
    // add a new student and verify it is added and treated as a new student
    StudentEnrollDetails enrollmentResult = enrollStudent(student1);
    assertEquals(1, studentsLogic.getStudentsForCourse(instructorCourse).size());
    verifyEnrollmentDetailsForStudent(student1, null, enrollmentResult, StudentUpdateStatus.NEW);
    verifyPresentInDatastore(student1);
    ______TS("add existing student");
    // Verify it was not added
    enrollmentResult = enrollStudent(student1);
    verifyEnrollmentDetailsForStudent(student1, null, enrollmentResult, StudentUpdateStatus.UNMODIFIED);
    assertEquals(1, studentsLogic.getStudentsForCourse(instructorCourse).size());
    ______TS("add student into non-empty course");
    StudentAttributes student2 = StudentAttributes.builder(instructorCourse, "n2", "e2@g").withSection("sect 1").withTeam("t1").withComments("c").build();
    enrollmentResult = enrollStudent(student2);
    verifyEnrollmentDetailsForStudent(student2, null, enrollmentResult, StudentUpdateStatus.NEW);
    // add some more students to the same course (we add more than one
    // because we can use them for testing cascade logic later in this test case)
    enrollStudent(StudentAttributes.builder(instructorCourse, "n3", "e3@g").withSection("sect 2").withTeam("t2").withComments("c").build());
    enrollStudent(StudentAttributes.builder(instructorCourse, "n4", "e4@g").withSection("sect 2").withTeam("t2").withComments("").build());
    assertEquals(4, studentsLogic.getStudentsForCourse(instructorCourse).size());
    ______TS("modify info of existing student");
    // add some more details to the student
    student1.googleId = "googleId";
    studentsLogic.updateStudentCascadeWithoutDocument(student1.email, student1);
}
Also used : StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 75 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class StudentsLogicTest method testGetStudentsForCourse.

private void testGetStudentsForCourse() {
    ______TS("course with multiple students");
    CourseAttributes course1OfInstructor1 = dataBundle.courses.get("typicalCourse1");
    List<StudentAttributes> studentList = studentsLogic.getStudentsForCourse(course1OfInstructor1.getId());
    assertEquals(5, studentList.size());
    for (StudentAttributes s : studentList) {
        assertEquals(course1OfInstructor1.getId(), s.course);
    }
    ______TS("course with 0 students");
    CourseAttributes course2OfInstructor1 = dataBundle.courses.get("courseNoEvals");
    studentList = studentsLogic.getStudentsForCourse(course2OfInstructor1.getId());
    assertEquals(0, studentList.size());
    ______TS("null parameter");
    try {
        studentsLogic.getStudentsForCourse(null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("non-existent course");
    studentList = studentsLogic.getStudentsForCourse("non-existent");
    assertEquals(0, studentList.size());
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Aggregations

StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)241 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)85 Test (org.testng.annotations.Test)80 ArrayList (java.util.ArrayList)55 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)33 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)33 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)27 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)22 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)17 ShowPageResult (teammates.ui.controller.ShowPageResult)15 HashMap (java.util.HashMap)14 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)14 InvalidParametersException (teammates.common.exception.InvalidParametersException)14 EmailWrapper (teammates.common.util.EmailWrapper)13 RedirectResult (teammates.ui.controller.RedirectResult)12 List (java.util.List)11 StatusMessage (teammates.common.util.StatusMessage)10 HashSet (java.util.HashSet)9 StudentEnrollDetails (teammates.common.datatransfer.StudentEnrollDetails)9