Search in sources :

Example 1 with StudentsDb

use of teammates.storage.api.StudentsDb in project teammates by TEAMMATES.

the class StudentCourseJoinActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    StudentCourseJoinAction joinAction;
    RedirectResult redirectResult;
    String[] submissionParams;
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    StudentsDb studentsDb = new StudentsDb();
    student1InCourse1 = studentsDb.getStudentForGoogleId(student1InCourse1.course, student1InCourse1.googleId);
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("not enough parameters");
    verifyAssumptionFailure();
    ______TS("typical case");
    String idOfNewStudent = "idOfNewStudent";
    StudentAttributes newStudentData = StudentAttributes.builder(student1InCourse1.course, "nameOfNewStudent", "newStudent@course1.com").withSection(student1InCourse1.section).withTeam(student1InCourse1.team).withComments("This is a new student").build();
    studentsDb.createEntity(newStudentData);
    gaeSimulation.loginUser(idOfNewStudent);
    String newStudentKey = StringHelper.encrypt(studentsDb.getStudentForEmail(newStudentData.course, newStudentData.email).key);
    /*
         * Reason why get student attributes for student just added again from
         * StudentsDb:below test needs the student's key, which is auto
         * generated when creating the student instance.So the reg key needs to
         * be obtained by calling the getter from logic to retrieve again
         */
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE };
    joinAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(joinAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_COURSE_JOIN_CONFIRMATION, false, idOfNewStudent), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_COURSE_JOIN_AUTHENTICATED, newStudentKey, Const.ActionURIs.STUDENT_PROFILE_PAGE), ((StudentCourseJoinConfirmationPageData) pageResult.data).getConfirmUrl());
    assertEquals("", pageResult.getStatusMessage());
    ______TS("skip confirmation");
    gaeSimulation.logoutUser();
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE, Const.ParamsNames.STUDENT_EMAIL, newStudentData.email, Const.ParamsNames.COURSE_ID, newStudentData.course };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_COURSE_JOIN_AUTHENTICATED, newStudentKey, Const.ActionURIs.STUDENT_PROFILE_PAGE.replace("/", "%2F"), false), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    // delete the new student
    studentsDb.deleteStudentWithoutDocument(newStudentData.course, newStudentData.email);
    ______TS("Non-existent student attempting to join course displays error");
    gaeSimulation.loginUser(idOfNewStudent);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE, Const.ParamsNames.STUDENT_EMAIL, newStudentData.email, Const.ParamsNames.COURSE_ID, newStudentData.course };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(Const.ActionURIs.STUDENT_HOME_PAGE, redirectResult.destination);
    assertEquals(String.format(Const.StatusMessages.NON_EXISTENT_STUDENT_ATTEMPTING_TO_JOIN_COURSE, newStudentData.course), redirectResult.getStatusMessage());
    assertEquals("warning", redirectResult.getStatusMessageColor());
    assertTrue(redirectResult.isError);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentCourseJoinAction(teammates.ui.controller.StudentCourseJoinAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) Test(org.testng.annotations.Test)

Example 2 with StudentsDb

use of teammates.storage.api.StudentsDb in project teammates by TEAMMATES.

the class StudentCourseJoinAuthenticatedActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    dataBundle = loadDataBundle("/StudentCourseJoinAuthenticatedTest.json");
    StudentsDb studentsDb = new StudentsDb();
    AccountsDb accountsDb = new AccountsDb();
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    student1InCourse1 = studentsDb.getStudentForGoogleId(student1InCourse1.course, student1InCourse1.googleId);
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("not enough parameters");
    verifyAssumptionFailure();
    ______TS("invalid key");
    String invalidKey = StringHelper.encrypt("invalid key");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE };
    try {
        StudentCourseJoinAuthenticatedAction authenticatedAction = getAction(submissionParams);
        getRedirectResult(authenticatedAction);
    } catch (UnauthorizedAccessException uae) {
        assertEquals("No student with given registration key:" + invalidKey, uae.getMessage());
    }
    ______TS("already registered student");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(student1InCourse1.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE };
    StudentCourseJoinAuthenticatedAction authenticatedAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, true, student1InCourse1.googleId), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You (student1InCourse1) have already joined this course", redirectResult.getStatusMessage());
    /*______TS("student object belongs to another account");

        StudentAttributes student2InCourse1 = dataBundle.students
                .get("student2InCourse1");
        student2InCourse1 = studentsDb.getStudentForGoogleId(
                student2InCourse1.course, student2InCourse1.googleId);

        submissionParams = new String[] {
                Const.ParamsNames.REGKEY,
                StringHelper.encrypt(student2InCourse1.key),
                Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE
        };

        authenticatedAction = getAction(submissionParams);
        redirectResult = getRedirectResult(authenticatedAction);

        assertEquals(
                Const.ActionURIs.STUDENT_HOME_PAGE
                        + "?persistencecourse=" + student1InCourse1.course
                        + "&error=true&user=" + student1InCourse1.googleId,
                redirectResult.getDestinationWithParams());
        assertTrue(redirectResult.isError);
        assertEquals(
                "The join link used belongs to a different user"
                        + " whose Google ID is stude..ourse1 "
                        + "(only part of the Google ID is shown to protect privacy)."
                        + " If that Google ID is owned by you, "
                        + "please logout and re-login using that Google account."
                        + " If it doesn’t belong to you, please "
                        + "<a href=\"mailto:" + Config.SUPPORT_EMAIL
                        + "?body=Your name:%0AYour course:%0AYour university:\">"
                        + "contact us</a> so that we can investigate.",
                redirectResult.getStatusMessage());
*/
    ______TS("join course with no feedback sessions, profile is empty");
    AccountAttributes studentWithEmptyProfile = dataBundle.accounts.get("noFSStudent");
    studentWithEmptyProfile = accountsDb.getAccount(studentWithEmptyProfile.googleId, true);
    assertNotNull(studentWithEmptyProfile.studentProfile);
    assertEquals("", studentWithEmptyProfile.studentProfile.pictureKey);
    assertEquals("", studentWithEmptyProfile.studentProfile.shortName);
    assertEquals("", studentWithEmptyProfile.studentProfile.nationality);
    assertEquals("", studentWithEmptyProfile.studentProfile.moreInfo);
    assertEquals("", studentWithEmptyProfile.studentProfile.email);
    StudentAttributes studentWithEmptyProfileAttributes = dataBundle.students.get("noFSStudentWithNoProfile");
    studentWithEmptyProfileAttributes = studentsDb.getStudentForEmail(studentWithEmptyProfileAttributes.course, studentWithEmptyProfileAttributes.email);
    gaeSimulation.loginUser("idOfNoFSStudent");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(studentWithEmptyProfileAttributes.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE };
    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, "idOfCourseNoEvals", false, "idOfNoFSStudent"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals") + "<br>" + String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals") + "<br>" + Const.StatusMessages.STUDENT_UPDATE_PROFILE, redirectResult.getStatusMessage());
    ______TS("join course with no feedback sessions, profile has only one missing field");
    AccountAttributes studentWithoutProfilePicture = dataBundle.accounts.get("noFSStudent2");
    studentWithoutProfilePicture = accountsDb.getAccount(studentWithoutProfilePicture.googleId, true);
    assertNotNull(studentWithoutProfilePicture.studentProfile);
    assertEquals("", studentWithoutProfilePicture.studentProfile.pictureKey);
    assertFalse(studentWithoutProfilePicture.studentProfile.nationality.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.shortName.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.moreInfo.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.email.isEmpty());
    StudentAttributes studentWithoutProfilePictureAttributes = dataBundle.students.get("noFSStudentWithPartialProfile");
    studentWithoutProfilePictureAttributes = studentsDb.getStudentForEmail(studentWithoutProfilePictureAttributes.course, studentWithoutProfilePictureAttributes.email);
    gaeSimulation.loginUser("idOfNoFSStudent2");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(studentWithoutProfilePictureAttributes.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE };
    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, "idOfCourseNoEvals", false, "idOfNoFSStudent2"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals") + "<br>" + String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals") + "<br>" + Const.StatusMessages.STUDENT_UPDATE_PROFILE_PICTURE, redirectResult.getStatusMessage());
    ______TS("join course with no feedback sessions, profile has no missing field");
    AccountAttributes studentWithFullProfile = dataBundle.accounts.get("noFSStudent3");
    studentWithFullProfile = accountsDb.getAccount(studentWithFullProfile.googleId, true);
    assertNotNull(studentWithFullProfile.studentProfile);
    assertFalse(studentWithFullProfile.studentProfile.pictureKey.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.nationality.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.shortName.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.moreInfo.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.email.isEmpty());
    StudentAttributes studentWithFullProfileAttributes = dataBundle.students.get("noFSStudentWithFullProfile");
    studentWithFullProfileAttributes = studentsDb.getStudentForEmail(studentWithFullProfileAttributes.course, studentWithFullProfileAttributes.email);
    gaeSimulation.loginUser("idOfNoFSStudent3");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(studentWithFullProfileAttributes.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE };
    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, "idOfCourseNoEvals", false, "idOfNoFSStudent3"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals") + "<br>" + String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, "[idOfCourseNoEvals] Typical Course 3 with 0 Evals"), redirectResult.getStatusMessage());
    ______TS("typical case");
    AccountAttributes newStudentAccount = AccountAttributes.builder().withGoogleId("idOfNewStudent").withName("nameOfNewStudent").withEmail("newStudent@gmail.com").withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes("idOfNewStudent").build();
    accountsDb.createAccount(newStudentAccount);
    StudentAttributes newStudentAttributes = StudentAttributes.builder(student1InCourse1.course, "nameOfNewStudent", "newStudent@course1.com").withSection(student1InCourse1.section).withTeam(student1InCourse1.team).withComments("This is a new student").build();
    studentsDb.createEntity(newStudentAttributes);
    newStudentAttributes = studentsDb.getStudentForEmail(newStudentAttributes.course, newStudentAttributes.email);
    gaeSimulation.loginUser("idOfNewStudent");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newStudentAttributes.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE };
    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, "idOfTypicalCourse1", false, "idOfNewStudent"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, "[idOfTypicalCourse1] Typical Course 1 with 2 Evals"), redirectResult.getStatusMessage());
    ______TS("typical case: data requires sanitization");
    AccountAttributes accountTestSanitization = dataBundle.accounts.get("student1InTestingSanitizationCourse");
    StudentAttributes studentTestSanitization = dataBundle.students.get("student1InTestingSanitizationCourse");
    CourseAttributes courseTestSanitization = dataBundle.courses.get("testingSanitizationCourse");
    gaeSimulation.loginUser(accountTestSanitization.googleId);
    // retrieve student from datastore to get regkey
    studentTestSanitization = studentsDb.getStudentForEmail(studentTestSanitization.course, studentTestSanitization.email);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(studentTestSanitization.key), Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE };
    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);
    assertEquals(Const.ActionURIs.STUDENT_PROFILE_PAGE + "?persistencecourse=" + courseTestSanitization.getId() + "&error=false&user=" + accountTestSanitization.googleId, redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    String courseIdentifier = "[" + courseTestSanitization.getId() + "] " + SanitizationHelper.sanitizeForHtml(courseTestSanitization.getName());
    String expectedStatusMessage = String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, courseIdentifier) + "<br>" + String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, courseIdentifier) + "<br>" + accountTestSanitization.studentProfile.generateUpdateMessageForStudent();
    assertEquals(expectedStatusMessage, redirectResult.getStatusMessage());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) AccountsDb(teammates.storage.api.AccountsDb) RedirectResult(teammates.ui.controller.RedirectResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) StudentCourseJoinAuthenticatedAction(teammates.ui.controller.StudentCourseJoinAuthenticatedAction) StudentsDb(teammates.storage.api.StudentsDb) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 3 with StudentsDb

