Search in sources :

Example 1 with InstructorCourseEditPageAction

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

the class InstructorCourseEditPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case: open the course edit page");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId };
    InstructorCourseEditPageAction editAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    InstructorCourseEditPageData data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
    String expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Typical case: open the course edit page with instructor's email");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, "instr1@course1.tmt", Const.ParamsNames.COURSE_EDIT_MAIN_INDEX, "1" };
    editAction = getAction(submissionParams);
    pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    assertEquals(1, data.getInstructorPanelList().size());
    expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Masquerade mode");
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor4");
    instructorId = instructor.googleId;
    courseId = instructor.courseId;
    gaeSimulation.loginAsAdmin("admin.user");
    submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
    editAction = getAction(submissionParams);
    pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor4"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
    expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Failure case: edit a non-existing course");
    CoursesLogic.inst().deleteCourseCascade(courseId);
    submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
    try {
        editAction = getAction(submissionParams);
        pageResult = getShowPageResult(editAction);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException e) {
        assertEquals("Trying to access system using a non-existent instructor entity", e.getMessage());
    }
}
Also used : InstructorCourseEditPageAction(teammates.ui.controller.InstructorCourseEditPageAction) ShowPageResult(teammates.ui.controller.ShowPageResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) InstructorCourseEditPageData(teammates.ui.pagedata.InstructorCourseEditPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)1 InstructorCourseEditPageAction (teammates.ui.controller.InstructorCourseEditPageAction)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 InstructorCourseEditPageData (teammates.ui.pagedata.InstructorCourseEditPageData)1