Search in sources :

Example 1 with RedirectResult

use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.

the class InstructorStudentRecordsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = typicalBundle.students.get("student2InCourse1");
    String instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid parameters");
    // no params
    verifyAssumptionFailure();
    // null courseId
    String[] invalidParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, student.email };
    verifyAssumptionFailure(invalidParams);
    // null student email
    invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId };
    verifyAssumptionFailure(invalidParams);
    // student not in course
    String studentEmailOfStudent1InCourse2 = typicalBundle.students.get("student1InCourse2").email;
    invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, studentEmailOfStudent1InCourse2 };
    RedirectResult redirect = getRedirectResult(getAction(invalidParams));
    AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, redirect.getDestinationWithParams());
    AssertHelper.assertContains(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, redirect.getStatusMessage());
    ______TS("Typical case: student has some records and has profile");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    InstructorStudentRecordsPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, "idOfInstructor3"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    InstructorStudentRecordsPageData actualData = (InstructorStudentRecordsPageData) r.data;
    StudentProfileAttributes expectedProfile = StudentProfileAttributes.builder(student.googleId).build();
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    expectedProfile.pictureKey = actualData.spa.pictureKey;
    assertEquals(instructorId, actualData.account.googleId);
    assertEquals(instructor.courseId, actualData.getCourseId());
    assertEquals(6, actualData.getSessionNames().size());
    assertEquals(student.googleId, actualData.spa.googleId);
    String expectedLogMessage = "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage" + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3" + "|||instr3@course1n2.tmt|||instructorStudentRecords Page Load<br>" + "Viewing <span class=\"bold\">" + student.email + "'s</span> records " + "for Course <span class=\"bold\">[" + instructor.courseId + "]</span><br>" + "Number of sessions: 6<br>" + "Student Profile: " + SanitizationHelper.sanitizeForHtmlTag(expectedProfile.toString()) + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Typical case: instructor cannot view sections");
    instructor = typicalBundle.instructors.get("helperOfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, "idOfHelperOfCourse1"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("Normally, we would show the student’s profile here. " + "However, you do not have access to view this student's profile<br>" + "No records were found for this student", r.getStatusMessage());
    ______TS("Typical case: student has no records, no profiles");
    String instructor4Id = typicalBundle.instructors.get("instructor4").googleId;
    // re-login as another instructor for new test
    gaeSimulation.loginAsInstructor(instructor4Id);
    String courseIdWithNoSession = "idOfCourseNoEvals";
    StudentAttributes testStudent = createStudentInTypicalDataBundleForCourseWithNoSession();
    String[] submissionParamsWithNoSession = new String[] { Const.ParamsNames.COURSE_ID, courseIdWithNoSession, Const.ParamsNames.STUDENT_EMAIL, "emailTemp@gmail.tmt" };
    InstructorStudentRecordsPageAction aWithNoSession = getAction(submissionParamsWithNoSession);
    ShowPageResult rWithNoSession = getShowPageResult(aWithNoSession);
    List<String> expectedMessages = new ArrayList<>();
    expectedMessages.add("No records were found for this student");
    expectedMessages.add(Const.StatusMessages.STUDENT_NOT_JOINED_YET_FOR_RECORDS);
    AssertHelper.assertContains(expectedMessages, rWithNoSession.getStatusMessage());
    ______TS("Typical case: student has profile but no records");
    testStudent.googleId = "valid.no.sessions";
    StudentsLogic.inst().updateStudentCascadeWithoutDocument(testStudent.email, testStudent);
    logic.createAccount(testStudent.googleId, testStudent.name, false, testStudent.email, "valid institute");
    a = getAction(submissionParamsWithNoSession);
    r = getShowPageResult(a);
    AssertHelper.assertContains("No records were found for this student", r.getStatusMessage());
    ______TS("Typical case: student has profile with script injection");
    instructor = typicalBundle.instructors.get("instructor1OfTestingSanitizationCourse");
    instructorId = instructor.googleId;
    String studentId = "student1InTestingSanitizationCourse";
    student = typicalBundle.students.get(studentId);
    expectedProfile = typicalBundle.accounts.get(studentId).studentProfile;
    gaeSimulation.loginAsInstructor(instructorId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    actualData = (InstructorStudentRecordsPageData) r.data;
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, instructorId), r.getDestinationWithParams());
    assertFalse(r.isError);
    expectedLogMessage = "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage" + "|||true|||Instructor|||Instructor&lt;script&gt; alert(&#39;hi!&#39;); &lt;&#x2f;script&gt;" + "|||" + instructorId + "|||instructor1@sanitization.tmt|||instructorStudentRecords Page Load<br>" + "Viewing <span class=\"bold\">" + student.email + "'s</span> records " + "for Course <span class=\"bold\">[" + instructor.courseId + "]</span><br>" + "Number of sessions: 1<br>" + "Student Profile: " + SanitizationHelper.sanitizeForHtmlTag(expectedProfile.toString()) + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorStudentRecordsPageAction(teammates.ui.controller.InstructorStudentRecordsPageAction) RedirectResult(teammates.ui.controller.RedirectResult) ArrayList(java.util.ArrayList) InstructorStudentRecordsPageData(teammates.ui.pagedata.InstructorStudentRecordsPageData) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 2 with RedirectResult