use of teammates.storage.api.StudentsDb in project teammates by TEAMMATES.

the class FeedbackResponsesLogicTest method testIsNameVisibleTo.

private void testIsNameVisibleTo() {
    ______TS("testIsNameVisibleTo");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    StudentAttributes student2 = dataBundle.students.get("student2InCourse1");
    StudentAttributes student3 = dataBundle.students.get("student3InCourse1");
    StudentAttributes student5 = dataBundle.students.get("student5InCourse1");
    FeedbackQuestionAttributes fq = getQuestionFromDatastore("qn3InSession1InCourse1");
    FeedbackResponseAttributes fr = getResponseFromDatastore("response1ForQ3S1C1");
    CourseRoster roster = new CourseRoster(new StudentsDb().getStudentsForCourse(fq.courseId), new InstructorsDb().getInstructorsForCourse(fq.courseId));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, true, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to own team members");
    fr.giver = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to receiver/reciever team members");
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("test anonymous team recipients");
    // Only members of the recipient team should be able to see the recipient name
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fq.showResponsesTo.add(FeedbackParticipantType.STUDENTS);
    fr.recipient = "Team 1.1";
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("null question");
    assertFalse(frLogic.isNameVisibleToUser(null, fr, student.email, UserRole.STUDENT, false, roster));
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) CourseRoster(teammates.common.datatransfer.CourseRoster) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 4 with StudentsDb

