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);
}
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));
}
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());
}
}
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);
}
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());
}
Aggregations