Search in sources :

Example 1 with InstructorFeedbackEditSaveAction

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

the class InstructorFeedbackEditSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session1InCourse1");
    String expectedString = "";
    ______TS("failure: Not enough parameters");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    verifyAssumptionFailure();
    // TODO make sure IFESA does assertNotNull for required parameters then uncomment
    // verifyAssumptionFailure(Const.ParamsNames.COURSE_ID, instructor1ofCourse1.courseId,
    // Const.ParamsNames.FEEDBACK_SESSION_NAME, session.feedbackSessionName);
    ______TS("success: Typical case");
    String[] params = createParamsForTypicalFeedbackSession(instructor1ofCourse1.courseId, session.getFeedbackSessionName());
    InstructorFeedbackEditSaveAction a = getAction(params);
    AjaxResult ar = getAjaxResult(a);
    InstructorFeedbackEditPageData pageData = (InstructorFeedbackEditPageData) ar.data;
    StatusMessage statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, Const.StatusMessages.FEEDBACK_SESSION_EDITED, StatusMessageColor.SUCCESS);
    assertFalse(pageData.getHasError());
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditSave|||instructorFeedbackEditSave|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Updated Feedback Session " + "<span class=\"bold\">(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span> created.<br>" + "<span class=\"bold\">From:</span> 2012-01-31T16:00:00Z" + "<span class=\"bold\"> to</span> 2014-12-31T16:00:00Z<br>" + "<span class=\"bold\">Session visible from:</span> 2011-12-31T16:00:00Z<br>" + "<span class=\"bold\">Results visible from:</span> 1970-06-22T00:00:00Z<br><br>" + "<span class=\"bold\">Instructions:</span> " + "<Text: instructions>|||/page/instructorFeedbackEditSave";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("failure: Fixed offset time zone");
    params[25] = "UTC+08:00";
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    expectedString = "\"UTC+08:00\" is not acceptable to TEAMMATES as a/an time zone because it is not " + "available as a choice. The value must be one of the values from the time zone dropdown selector.";
    statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, expectedString, StatusMessageColor.DANGER);
    assertTrue(pageData.getHasError());
    ______TS("failure: Invalid parameters");
    params[15] = "Thu, 01 Mar, 2012";
    params[25] = "UTC";
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    expectedString = "The start time for this feedback session cannot be " + "earlier than the time when the session will be visible.";
    statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, expectedString, StatusMessageColor.DANGER);
    assertTrue(pageData.getHasError());
    ______TS("success: Time zone with DST, gap start time, overlap end time");
    params[25] = "Europe/Andorra";
    // After Sun, 25 Mar 2012, 01:59:59 AM: clocks sprang forward to Sun, 25 Mar 2012, 03:00:00 AM
    params[5] = "Sun, 25 Mar, 2012";
    params[7] = "2";
    // After Sun, 28 Oct 2012, 02:59:59 AM: clocks fell back to Sun, 28 Oct 2012, 02:00:00 AM
    params[9] = "Sun, 28 Oct, 2012";
    params[11] = "2";
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    expectedString = String.format(Const.StatusMessages.AMBIGUOUS_LOCAL_DATE_TIME_GAP, "start time", "Sun, 25 Mar 2012, 02:00 AM", "Sun, 25 Mar 2012, 03:00 AM CEST (UTC+0200)");
    verifyStatusMessage(pageData.getStatusMessagesToUser().get(0), expectedString, StatusMessageColor.WARNING);
    expectedString = String.format(Const.StatusMessages.AMBIGUOUS_LOCAL_DATE_TIME_OVERLAP, "end time", "Sun, 28 Oct 2012, 02:00 AM", "Sun, 28 Oct 2012, 02:00 AM CEST (UTC+0200)", "Sun, 28 Oct 2012, 02:00 AM CET (UTC+0100)", "Sun, 28 Oct 2012, 02:00 AM CEST (UTC+0200)");
    verifyStatusMessage(pageData.getStatusMessagesToUser().get(1), expectedString, StatusMessageColor.WARNING);
    expectedString = Const.StatusMessages.FEEDBACK_SESSION_EDITED;
    verifyStatusMessage(pageData.getStatusMessagesToUser().get(2), expectedString, StatusMessageColor.SUCCESS);
    assertFalse(pageData.getHasError());
    ______TS("success: Custom time zone, 'never' show session, 'custom' show results");
    params = createParamsForTypicalFeedbackSession(instructor1ofCourse1.courseId, session.getFeedbackSessionName());
    params[25] = "Asia/Kathmandu";
    params[13] = Const.INSTRUCTOR_FEEDBACK_SESSION_VISIBLE_TIME_NEVER;
    params[19] = Const.INSTRUCTOR_FEEDBACK_RESULTS_VISIBLE_TIME_LATER;
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, Const.StatusMessages.FEEDBACK_SESSION_EDITED, StatusMessageColor.SUCCESS);
    assertFalse(pageData.getHasError());
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditSave|||instructorFeedbackEditSave|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Updated Feedback Session " + "<span class=\"bold\">(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span> created.<br>" + "<span class=\"bold\">From:</span> 2012-01-31T18:15:00Z" + "<span class=\"bold\"> to</span> 2014-12-31T18:15:00Z<br>" + "<span class=\"bold\">Session visible from:</span> 1970-11-27T00:00:00Z<br>" + "<span class=\"bold\">Results visible from:</span> 1970-01-01T00:00:00Z<br><br>" + "<span class=\"bold\">Instructions:</span> " + "<Text: instructions>|||/page/instructorFeedbackEditSave";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("success: At open session visible time, custom results visible time, UTC");
    params = createParamsCombinationForFeedbackSession(instructor1ofCourse1.courseId, session.getFeedbackSessionName(), 1);
    params[25] = "UTC";
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, Const.StatusMessages.FEEDBACK_SESSION_EDITED, StatusMessageColor.SUCCESS);
    assertFalse(pageData.getHasError());
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditSave|||instructorFeedbackEditSave|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Updated Feedback Session " + "<span class=\"bold\">(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span> created.<br>" + "<span class=\"bold\">From:</span> 2012-02-01T00:00:00Z" + "<span class=\"bold\"> to</span> 2015-01-01T00:00:00Z<br>" + "<span class=\"bold\">Session visible from:</span> 1970-12-31T00:00:00Z<br>" + "<span class=\"bold\">Results visible from:</span> 2014-05-08T02:00:00Z<br><br>" + "<span class=\"bold\">Instructions:</span> " + "<Text: instructions>|||/page/instructorFeedbackEditSave";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("success: Masquerade mode, manual release results, UTC");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    params = createParamsForTypicalFeedbackSession(instructor1ofCourse1.courseId, session.getFeedbackSessionName());
    params[19] = Const.INSTRUCTOR_FEEDBACK_RESULTS_VISIBLE_TIME_LATER;
    params[25] = "UTC";
    params = addUserIdToParams(instructor1ofCourse1.googleId, params);
    a = getAction(params);
    ar = getAjaxResult(a);
    pageData = (InstructorFeedbackEditPageData) ar.data;
    statusMessage = pageData.getStatusMessagesToUser().get(0);
    verifyStatusMessage(statusMessage, Const.StatusMessages.FEEDBACK_SESSION_EDITED, StatusMessageColor.SUCCESS);
    assertFalse(pageData.getHasError());
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditSave|||instructorFeedbackEditSave|||true|||" + "Instructor(M)|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Updated Feedback Session " + "<span class=\"bold\">(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span> created.<br>" + "<span class=\"bold\">From:</span> 2012-02-01T00:00:00Z" + "<span class=\"bold\"> to</span> 2015-01-01T00:00:00Z<br>" + "<span class=\"bold\">Session visible from:</span> 2012-01-01T00:00:00Z<br>" + "<span class=\"bold\">Results visible from:</span> 1970-01-01T00:00:00Z<br><br>" + "<span class=\"bold\">Instructions:</span> " + "<Text: instructions>|||/page/instructorFeedbackEditSave";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedString, a.getLogMessage(), adminUserId);
    ______TS("failure: Invalid time zone");
    params[27] = "invalid time zone";
    verifyAssumptionFailure(params);
    ______TS("failure: Null time zone");
    params = ArrayUtils.remove(params, 26);
    params = ArrayUtils.remove(params, 26);
    verifyAssumptionFailure(params);
    ______TS("failure: Invalid grace period");
    params[25] = "12dsf";
    verifyAssumptionFailure(params);
    ______TS("failure: Null grace period");
    params = ArrayUtils.remove(params, 26);
    params = ArrayUtils.remove(params, 26);
    verifyAssumptionFailure(params);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackEditPageData(teammates.ui.pagedata.InstructorFeedbackEditPageData) AjaxResult(teammates.ui.controller.AjaxResult) InstructorFeedbackEditSaveAction(teammates.ui.controller.InstructorFeedbackEditSaveAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 StatusMessage (teammates.common.util.StatusMessage)1 AjaxResult (teammates.ui.controller.AjaxResult)1 InstructorFeedbackEditSaveAction (teammates.ui.controller.InstructorFeedbackEditSaveAction)1 InstructorFeedbackEditPageData (teammates.ui.pagedata.InstructorFeedbackEditPageData)1