use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class InstructorFeedbackQuestionAddActionTest method testExecuteAndPostProcessContributionQuestion.
@Test
public void testExecuteAndPostProcessContributionQuestion() {
InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
______TS("Typical case");
FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
String[] params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.OWN_TEAM_MEMBERS_INCLUDING_SELF.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "CONTRIB", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "How much has each team member including yourself, contributed to the project?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "1", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit" };
InstructorFeedbackQuestionAddAction action = getAction(params);
RedirectResult result = getRedirectResult(action);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Team contribution question:</span> " + "How much has each team member including yourself, contributed to the project?" + "|||/page/instructorFeedbackQuestionAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
______TS("Invalid giver case");
params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.OWN_TEAM_MEMBERS_INCLUDING_SELF.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "CONTRIB", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "How much has each team member including yourself, contributed to the project?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "1", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit" };
action = getAction(params);
result = getRedirectResult(action);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, true), result.getDestinationWithParams());
expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Team contribution question:</span> " + "How much has each team member including yourself, contributed to the project?" + "|||/page/instructorFeedbackQuestionAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
assertEquals(Const.FeedbackQuestion.CONTRIB_ERROR_INVALID_FEEDBACK_PATH + "<br>" + Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class InstructorFeedbackQuestionCopyActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
______TS("Not enough parameters");
gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
verifyAssumptionFailure();
// This is commented out as InstructorFeedbackAddAction already assertNotNull using Assumption
// verifyAssumptionFailure(Const.ParamsNames.COURSE_ID, instructor1ofCourse1.courseId);
______TS("Typical case");
FeedbackSessionAttributes session1 = typicalBundle.feedbackSessions.get("session1InCourse1");
FeedbackQuestionAttributes question1 = FeedbackQuestionsLogic.inst().getFeedbackQuestion(session1.getFeedbackSessionName(), session1.getCourseId(), 1);
FeedbackQuestionAttributes question2 = FeedbackQuestionsLogic.inst().getFeedbackQuestion(session1.getFeedbackSessionName(), session1.getCourseId(), 2);
String[] params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "Second feedback session", Const.ParamsNames.COURSE_ID, "idOfTypicalCourse1", Const.ParamsNames.FEEDBACK_SESSION_NAME + "-0", question1.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID + "-0", question1.getCourseId(), Const.ParamsNames.FEEDBACK_QUESTION_ID + "-0", question1.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME + "-1", question2.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID + "-1", question2.getCourseId(), Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", question2.getId() };
InstructorFeedbackQuestionCopyAction a = getAction(params);
RedirectResult rr = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "Second+feedback+session", instructor1ofCourse1.googleId, false), rr.getDestinationWithParams());
String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionCopy|||" + "instructorFeedbackQuestionCopy|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:" + "<span class=\"bold\">(Second feedback session)" + "</span> for Course <span class=\"bold\">[idOfTypicalCourse1]</span> " + "created.<br><span class=\"bold\">" + "Essay question:</span> What is the best selling point of your product?" + "Created Feedback Question for " + "Feedback Session:<span class=\"bold\">(Second feedback session)</span> " + "for Course <span class=\"bold\">" + "[idOfTypicalCourse1]</span> created.<br>" + "<span class=\"bold\">Essay question:</span> Rate 1 other student's " + "product|||/page/instructorFeedbackQuestionCopy";
AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
______TS("Question text requires sanitization");
FeedbackSessionAttributes sanitizationSession = typicalBundle.feedbackSessions.get("session1InTestingSanitizationCourse");
question1 = FeedbackQuestionsLogic.inst().getFeedbackQuestion(sanitizationSession.getFeedbackSessionName(), sanitizationSession.getCourseId(), 1);
params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "Second feedback session", Const.ParamsNames.COURSE_ID, "idOfTypicalCourse1", Const.ParamsNames.FEEDBACK_QUESTION_ID + "-0", question1.getId() };
a = getAction(params);
rr = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "Second+feedback+session", instructor1ofCourse1.googleId, false), rr.getDestinationWithParams());
expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionCopy|||" + "instructorFeedbackQuestionCopy|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:" + "<span class=\"bold\">(Second feedback session)" + "</span> for Course <span class=\"bold\">[idOfTypicalCourse1]</span> " + "created.<br><span class=\"bold\">" + "Essay question:</span> " + "Testing quotation marks '" " + "Testing unclosed tags </td></div> " + "Testing script injection <script> alert('hello'); </script>" + "|||/page/instructorFeedbackQuestionCopy";
AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
______TS("Error: Indicate no questions to be copied");
params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "Second feedback session", Const.ParamsNames.COURSE_ID, "idOfTypicalCourse1" };
a = getAction(params);
rr = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "Second+feedback+session", instructor1ofCourse1.googleId, true), rr.getDestinationWithParams());
expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionCopy|||" + "instructorFeedbackQuestionCopy|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "|||/page/instructorFeedbackQuestionCopy";
AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
______TS("Masquerade mode");
FeedbackQuestionAttributes question3 = FeedbackQuestionsLogic.inst().getFeedbackQuestion(session1.getFeedbackSessionName(), session1.getCourseId(), 3);
String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "Second feedback session", Const.ParamsNames.COURSE_ID, "idOfTypicalCourse1", Const.ParamsNames.FEEDBACK_SESSION_NAME + "-0", question3.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID + "-0", question3.getCourseId(), Const.ParamsNames.FEEDBACK_QUESTION_ID + "-0", question3.getId() };
params = addUserIdToParams(instructor1ofCourse1.googleId, params);
a = getAction(params);
rr = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "Second+feedback+session", instructor1ofCourse1.googleId, false), rr.getDestinationWithParams());
expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionCopy|||" + "instructorFeedbackQuestionCopy|||true|||" + "Instructor(M)|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:" + "<span class=\"bold\">(Second feedback session)</span> " + "for Course <span class=\"bold\">[idOfTypicalCourse1]</span> " + "created.<br><span class=\"bold\">" + "Essay question:</span> My comments on the class|||" + "/page/instructorFeedbackQuestionCopy";
AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, a.getLogMessage(), adminUserId);
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class InstructorCourseInstructorDeleteActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes loginInstructor = typicalBundle.instructors.get("instructor1OfCourse1");
String loginInstructorId = loginInstructor.googleId;
String courseId = loginInstructor.courseId;
String adminUserId = "admin.user";
gaeSimulation.loginAsInstructor(loginInstructorId);
______TS("Typical case: Delete other instructor successfully, redirect back to edit page");
InstructorAttributes instructorToDelete = typicalBundle.instructors.get("instructor2OfCourse1");
String instructorEmailToDelete = instructorToDelete.email;
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
InstructorCourseInstructorDeleteAction deleteAction = getAction(submissionParams);
RedirectResult redirectResult = getRedirectResult(deleteAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, redirectResult.getStatusMessage());
assertFalse(instructorsLogic.isEmailOfInstructorOfCourse(instructorEmailToDelete, courseId));
String expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
______TS("Success: delete own instructor role from course, redirect back to courses page");
instructorEmailToDelete = loginInstructor.email;
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
deleteAction = getAction(submissionParams);
redirectResult = getRedirectResult(deleteAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, redirectResult.getStatusMessage());
assertFalse(instructorsLogic.isGoogleIdOfInstructorOfCourse(loginInstructor.googleId, courseId));
expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
______TS("Masquerade mode: delete instructor failed due to last instructor in course");
instructorToDelete = typicalBundle.instructors.get("instructor4");
instructorEmailToDelete = instructorToDelete.email;
courseId = instructorToDelete.courseId;
gaeSimulation.loginAsAdmin(adminUserId);
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
deleteAction = getAction(addUserIdToParams(instructorToDelete.googleId, submissionParams));
redirectResult = getRedirectResult(deleteAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, "idOfInstructor4", "idOfCourseNoEvals"), redirectResult.getDestinationWithParams());
assertTrue(redirectResult.isError);
assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETE_NOT_ALLOWED, redirectResult.getStatusMessage());
assertTrue(instructorsLogic.isGoogleIdOfInstructorOfCourse(instructorToDelete.googleId, courseId));
expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> could not be deleted " + "as there is only one instructor left to be able to modify instructors.<br>";
AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class InstructorCourseInstructorEditSaveActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructorToEdit = typicalBundle.instructors.get("instructor1OfCourse1");
String instructorId = instructorToEdit.googleId;
String courseId = instructorToEdit.courseId;
String adminUserId = "admin.user";
gaeSimulation.loginAsInstructor(instructorId);
______TS("Typical case: edit instructor successfully");
String newInstructorName = "newName";
String newInstructorEmail = "newEmail@email.com";
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER };
InstructorCourseInstructorEditSaveAction saveAction = getAction(submissionParams);
RedirectResult redirectResult = getRedirectResult(saveAction);
AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_EDITED, newInstructorName), redirectResult.getStatusMessage());
InstructorAttributes editedInstructor = instructorsLogic.getInstructorForGoogleId(courseId, instructorId);
assertEquals(newInstructorName, editedInstructor.name);
assertEquals(newInstructorEmail, editedInstructor.email);
assertTrue(editedInstructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
assertTrue(editedInstructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
assertTrue(editedInstructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
assertTrue(editedInstructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
String expectedLogSegment = "Instructor <span class=\"bold\"> " + newInstructorName + "</span>" + " for Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Name: " + newInstructorName + "<br>New Email: " + newInstructorEmail;
AssertHelper.assertContains(expectedLogSegment, saveAction.getLogMessage());
______TS("Failure case: edit failed due to invalid parameters");
String invalidEmail = "wrongEmail.com";
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_NAME, instructorToEdit.name, Const.ParamsNames.INSTRUCTOR_EMAIL, invalidEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
saveAction = getAction(submissionParams);
redirectResult = getRedirectResult(saveAction);
AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.getDestinationWithParams());
assertTrue(redirectResult.isError);
String expectedErrorMessage = new FieldValidator().getInvalidityInfoForEmail(invalidEmail);
assertEquals(expectedErrorMessage, redirectResult.getStatusMessage());
AssertHelper.assertContains(expectedErrorMessage, saveAction.getLogMessage());
______TS("Masquerade mode: edit instructor successfully");
gaeSimulation.loginAsAdmin(adminUserId);
newInstructorName = "newName2";
newInstructorEmail = "newEmail2@email.com";
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
saveAction = getAction(addUserIdToParams(instructorId, submissionParams));
redirectResult = getRedirectResult(saveAction);
AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_EDITED, newInstructorName), redirectResult.getStatusMessage());
editedInstructor = instructorsLogic.getInstructorForGoogleId(courseId, instructorId);
assertEquals(newInstructorEmail, editedInstructor.email);
assertEquals(newInstructorName, editedInstructor.name);
expectedLogSegment = "Instructor <span class=\"bold\"> " + newInstructorName + "</span>" + " for Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Name: " + newInstructorName + "<br>New Email: " + newInstructorEmail;
AssertHelper.assertContains(expectedLogSegment, saveAction.getLogMessage());
// remove the new instructor entity that was created
CoursesLogic.inst().deleteCourseCascade("icieat.courseId");
______TS("Unsuccessful case: test null course id parameter");
submissionParams = new String[] { Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
try {
saveAction = getAction(submissionParams);
getRedirectResult(saveAction);
} catch (NullPostParameterException e) {
assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), e.getMessage());
}
______TS("Unsuccessful case: test null instructor name parameter");
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
try {
saveAction = getAction(submissionParams);
getRedirectResult(saveAction);
} catch (NullPostParameterException e) {
assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.INSTRUCTOR_NAME), e.getMessage());
}
______TS("Unsuccessful case: test null instructor email parameter");
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_ID, instructorId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
try {
saveAction = getAction(submissionParams);
getRedirectResult(saveAction);
} catch (NullPostParameterException e) {
assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.INSTRUCTOR_EMAIL), e.getMessage());
}
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class InstructorCourseJoinActionTest method testExecuteAndPostProcess.
@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
InstructorsDb instrDb = new InstructorsDb();
// Reassign to let "key" variable in "instructor" not to be null
instructor = instrDb.getInstructorForGoogleId(instructor.courseId, instructor.googleId);
String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
gaeSimulation.loginAsInstructor(instructor.googleId);
______TS("Invalid key, redirect for confirmation again");
String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
InstructorCourseJoinAction confirmAction = getAction(submissionParams);
ShowPageResult pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "idOfInstructor1OfCourse1", invalidEncryptedKey), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
String expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + invalidEncryptedKey;
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Already registered instructor, redirect straight to authentication page");
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
confirmAction = getAction(submissionParams);
RedirectResult redirectResult = getRedirectResult(confirmAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN_AUTHENTICATED, StringHelper.encrypt(instructor.key), false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals("", redirectResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(instructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Typical case: unregistered instructor, redirect to confirmation page");
instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAT.instr@email.com").build();
InstructorsLogic.inst().createInstructor(instructor);
instructor.googleId = "ICJAT.instr";
AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
AccountsLogic.inst().createAccount(newInstructorAccount);
InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
gaeSimulation.loginUser(instructor.googleId);
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
confirmAction = getAction(submissionParams);
pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "ICJAT.instr", StringHelper.encrypt(newInstructor.key)), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(newInstructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
}
Aggregations