use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.

the class StudentCourseDetailsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String idOfCourseOfStudent = student1InCourse1.course;
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, idOfCourseOfStudent };
    ______TS("Invalid parameters");
    // parameters missing.
    verifyAssumptionFailure(new String[] {});
    ______TS("Typical case, student in the same course");
    StudentCourseDetailsPageAction pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_COURSE_DETAILS, false, "student1InCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    StudentCourseDetailsPageData pageData = (StudentCourseDetailsPageData) pageResult.data;
    assertEquals(student1InCourse1.course, pageData.getStudentCourseDetailsPanel().getCourseId());
    assertEquals(student1InCourse1.googleId, pageData.account.googleId);
    assertEquals(student1InCourse1.getIdentificationString(), pageData.student.getIdentificationString());
    assertEquals(student1InCourse1.team, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    List<StudentAttributes> expectedStudentsList = StudentsLogic.inst().getStudentsForTeam(student1InCourse1.team, student1InCourse1.course);
    List<StudentAttributes> actualStudentsList = pageData.getStudentCourseDetailsPanel().getTeammates();
    AssertHelper.assertSameContentIgnoreOrder(expectedStudentsList, actualStudentsList);
    // assertEquals(StudentsLogic.inst().getStudentsForTeam(student1InCourse1.team, student1InCourse1), pageData.);
    // above comparison method failed, so use the one below
    List<InstructorAttributes> expectedInstructorsList = InstructorsLogic.inst().getInstructorsForCourse(student1InCourse1.course);
    List<InstructorAttributes> actualInstructorsList = pageData.getStudentCourseDetailsPanel().getInstructors();
    AssertHelper.assertSameContentIgnoreOrder(expectedInstructorsList, actualInstructorsList);
    String expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||Student 1 in course 1|||student1InCourse1|||" + "student1InCourse1@gmail.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTypicalCourse1] " + "Typical Course 1 with 2 Evals</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
    ______TS("Typical case, the student is not in the course");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "idOfTypicalCourse2" };
    StudentCourseDetailsPageAction redirectAction = getAction(submissionParams);
    RedirectResult redirectResult = this.getRedirectResult(redirectAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, true, "student1InCourse1"), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You are not registered in the course idOfTypicalCourse2", redirectResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||Student 1 in course 1|||student1InCourse1|||" + "student1InCourse1@gmail.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTypicalCourse1] " + "Typical Course 1 with 2 Evals</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
    ______TS("Typical case, student contains data requiring sanitization");
    StudentAttributes studentTestingSanitization = typicalBundle.students.get("student1InTestingSanitizationCourse");
    gaeSimulation.loginAsStudent(studentTestingSanitization.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, studentTestingSanitization.course };
    pageAction = getAction(submissionParams);
    pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_COURSE_DETAILS + "?error=false&user=" + studentTestingSanitization.googleId, pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||" + SanitizationHelper.sanitizeForHtml("Stud1<script> alert('hi!'); </script>") + "|||student1InTestingSanitizationCourse|||" + "normal@sanitization.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTestingSanitizationCourse] " + SanitizationHelper.sanitizeForHtml("Testing<script> alert('hi!'); </script>") + "</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentCourseDetailsPageAction(teammates.ui.controller.StudentCourseDetailsPageAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 3 with RedirectResult

use of teammates.ui.controller.RedirectResult 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 4 with RedirectResult

use of teammates.ui.controller.RedirectResult 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 5 with RedirectResult

use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.

the class StudentProfileEditSaveActionTest method testActionInMasqueradeMode.

private void testActionInMasqueradeMode(AccountAttributes student) {
    ______TS("Typical case: masquerade mode");
    gaeSimulation.loginAsAdmin("admin.user");
    String[] submissionParams = createValidParamsForProfile();
    StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
    expectedProfile.googleId = student.googleId;
    StudentProfileEditSaveAction action = getAction(addUserIdToParams(student.googleId, submissionParams));
    RedirectResult result = getRedirectResult(action);
    assertFalse(result.isError);
    assertEquals(Const.StatusMessages.STUDENT_PROFILE_EDITED, result.getStatusMessage());
    AssertHelper.assertContains(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, false, student.googleId), result.getDestinationWithParams());
    verifyLogMessage(student, action, expectedProfile, true);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Aggregations

RedirectResult (teammates.ui.controller.RedirectResult)68 Test (org.testng.annotations.Test)49 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)46 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)27 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 NullPostParameterException (teammates.common.exception.NullPostParameterException)10 ShowPageResult (teammates.ui.controller.ShowPageResult)10 DataBundle (teammates.common.datatransfer.DataBundle)9 StudentProfilePictureEditAction (teammates.ui.controller.StudentProfilePictureEditAction)9 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)8 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)8 InstructorFeedbackQuestionAddAction (teammates.ui.controller.InstructorFeedbackQuestionAddAction)8 InstructorFeedbackQuestionEditAction (teammates.ui.controller.InstructorFeedbackQuestionEditAction)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 FeedbackSessionsDb (teammates.storage.api.FeedbackSessionsDb)5 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)4 TaskWrapper (teammates.common.util.TaskWrapper)4