Search in sources :

Example 1 with InstructorCourseDeleteAction

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

the class InstructorCourseDeleteActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case, 2 courses, redirect to homepage");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id1", "New course", "UTC");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_HOME_PAGE };
    assertTrue(CoursesLogic.inst().isCoursePresent("icdct.tpa.id1"));
    InstructorCourseDeleteAction deleteAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course idOfTypicalCourse1 has been deleted.", redirectResult.getStatusMessage());
    List<CourseAttributes> courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(1, courseList.size());
    assertEquals("icdct.tpa.id1", courseList.get(0).getId());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Course deleted: idOfTypicalCourse1|||" + "/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, deleteAction.getLogMessage());
    ______TS("Masquerade mode, delete last course, redirect to Courses page");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id1", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id1 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id1|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
    ______TS("Masquerade mode, delete last course, no next URL, redirect to Courses page");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id2", "New course", "UTC");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id2" };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id2 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id2|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseDeleteAction(teammates.ui.controller.InstructorCourseDeleteAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 InstructorCourseDeleteAction (teammates.ui.controller.InstructorCourseDeleteAction)1 RedirectResult (teammates.ui.controller.RedirectResult)1