Search in sources :

Example 66 with RedirectResult

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

the class InstructorCourseArchiveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    String[] submissionParams = new String[] {};
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    verifyAssumptionFailure(Const.ParamsNames.COURSE_ID, courseId);
    verifyAssumptionFailure(Const.ParamsNames.COURSE_ARCHIVE_STATUS, "true");
    ______TS("Typical case: archive a course, redirect to homepage");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "true", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_HOME_PAGE };
    InstructorCourseArchiveAction archiveAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(archiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_ARCHIVED_FROM_HOMEPAGE, courseId), redirectResult.getStatusMessage());
    String expectedLogSegment = "Course archived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, archiveAction.getLogMessage());
    ______TS("Rare case: archive an already archived course, redirect to homepage");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "true", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_HOME_PAGE };
    archiveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(archiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_ARCHIVED_FROM_HOMEPAGE, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "Course archived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, archiveAction.getLogMessage());
    ______TS("Typical case: unarchive a course, redirect to Courses page");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "false", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    InstructorCourseArchiveAction unarchiveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(unarchiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_UNARCHIVED, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "Course unarchived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, unarchiveAction.getLogMessage());
    ______TS("Rare case: unarchive an active course, redirect to Courses page");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "false", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    unarchiveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(unarchiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_UNARCHIVED, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "Course unarchived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, unarchiveAction.getLogMessage());
    ______TS("Rare case: unarchive an active course, no next URL, redirect to Courses page");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "false" };
    unarchiveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(unarchiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_UNARCHIVED, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "Course unarchived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, unarchiveAction.getLogMessage());
    ______TS("Masquerade mode: archive course, redirect to Courses page");
    gaeSimulation.loginAsAdmin("admin.user");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.COURSE_ARCHIVE_STATUS, "true", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    archiveAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(archiveAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_ARCHIVED, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "Course archived: " + courseId;
    AssertHelper.assertContains(expectedLogSegment, archiveAction.getLogMessage());
    ______TS("Rare case: empty course ID");
    gaeSimulation.loginAsAdmin("admin.user");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "", Const.ParamsNames.COURSE_ARCHIVE_STATUS, "true", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    archiveAction = getAction(addUserIdToParams(instructorId, submissionParams));
    try {
        redirectResult = getRedirectResult(archiveAction);
        signalFailureToDetectException(" - IllegalArgumentException");
    } catch (Exception e) {
        AssertHelper.assertContains("name cannot be null or empty", e.getMessage());
    }
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_ARCHIVED, courseId), redirectResult.getStatusMessage());
    expectedLogSegment = "TEAMMATESLOG|||instructorCourseArchive|||instructorCourseArchive|||true|||" + "Instructor(M)|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Unknown|||/page/instructorCourseArchive";
    AssertHelper.assertContains(expectedLogSegment, archiveAction.getLogMessage());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorCourseArchiveAction(teammates.ui.controller.InstructorCourseArchiveAction) Test(org.testng.annotations.Test)

Example 67 with RedirectResult

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

the class InstructorCourseEditSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor.googleId;
    String courseId = instructor.courseId;
    String courseName = CoursesLogic.inst().getCourse(courseId).getName();
    String courseTimeZone = "UTC";
    String statusMessage = "";
    String[] submissionParams;
    InstructorCourseEditSaveAction courseEditSaveAction;
    RedirectResult redirectResult;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case: edit course name with same name");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseName, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    // get updated results and compare
    statusMessage = Const.StatusMessages.COURSE_EDITED;
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, false, instructorId, courseId), redirectResult.getDestinationWithParams());
    ______TS("Typical case: edit course name with valid characters");
    String courseNameWithValidCharacters = courseName + " valid";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseNameWithValidCharacters, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    // get updated results and compare
    statusMessage = Const.StatusMessages.COURSE_EDITED;
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, false, instructorId, courseId), redirectResult.getDestinationWithParams());
    ______TS("Failure case: edit course name with empty string");
    courseName = "";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseName, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    // get updated results and compare
    statusMessage = getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.COURSE_NAME_FIELD_NAME, FieldValidator.COURSE_NAME_MAX_LENGTH);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, instructorId, courseId), redirectResult.getDestinationWithParams());
    ______TS("Failure case: edit course name with non-alphanumeric start character");
    courseName = "@#$@#$";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseName, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    // get updated results and compare
    statusMessage = getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, courseName, FieldValidator.COURSE_NAME_FIELD_NAME, FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, instructorId, courseId), redirectResult.getDestinationWithParams());
    ______TS("Failure case: edit course name with name containing | and %");
    courseName = "normal|name%";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseName, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    // get updated results and compare
    statusMessage = getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, courseName, FieldValidator.COURSE_NAME_FIELD_NAME, FieldValidator.REASON_CONTAINS_INVALID_CHAR);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, instructorId, courseId), redirectResult.getDestinationWithParams());
    ______TS("Failure case: invalid time zone");
    courseName = CoursesLogic.inst().getCourse(courseId).getName();
    courseTimeZone = "InvalidTimeZone";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.COURSE_NAME, courseName, Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone };
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);
    statusMessage = getPopulatedErrorMessage(FieldValidator.TIME_ZONE_ERROR_MESSAGE, courseTimeZone, FieldValidator.TIME_ZONE_FIELD_NAME, FieldValidator.REASON_UNAVAILABLE_AS_CHOICE);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, instructorId, courseId), redirectResult.getDestinationWithParams());
}
Also used : InstructorCourseEditSaveAction(teammates.ui.controller.InstructorCourseEditSaveAction) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 68 with RedirectResult

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

the class AdminAccountDeletePageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    ______TS("success: delete entire account");
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.INSTRUCTOR_ID, instructor1OfCourse1.googleId, "account", "true" };
    final String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    AdminAccountDeleteAction deleteAction = getAction(submissionParams);
    RedirectResult result = getRedirectResult(deleteAction);
    assertNull(AccountsLogic.inst().getAccount(instructor1OfCourse1.googleId));
    assertEquals(Const.StatusMessages.INSTRUCTOR_ACCOUNT_DELETED, result.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.ADMIN_ACCOUNT_MANAGEMENT_PAGE, false, adminUserId), result.getDestinationWithParams());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) AdminAccountDeleteAction(teammates.ui.controller.AdminAccountDeleteAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

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