Search in sources :

Example 21 with RedirectResult

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

the class InstructorFeedbackQuestionAddActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] params = { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName() };
    verifyAssumptionFailure(params);
    ______TS("Empty questionText");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "");
    verifyAssumptionFailure(params);
    ______TS("Invalid questionNumber");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    // change questionNumber to invalid number
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "0");
    verifyAssumptionFailure(params);
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    // change questionNumber to invalid number
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "-1");
    verifyAssumptionFailure(params);
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    // change questionNumber to invalid "number"
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "ABC");
    try {
        InstructorFeedbackQuestionAddAction c = getAction(params);
        c.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (NumberFormatException e) {
        ignoreExpectedException();
    }
    ______TS("Non-existent Enumeration");
    params = createParamsForTypicalFeedbackQuestion(instructor1ofCourse1.courseId, fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, "NON_EXISTENT_ENUMERATION");
    try {
        InstructorFeedbackQuestionAddAction c = getAction(params);
        c.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (IllegalArgumentException e) {
        ignoreExpectedException();
    }
    params = createParamsForTypicalFeedbackQuestion(instructor1ofCourse1.courseId, fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, "NON_EXISTENT_ENUMERATION");
    try {
        InstructorFeedbackQuestionAddAction c = getAction(params);
        c.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (IllegalArgumentException e) {
        ignoreExpectedException();
    }
    params = createParamsForTypicalFeedbackQuestion(instructor1ofCourse1.courseId, fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "NON_EXISTENT_ENUMERATION");
    try {
        InstructorFeedbackQuestionAddAction c = getAction(params);
        c.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (IllegalArgumentException e) {
        ignoreExpectedException();
    }
    ______TS("Typical case");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    // change number of feedback to give to unlimited
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max");
    InstructorFeedbackQuestionAddAction action = getAction(params);
    RedirectResult result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Custom number of students to give feedback to");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Custom number of teams to give feedback to");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, "TEAMS");
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Remnant custom number of entities when recipient is changed to non-student and non-team");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, "INSTRUCTORS");
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Question text requires sanitization");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "attempted html injection '\"/>");
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "attempted html injection &#39;&quot;&#x2f;&gt;|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Failure: Empty or null participant lists");
    params = createParamsForTypicalFeedbackQuestion(fs.getCourseId(), fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "");
    // Purposely not using modifyParamVale because we're removing showRecipientTo
    params[22] = Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE;
    params[23] = "edit";
    params = Arrays.copyOf(params, 24);
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    ______TS("Failure: Invalid Parameter");
    params = createParamsForTypicalFeedbackQuestion(instructor1ofCourse1.courseId, fs.getFeedbackSessionName());
    modifyParamValue(params, Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, "NONE");
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, true), result.getDestinationWithParams());
    assertEquals("NONE is not a valid feedback giver.", result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + String.format(FieldValidator.PARTICIPANT_TYPE_ERROR_MESSAGE, "NONE", FieldValidator.GIVER_TYPE_NAME) + "|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Masquerade mode");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    params = createParamsForTypicalFeedbackQuestion(instructor1ofCourse1.courseId, fs.getFeedbackSessionName());
    params = addUserIdToParams(instructor1ofCourse1.googleId, params);
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor(M)|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Essay question:</span> " + "question|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, action.getLogMessage(), adminUserId);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackQuestionAddAction(teammates.ui.controller.InstructorFeedbackQuestionAddAction) Test(org.testng.annotations.Test)

Example 22 with RedirectResult

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

the class InstructorFeedbackQuestionAddActionTest method testExecuteAndPostProcessNumScale.

