use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class StudentFeedbackSubmissionEditSaveActionTest method testGracePeriodExecuteAndPostProcess.
@Test
public void testGracePeriodExecuteAndPostProcess() throws Exception {
FeedbackSessionsDb feedbackSessionDb = new FeedbackSessionsDb();
FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("gracePeriodSession");
StudentAttributes studentInGracePeriod = typicalBundle.students.get("student1InCourse1");
gaeSimulation.loginAsStudent(studentInGracePeriod.googleId);
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName() };
______TS("opened");
fs.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(1));
feedbackSessionDb.updateFeedbackSession(fs);
assertTrue(fs.isOpened());
assertFalse(fs.isInGracePeriod());
StudentFeedbackSubmissionEditSaveAction a = getAction(submissionParams);
RedirectResult r = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT_PAGE, r.isError, "student1InCourse1", "idOfTypicalCourse1", "Grace+Period+Session"), r.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
assertFalse(r.isError);
______TS("during grace period");
fs.setEndTime(Instant.now());
feedbackSessionDb.updateFeedbackSession(fs);
assertFalse(fs.isOpened());
assertTrue(fs.isInGracePeriod());
a = getAction(submissionParams);
r = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT_PAGE, r.isError, "student1InCourse1", "idOfTypicalCourse1", "Grace+Period+Session"), r.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
assertFalse(r.isError);
______TS("after grace period");
fs.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(-10));
feedbackSessionDb.updateFeedbackSession(fs);
assertFalse(fs.isOpened());
assertFalse(fs.isInGracePeriod());
a = getAction(submissionParams);
r = getRedirectResult(a);
assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, r.getStatusMessage());
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class StudentProfileEditSaveActionTest method testActionSuccess.
private void testActionSuccess(AccountAttributes student, String caseDescription) {
String[] submissionParams = createValidParamsForProfile();
StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
gaeSimulation.loginAsStudent(student.googleId);
______TS(caseDescription);
StudentProfileEditSaveAction action = getAction(submissionParams);
RedirectResult result = getRedirectResult(action);
expectedProfile.googleId = student.googleId;
assertFalse(result.isError);
AssertHelper.assertContains(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, false, student.googleId), result.getDestinationWithParams());
assertEquals(Const.StatusMessages.STUDENT_PROFILE_EDITED, result.getStatusMessage());
verifyLogMessage(student, action, expectedProfile, false);
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class StudentProfileEditSaveActionTest method testActionWithInvalidParameters.
private void testActionWithInvalidParameters(AccountAttributes student) throws Exception {
gaeSimulation.loginAsStudent(student.googleId);
______TS("Failure case: invalid parameters");
String[] submissionParams = createInvalidParamsForProfile();
StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
expectedProfile.googleId = student.googleId;
StudentProfileEditSaveAction action = getAction(submissionParams);
RedirectResult result = getRedirectResult(action);
assertTrue(result.isError);
AssertHelper.assertContains(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, true, student.googleId), result.getDestinationWithParams());
List<String> expectedErrorMessages = new ArrayList<>();
expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, submissionParams[1], FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR, FieldValidator.PERSON_NAME_MAX_LENGTH));
expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, submissionParams[3], FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH));
AssertHelper.assertContains(expectedErrorMessages, result.getStatusMessage());
String expectedLogMessage = "TEAMMATESLOG|||studentProfileEditSave|||studentProfileEditSave" + "|||true|||Student|||" + student.name + "|||" + student.googleId + "|||" + student.email + "|||" + Const.ACTION_RESULT_FAILURE + " : " + result.getStatusMessage() + "|||/page/studentProfileEditSave";
AssertHelper.assertContainsRegex(expectedLogMessage, action.getLogMessage());
______TS("Failure case: invalid parameters with attempted script injection");
submissionParams = createInvalidParamsForProfileWithScriptInjection();
expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
expectedProfile.googleId = student.googleId;
action = getAction(submissionParams);
result = getRedirectResult(action);
assertTrue(result.isError);
AssertHelper.assertContains(Const.ActionURIs.STUDENT_PROFILE_PAGE + "?error=true&user=" + student.googleId, result.getDestinationWithParams());
expectedErrorMessages = new ArrayList<>();
expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[1]), FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.REASON_CONTAINS_INVALID_CHAR, FieldValidator.PERSON_NAME_MAX_LENGTH));
expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[3]), FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH));
expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[5]), FieldValidator.INSTITUTE_NAME_FIELD_NAME, FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR, FieldValidator.INSTITUTE_NAME_MAX_LENGTH));
expectedErrorMessages.add(String.format(FieldValidator.NATIONALITY_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[7])));
expectedErrorMessages.add(String.format(FieldValidator.GENDER_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[9])));
AssertHelper.assertContains(expectedErrorMessages, result.getStatusMessage());
expectedLogMessage = "TEAMMATESLOG|||studentProfileEditSave|||studentProfileEditSave" + "|||true|||Student|||" + student.name + "|||" + student.googleId + "|||" + student.email + "|||" + Const.ACTION_RESULT_FAILURE + " : " + result.getStatusMessage() + "|||/page/studentProfileEditSave";
AssertHelper.assertContainsRegex(expectedLogMessage, action.getLogMessage());
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class StudentProfilePictureEditActionTest method testActionForEmptyTopY.
private void testActionForEmptyTopY(AccountAttributes student) {
______TS("Failure case: empty parameter - topy");
String expectedLogMessage = getExpectedLogMessageEmptyCoords(student);
String expectedUrl = getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, true, student.googleId);
String[] submissionParams = createValidParamsForProfilePictureEdit();
submissionParams[5] = "";
StudentProfilePictureEditAction action = getAction(submissionParams);
RedirectResult result = getRedirectResult(action);
AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
assertEquals(expectedUrl, result.getDestinationWithParams());
}
use of teammates.ui.controller.RedirectResult in project teammates by TEAMMATES.
the class StudentProfilePictureEditActionTest method testActionForNonExistentBlobKey.
private void testActionForNonExistentBlobKey(AccountAttributes student) {
______TS("Failure case: non-existent blobKey");
String expectedUrl = getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, true, student.googleId);
String[] submissionParams = createValidParamsForProfilePictureEdit();
StudentProfilePictureEditAction action = getAction(submissionParams);
RedirectResult result = getRedirectResult(action);
String expectedLogMessage = getExpectedLogMessageNonExistentBlob(student);
AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
assertEquals(expectedUrl, result.getDestinationWithParams());
}
Aggregations