Search in sources :

Example 36 with RedirectResult

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());
}
Also used : FeedbackSessionsDb(teammates.storage.api.FeedbackSessionsDb) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) RedirectResult(teammates.ui.controller.RedirectResult) StudentFeedbackSubmissionEditSaveAction(teammates.ui.controller.StudentFeedbackSubmissionEditSaveAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Example 37 with RedirectResult

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);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 38 with RedirectResult

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());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) ArrayList(java.util.ArrayList) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 39 with RedirectResult

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());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentProfilePictureEditAction(teammates.ui.controller.StudentProfilePictureEditAction)

Example 40 with RedirectResult

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());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentProfilePictureEditAction(teammates.ui.controller.StudentProfilePictureEditAction)

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