@Test
public void testExecuteAndPostProcessNumScale() {
    InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    ______TS("Typical case");
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "NUMSCALE", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Rate the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MIN, "1", Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MAX, "5", Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_STEP, "0.5", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit" };
    InstructorFeedbackQuestionAddAction action = getAction(params);
    RedirectResult result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Numerical-scale question:</span> " + "Rate the class?|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackQuestionAddAction(teammates.ui.controller.InstructorFeedbackQuestionAddAction) Test(org.testng.annotations.Test)

Example 23 with RedirectResult

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

the class InstructorFeedbackQuestionAddActionTest method testExecuteAndPostProcessMsq.

@Test
public void testExecuteAndPostProcessMsq() {
    InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    ______TS("Typical case");
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "5", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-2", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-3", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-4", "The Atmosphere", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    InstructorFeedbackQuestionAddAction action = getAction(params);
    RedirectResult result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd" + "|||instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> " + "for Course <span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (multiple answers) " + "question:</span> What do you like best about the class?" + "|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Generated options");
    params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Who do you like in the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "2", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (multiple answers) question:</span> " + "Who do you like in the class?|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Enable other option");
    params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "3", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Choose all the food you like", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "3", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", "Pizza", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-1", "Pasta", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-2", "Chicken rice", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString(), Const.ParamsNames.FEEDBACK_QUESTION_MSQOTHEROPTIONFLAG, "on" };
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (multiple answers) question:</span> " + "Choose all the food you like|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackQuestionAddAction(teammates.ui.controller.InstructorFeedbackQuestionAddAction) Test(org.testng.annotations.Test)

Example 24 with RedirectResult

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

the class InstructorFeedbackQuestionAddActionTest method testExecuteAndPostProcessMcq.

@Test
public void testExecuteAndPostProcessMcq() {
    InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    ______TS("Typical case");
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "5", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-2", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-3", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-4", "The Atmosphere", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    InstructorFeedbackQuestionAddAction action = getAction(params);
    RedirectResult result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (single answer) " + "question:</span> What do you like best about the class?" + "|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Generated options");
    params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "2", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Who do you like best in the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", // this field defaults to 2
    Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, // this field defaults to 2
    "2", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (single answer) question:</span> " + "Who do you like best in the class?|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
    ______TS("Enable other option");
    params = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "3", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What can be improved for this class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "4", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", "The content", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-1", "Teaching style", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-2", "Tutorial questions", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-3", "Assignments", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "custom", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, "2", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString(), Const.ParamsNames.FEEDBACK_QUESTION_MCQOTHEROPTIONFLAG, "on" };
    action = getAction(params);
    result = getRedirectResult(action);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, instructor1ofCourse1.courseId, "First+feedback+session", instructor1ofCourse1.googleId, false), result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionAdd|||" + "instructorFeedbackQuestionAdd|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Created Feedback Question for Feedback Session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " created.<br><span class=\"bold\">Multiple-choice (single answer) question:</span> " + "What can be improved for this class?|||/page/instructorFeedbackQuestionAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, action.getLogMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackQuestionAddAction(teammates.ui.controller.InstructorFeedbackQuestionAddAction) Test(org.testng.annotations.Test)

Example 25 with RedirectResult

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

the class InstructorCourseStudentDetailsEditSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String newStudentEmail = "newemail@gmail.tmt";
    String newStudentTeam = "new student's team";
    String newStudentComments = "this is new comment after editing";
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid parameters");
    // no parameters
    verifyAssumptionFailure();
    // null student email
    String[] invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    verifyAssumptionFailure(invalidParams);
    // null course id
    invalidParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyAssumptionFailure(invalidParams);
    ______TS("Typical case, successful edit and save student detail");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, newStudentEmail, Const.ParamsNames.COMMENTS, newStudentComments, Const.ParamsNames.TEAM_NAME, newStudentTeam, Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK, "true" };
    InstructorCourseStudentDetailsEditSaveAction a = getAction(submissionParams);
    RedirectResult r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT, r.getStatusMessage());
    verifyNumberOfEmailsSent(a, 1);
    EmailWrapper email = getEmailsSent(a).get(0);
    String courseName = coursesLogic.getCourse(instructor1OfCourse1.courseId).getName();
    assertEquals(String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), courseName, instructor1OfCourse1.courseId), email.getSubject());
    assertEquals(newStudentEmail, email.getRecipient());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + student1InCourse1.email + "'s</span> details in Course <span class=\"bold\">[idOfTypicalCourse1]</span> edited.<br>" + "New Email: " + newStudentEmail + "<br>New Team: " + newStudentTeam + "<br>Comments: " + newStudentComments + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Typical case, successful edit and save student detail with spaces to be trimmed");
    // after trim, this is equal to newStudentEmail
    String newStudentEmailToBeTrimmed = "  newemail@gmail.tmt   ";
    String newStudentTeamToBeTrimmed = "  New team   ";
    String newStudentCommentsToBeTrimmed = "  this is new comment after editing   ";
    String[] submissionParamsToBeTrimmed = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, newStudentEmailToBeTrimmed, Const.ParamsNames.COMMENTS, newStudentCommentsToBeTrimmed, Const.ParamsNames.TEAM_NAME, newStudentTeamToBeTrimmed, Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK, "true" };
    InstructorCourseStudentDetailsEditSaveAction aToBeTrimmed = getAction(submissionParamsToBeTrimmed);
    RedirectResult rToBeTrimmed = getRedirectResult(aToBeTrimmed);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), rToBeTrimmed.getDestinationWithParams());
    assertFalse(rToBeTrimmed.isError);
    assertEquals(Const.StatusMessages.STUDENT_EDITED, rToBeTrimmed.getStatusMessage());
    verifyNoEmailsSent(aToBeTrimmed);
    String expectedLogMessageToBeTrimmed = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + newStudentEmail + "'s</span> details in Course <span class=\"bold\">[idOfTypicalCourse1]</span> edited.<br>" + "New Email: " + newStudentEmailToBeTrimmed.trim() + "<br>New Team: " + newStudentTeamToBeTrimmed.trim() + "<br>Comments: " + newStudentCommentsToBeTrimmed.trim() + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessageToBeTrimmed, aToBeTrimmed.getLogMessage());
    ______TS("Error case, invalid email parameter (email has too many characters)");
    String invalidStudentEmail = StringHelperExtension.generateStringOfLength(255 - "@gmail.tmt".length()) + "@gmail.tmt";
    assertEquals(FieldValidator.EMAIL_MAX_LENGTH + 1, invalidStudentEmail.length());
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, // Use the new email as the previous email have been changed
    Const.ParamsNames.STUDENT_EMAIL, // Use the new email as the previous email have been changed
    newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, invalidStudentEmail, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    ShowPageResult result = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, true, "idOfInstructor1OfCourse1"), result.getDestinationWithParams());
    assertTrue(result.isError);
    assertEquals(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidStudentEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.EMAIL_MAX_LENGTH), result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Servlet Action Failure : " + getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidStudentEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.EMAIL_MAX_LENGTH) + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Error case, invalid email parameter (email already taken by others)");
    StudentAttributes student2InCourse1 = typicalBundle.students.get("student2InCourse1");
    String takenStudentEmail = student2InCourse1.email;
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, // Use the new email as the previous email have been changed
    Const.ParamsNames.STUDENT_EMAIL, // Use the new email as the previous email have been changed
    newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, takenStudentEmail, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    result = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, true, "idOfInstructor1OfCourse1"), result.getDestinationWithParams());
    assertTrue(result.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_EMAIL_TAKEN_MESSAGE, student2InCourse1.name, takenStudentEmail), result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Servlet Action Failure : " + String.format(Const.StatusMessages.STUDENT_EMAIL_TAKEN_MESSAGE, student2InCourse1.name, takenStudentEmail) + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    // deleting edited student
    AccountsLogic.inst().deleteAccountCascade(student2InCourse1.googleId);
    AccountsLogic.inst().deleteAccountCascade(student1InCourse1.googleId);
    ______TS("Error case, student does not exist");
    String nonExistentEmailForStudent = "notinuseemail@gmail.tmt";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, nonExistentEmailForStudent, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, student1InCourse1.email, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, true, instructorId, instructor1OfCourse1.courseId), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, redirectResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + nonExistentEmailForStudent + "</span> in " + "Course <span class=\"bold\">[" + instructor1OfCourse1.courseId + "]</span> not found." + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Unsuccessful case: test null student email parameter");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    try {
        a = getAction(submissionParams);
        r = getRedirectResult(a);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.STUDENT_EMAIL), e.getMessage());
    }
    ______TS("Unsuccessful case: test null course id parameter");
    submissionParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, newStudentEmail };
    try {
        a = getAction(submissionParams);
        r = getRedirectResult(a);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), e.getMessage());
    }
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) NullPostParameterException(teammates.common.exception.NullPostParameterException) RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseStudentDetailsEditSaveAction(teammates.ui.controller.InstructorCourseStudentDetailsEditSaveAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) 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