use of teammates.storage.api.StudentsDb in project teammates by TEAMMATES.

the class StudentSearchTest method allTests.

@Test
public void allTests() {
    StudentsDb studentsDb = new StudentsDb();
    StudentAttributes stu1InCourse1 = dataBundle.students.get("student1InCourse1");
    StudentAttributes stu2InCourse1 = dataBundle.students.get("student2InCourse1");
    StudentAttributes stu1InCourse2 = dataBundle.students.get("student1InCourse2");
    StudentAttributes stu2InCourse2 = dataBundle.students.get("student2InCourse2");
    StudentAttributes stu1InUnregCourse = dataBundle.students.get("student1InUnregisteredCourse");
    StudentAttributes stu2InUnregCourse = dataBundle.students.get("student2InUnregisteredCourse");
    StudentAttributes stu1InArchCourse = dataBundle.students.get("student1InArchivedCourse");
    ______TS("success: search for students in whole system; query string does not match any student");
    StudentSearchResultBundle bundle = studentsDb.searchStudentsInWholeSystem("non-existent");
    assertEquals(0, bundle.numberOfResults);
    assertTrue(bundle.studentList.isEmpty());
    ______TS("success: search for students in whole system; query string matches some students");
    bundle = studentsDb.searchStudentsInWholeSystem("student1");
    assertEquals(4, bundle.numberOfResults);
    AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse1, stu1InCourse2, stu1InUnregCourse, stu1InArchCourse), bundle.studentList);
    ______TS("success: search for students in whole system; query string should be case-insensitive");
    bundle = studentsDb.searchStudentsInWholeSystem("stUdeNt2");
    assertEquals(3, bundle.numberOfResults);
    AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu2InCourse1, stu2InCourse2, stu2InUnregCourse), bundle.studentList);
    ______TS("success: search for students; query string matches some students; results restricted " + "based on instructor's privilege");
    List<InstructorAttributes> ins1OfCourse1 = Arrays.asList(new InstructorAttributes[] { dataBundle.instructors.get("instructor1OfCourse1") });
    List<InstructorAttributes> ins1OfCourse2 = Arrays.asList(new InstructorAttributes[] { dataBundle.instructors.get("instructor1OfCourse2") });
    bundle = studentsDb.search("student1", ins1OfCourse1);
    assertEquals(1, bundle.numberOfResults);
    AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse1), bundle.studentList);
    bundle = studentsDb.search("student1", ins1OfCourse2);
    assertEquals(1, bundle.numberOfResults);
    AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse2), bundle.studentList);
    ______TS("success: search for students; deleted student no longer searchable");
    studentsDb.deleteStudent(stu1InCourse1.course, stu1InCourse1.email);
    bundle = studentsDb.search("student1", ins1OfCourse1);
    assertEquals(0, bundle.numberOfResults);
    assertTrue(bundle.studentList.isEmpty());
    ______TS("success: search for students; deleted student without deleted document: the document " + "will be deleted during the search");
    studentsDb.deleteStudentWithoutDocument(stu1InCourse2.course, stu1InCourse2.email);
    bundle = studentsDb.search("student1", ins1OfCourse2);
    assertEquals(0, bundle.numberOfResults);
    assertTrue(bundle.studentList.isEmpty());
    studentsDb.deleteStudentWithoutDocument(stu2InCourse1.course, stu2InCourse1.email);
    bundle = studentsDb.searchStudentsInWholeSystem("student2");
    assertEquals(2, bundle.numberOfResults);
    AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu2InCourse2, stu2InUnregCourse), bundle.studentList);
}
Also used : StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) StudentsDb(teammates.storage.api.StudentsDb) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 5 with StudentsDb

use of teammates.storage.api.StudentsDb in project teammates by TEAMMATES.

the class StudentFeedbackSubmissionEditPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    StudentAttributes unregStudent = StudentAttributes.builder("idOfTypicalCourse1", "Unreg Student", "unreg@stud.ent").withSection("1").withTeam("Team0.1").withComments("asdf").build();
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("not enough parameters");
    verifyAssumptionFailure();
    FeedbackSessionAttributes session1InCourse1 = dataBundle.feedbackSessions.get("session1InCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    verifyAssumptionFailure(submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    verifyAssumptionFailure(submissionParams);
    ______TS("Test null feedback session name parameter");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    StudentFeedbackSubmissionEditPageAction pageAction;
    RedirectResult redirectResult;
    try {
        pageAction = getAction(submissionParams);
        redirectResult = getRedirectResult(pageAction);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.FEEDBACK_SESSION_NAME), e.getMessage());
    }
    ______TS("Test null course id parameter");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    try {
        pageAction = getAction(submissionParams);
        redirectResult = getRedirectResult(pageAction);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), e.getMessage());
    }
    ______TS("typical success case for registered student");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT, false, student1InCourse1.googleId), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, pageResult.getStatusMessage());
    ______TS("feedbacksession deleted");
    FeedbackSessionsDb feedbackSessionsDb = new FeedbackSessionsDb();
    feedbackSessionsDb.deleteEntity(session1InCourse1);
    String[] params = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    pageAction = getAction(params);
    redirectResult = getRedirectResult(pageAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, false, "student1InCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_DELETED_NO_ACCESS, redirectResult.getStatusMessage());
    // for unregistered student
    StudentsDb stDb = new StudentsDb();
    stDb.createStudentWithoutDocument(unregStudent);
    unregStudent = stDb.getStudentForEmail("idOfTypicalCourse1", "unreg@stud.ent");
    gaeSimulation.logoutUser();
    params = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.REGKEY, StringHelper.encrypt(unregStudent.key), Const.ParamsNames.STUDENT_EMAIL, unregStudent.email };
    try {
        pageAction = getAction(params);
        AssertHelper.assertLogMessageEqualsForUnregisteredStudentUser("TEAMMATESLOG|||studentFeedbackSubmissionEditPage|||studentFeedbackSubmissionEditPage|||" + "true|||Unregistered:idOfTypicalCourse1|||Unreg Student|||Unknown|||unreg@stud.ent|||" + "Unknown|||/page/studentFeedbackSubmissionEditPage", pageAction.getLogMessage(), unregStudent.email, unregStudent.course);
        redirectResult = getRedirectResult(pageAction);
        signalFailureToDetectException("EntityDoesNotExist");
    } catch (EntityNotFoundException enfe) {
        assertEquals("unregistered student trying to access non-existent session", enfe.getMessage());
    }
    stDb.deleteStudent("idOfTypicalCourse1", "unreg@stud.ent");
    ______TS("typical success case for unregistered student");
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    removeAndRestoreTypicalDataBundle();
    session1InCourse1 = dataBundle.feedbackSessions.get("session1InCourse1");
    params = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName(), Const.ParamsNames.USER_ID, student1InCourse1.googleId };
    pageAction = getAction(params);
    pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT, false, student1InCourse1.googleId), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, pageResult.getStatusMessage());
    ______TS("masquerade mode");
    gaeSimulation.loginAsAdmin("admin.user");
    pageAction = getAction(params);
    pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT, false, student1InCourse1.googleId), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, pageResult.getStatusMessage());
    ______TS("student has not joined course");
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    student1InCourse1.googleId = null;
    new StudentsDb().updateStudentWithoutSearchability(student1InCourse1.course, student1InCourse1.email, student1InCourse1.name, student1InCourse1.team, student1InCourse1.section, student1InCourse1.email, student1InCourse1.googleId, student1InCourse1.comments);
    pageAction = getAction(params);
    redirectResult = getRedirectResult(pageAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, true, "student1InCourse1"), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You are not registered in the course " + session1InCourse1.getCourseId(), redirectResult.getStatusMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackSessionsDb(teammates.storage.api.FeedbackSessionsDb) NullPostParameterException(teammates.common.exception.NullPostParameterException) ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentFeedbackSubmissionEditPageAction(teammates.ui.controller.StudentFeedbackSubmissionEditPageAction) EntityNotFoundException(teammates.common.exception.EntityNotFoundException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) Test(org.testng.annotations.Test)

Aggregations

StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)5 StudentsDb (teammates.storage.api.StudentsDb)5 Test (org.testng.annotations.Test)4 RedirectResult (teammates.ui.controller.RedirectResult)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 CourseRoster (teammates.common.datatransfer.CourseRoster)1 StudentSearchResultBundle (teammates.common.datatransfer.StudentSearchResultBundle)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 EntityNotFoundException (teammates.common.exception.EntityNotFoundException)1 NullPostParameterException (teammates.common.exception.NullPostParameterException)1 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)1 AccountsDb (teammates.storage.api.AccountsDb)1 FeedbackSessionsDb (teammates.storage.api.FeedbackSessionsDb)1 InstructorsDb (teammates.storage.api.InstructorsDb)1 StudentCourseJoinAction (teammates.ui.controller.StudentCourseJoinAction)1