Search in sources :

Example 1 with NullPostParameterException

use of teammates.common.exception.NullPostParameterException in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionEditActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    gaeSimulation.loginAsInstructor(typicalBundle.instructors.get("instructor1OfCourse1").googleId);
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    FeedbackQuestionAttributes fq = FeedbackQuestionsLogic.inst().getFeedbackQuestion(fs.getFeedbackSessionName(), fs.getCourseId(), 1);
    ______TS("Typical Case");
    String[] typicalParams = { 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, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", 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_ID, fq.getId() };
    InstructorFeedbackQuestionEditAction a = getAction(typicalParams);
    RedirectResult r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Custom number of recipient");
    String[] customParams = { 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, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", 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_ID, fq.getId() };
    a = getAction(customParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Anonymous Team Session");
    String[] teamParams = { 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.TEAMS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    a = getAction(teamParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Self Feedback");
    String[] selfParams = { 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.SELF.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    a = getAction(selfParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Question text requires sanitization");
    String[] sanitizeParams = { 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.SELF.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "attempted html injection '\"/>", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    a = getAction(sanitizeParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    String expectedLogMessage = "TEAMMATESLOG|||instructorFeedbackQuestionEdit|||" + "instructorFeedbackQuestionEdit|||true|||" + "Instructor|||Instructor 1 of Course 1|||" + "idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Feedback Question 1 for session:<span class=\"bold\">" + "(First feedback session)</span> for Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + " edited.<br><span class=\"bold\">Essay question:</span> " + "attempted html injection &#39;&quot;&#x2f;&gt;|||/page/instructorFeedbackQuestionEdit";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Invalid edit type");
    String[] invalidEditTypeParams = { 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, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), // change to invalid edit type.
    Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, // change to invalid edit type.
    "INVALID", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    verifyAssumptionFailure(invalidEditTypeParams);
    ______TS("Invalid questionNumber");
    String[] invalidQnNumParams = { 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.SELF.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    // change questionNumber to an invalid number
    modifyParamValue(invalidQnNumParams, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "-1");
    verifyAssumptionFailure(invalidQnNumParams);
    // change questionNumber to invalid "number"
    modifyParamValue(invalidQnNumParams, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "ABC");
    try {
        a = getAction(invalidQnNumParams);
        r = getRedirectResult(a);
        signalFailureToDetectException();
    } catch (NumberFormatException e) {
        ignoreExpectedException();
    }
    ______TS("Invalid parameters");
    String[] invalidParams = { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.TEAMS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.OWN_TEAM_MEMBERS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    a = getAction(invalidParams);
    r = getRedirectResult(a);
    assertEquals(String.format(FieldValidator.PARTICIPANT_TYPE_TEAM_ERROR_MESSAGE, FeedbackParticipantType.OWN_TEAM_MEMBERS.toDisplayRecipientName(), FeedbackParticipantType.TEAMS.toDisplayGiverName()), r.getStatusMessage());
    ______TS("Delete Feedback");
    String[] deleteParams = { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, "", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.RECEIVER.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "delete", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
    a = getAction(deleteParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "idOfTypicalCourse1", "First+feedback+session", "idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_DELETED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Unsuccessful case: test null course id parameter");
    String[] submissionParams = new String[] { 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, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", 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_ID, fq.getId() };
    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());
    }
    ______TS("Unsuccessful case: test null course id parameter");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, FeedbackParticipantType.STUDENTS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "TEXT", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "question", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", 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_ID, fq.getId() };
    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.FEEDBACK_SESSION_NAME), e.getMessage());
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) NullPostParameterException(teammates.common.exception.NullPostParameterException) InstructorFeedbackQuestionEditAction(teammates.ui.controller.InstructorFeedbackQuestionEditAction) RedirectResult(teammates.ui.controller.RedirectResult) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Test(org.testng.annotations.Test)

Example 2 with NullPostParameterException

use of teammates.common.exception.NullPostParameterException in project teammates by TEAMMATES.

the class InstructorFeedbackSubmissionEditPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session1InCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("not enough parameters");
    String[] paramsWithoutCourseId = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithoutFeedbackSessionName = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId() };
    verifyAssumptionFailure(paramsWithoutCourseId);
    verifyAssumptionFailure(paramsWithoutFeedbackSessionName);
    ______TS("Test null feedback session name parameter");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.USER_ID, instructor.googleId };
    InstructorFeedbackSubmissionEditPageAction a;
    ShowPageResult r;
    try {
        a = getAction(submissionParams);
        r = getShowPageResult(a);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.FEEDBACK_SESSION_NAME), e.getMessage());
    }
    ______TS("Test null course id parameter");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.USER_ID, instructor.googleId };
    try {
        a = getAction(submissionParams);
        r = getShowPageResult(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());
    }
    ______TS("Test insufficient authorization");
    instructor = typicalBundle.instructors.get("helperOfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.USER_ID, instructor.googleId };
    try {
        a = getAction(submissionParams);
        r = getShowPageResult(a);
        signalFailureToDetectException("Did not detect insufficient authorization.");
    } catch (UnauthorizedAccessException e) {
        assertEquals("Feedback session [First feedback session] is not accessible to instructor " + "[helper@course1.tmt] for this purpose", e.getMessage());
    }
    ______TS("Test feedback session that does not exist");
    instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, "feedback session that does not exist", Const.ParamsNames.USER_ID, instructor.googleId };
    a = getAction(submissionParams);
    RedirectResult rr = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, instructor.googleId), rr.getDestinationWithParams());
    assertFalse(rr.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_DELETED_NO_ACCESS, rr.getStatusMessage());
    ______TS("typical success case");
    String[] params = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.USER_ID, instructor.googleId };
    a = getAction(params);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT, false, instructor.googleId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, r.getStatusMessage());
    ______TS("masquerade mode");
    gaeSimulation.loginAsAdmin("admin.user");
    a = getAction(params);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT, false, instructor.googleId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, r.getStatusMessage());
    ______TS("closed session case");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    session = typicalBundle.feedbackSessions.get("closedSession");
    params = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.USER_ID, instructor.googleId };
    a = getAction(params);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT, false, instructor.googleId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, r.getStatusMessage());
    ______TS("private session case");
    instructor = typicalBundle.instructors.get("instructor1OfCourse2");
    session = typicalBundle.feedbackSessions.get("session1InCourse2");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    params = new String[] { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.USER_ID, instructor.googleId };
    a = getAction(params);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT, false, instructor.googleId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_SUBMISSIONS_CAN_SUBMIT_PARTIAL_ANSWER, r.getStatusMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ShowPageResult(teammates.ui.controller.ShowPageResult) NullPostParameterException(teammates.common.exception.NullPostParameterException) RedirectResult(teammates.ui.controller.RedirectResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackSubmissionEditPageAction(teammates.ui.controller.InstructorFeedbackSubmissionEditPageAction) Test(org.testng.annotations.Test)

Example 3 with NullPostParameterException

use of teammates.common.exception.NullPostParameterException in project teammates by TEAMMATES.

the class InstructorFeedbackSubmissionEditSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    prepareTestData();
    InstructorAttributes instructor1InCourse1 = dataBundle.instructors.get("instructor1InCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    ______TS("Unsuccessful case: test empty feedback session name parameter");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, dataBundle.feedbackResponses.get("response1ForQ1S1C1").courseId };
    InstructorFeedbackSubmissionEditSaveAction a;
    RedirectResult r;
    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.FEEDBACK_SESSION_NAME), e.getMessage());
    }
    ______TS("Unsuccessful case: test empty course id parameter");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, dataBundle.feedbackResponses.get("response1ForQ1S1C1").feedbackSessionName };
    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());
    }
    ______TS("Successful case: edit existing answer");
    FeedbackQuestionsDb fqDb = new FeedbackQuestionsDb();
    FeedbackQuestionAttributes fq = fqDb.getFeedbackQuestion("First Session", "idOfCourse1", 1);
    assertNotNull("Feedback question not found in database", fq);
    FeedbackResponsesDb frDb = new FeedbackResponsesDb();
    FeedbackResponseAttributes fr = dataBundle.feedbackResponses.get("response1ForQ1S1C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    instructor1InCourse1 = dataBundle.instructors.get("instructor1InCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "Edited" + fr.getResponseDetails().getAnswerString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    // submission confirmation email not sent if parameter does not exist
    verifyNoEmailsSent(a);
    ______TS("Successful case: deleted response");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "", Const.ParamsNames.SEND_SUBMISSION_EMAIL, "on" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    // submission confirmation email sent
    verifyNumberOfEmailsSent(a, 1);
    EmailWrapper email = getEmailsSent(a).get(0);
    String courseName = coursesLogic.getCourse(fr.courseId).getName();
    assertEquals(String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), courseName, fr.feedbackSessionName), email.getSubject());
    assertEquals(instructor1InCourse1.email, email.getRecipient());
    // delete respondent task scheduled
    verifySpecifiedTasksAdded(a, Const.TaskQueue.FEEDBACK_SESSION_UPDATE_RESPONDENT_QUEUE_NAME, 1);
    ______TS("Successful case: skipped question");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "", Const.ParamsNames.SEND_SUBMISSION_EMAIL, "off" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    // submission confirmation email not sent if parameter is not "on"
    verifyNoEmailsSent(a);
    ______TS("Successful case: new response");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "New " + fr.getResponseDetails().getAnswerString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    // append respondent task scheduled
    verifySpecifiedTasksAdded(a, Const.TaskQueue.FEEDBACK_SESSION_UPDATE_RESPONDENT_QUEUE_NAME, 1);
    ______TS("Successful case: edit response, did not specify recipient");
    fq = fqDb.getFeedbackQuestion("First Session", "idOfCourse1", 2);
    assertNotNull("Feedback question not found in database", fq);
    fr = dataBundle.feedbackResponses.get("response1ForQ2S1C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-2", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-2-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-2", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-2-0", "student1InCourse1@gmail.tmt", Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-2", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-2-0", "Edited" + fr.getResponseDetails().getAnswerString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: new response, did not specify recipient");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-2", "1", Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-2", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-2-0", "student1InCourse1@gmail.tmt", Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-2", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-2-0", fr.getResponseDetails().getAnswerString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: private session");
    fq = fqDb.getFeedbackQuestion("Private Session", "idOfCourse1", 1);
    assertNotNull("Feedback question not found in database", fq);
    fr = dataBundle.feedbackResponses.get("response1ForPrivateSession");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "Edited" + fr.getResponseDetails().getAnswerString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Unsuccessful case: modified recipient to invalid recipient");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", "invalid_recipient_email", Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", fr.getResponseDetails().getAnswerString(), Const.ParamsNames.SEND_SUBMISSION_EMAIL, "on" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertTrue(r.isError);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "instructor1InCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, "invalid_recipient_email"));
    // submission confirmation email not sent if the action is an error, even with submission parameter "on"
    verifyNoEmailsSent(a);
    ______TS("Successful case: mcq: typical case");
    DataBundle dataBundle = loadDataBundle("/FeedbackSessionQuestionTypeTest.json");
    removeAndRestoreDataBundle(dataBundle);
    fq = fqDb.getFeedbackQuestion("MCQ Session", "FSQTT.idOfTypicalCourse1", 2);
    assertNotNull("Feedback question not found in database", fq);
    fr = dataBundle.feedbackResponses.get("response1ForQ2S1C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    instructor1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "It's perfect" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: mcq: question skipped");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: msq: typical case");
    fq = fqDb.getFeedbackQuestion("MSQ Session", "FSQTT.idOfTypicalCourse1", 2);
    assertNotNull("Feedback question not found in database", fq);
    fr = dataBundle.feedbackResponses.get("response1ForQ2S2C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    instructor1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "It's perfect" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful csae: msq: question skipped");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString() };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: numerical scale: typical case");
    fq = fqDb.getFeedbackQuestion("NUMSCALE Session", "FSQTT.idOfTypicalCourse1", 2);
    assertNotNull("Feedback question not found in database", fq);
    FeedbackNumericalScaleQuestionDetails fqd = (FeedbackNumericalScaleQuestionDetails) fq.getQuestionDetails();
    fr = dataBundle.feedbackResponses.get("response1ForQ2S3C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    instructor1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "3.5", Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MIN + "-1-0", Integer.toString(fqd.getMinScale()), Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MAX + "-1-0", Integer.toString(fqd.getMaxScale()), Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_STEP + "-1-0", StringHelper.toDecimalFormatString(fqd.getStep()) };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: numerical scale: question skipped");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "", Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MIN + "-1-0", Integer.toString(fqd.getMinScale()), Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_MAX + "-1-0", Integer.toString(fqd.getMaxScale()), Const.ParamsNames.FEEDBACK_QUESTION_NUMSCALE_STEP + "-1-0", StringHelper.toDecimalFormatString(fqd.getStep()) };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: const sum: typical case");
    fq = fqDb.getFeedbackQuestion("CONSTSUM Session", "FSQTT.idOfTypicalCourse1", 2);
    assertNotNull("Feedback question not found in database", fq);
    fr = dataBundle.feedbackResponses.get("response1ForQ2S4C1");
    // necessary to get the correct responseId
    fr = frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertNotNull("Feedback response not found in database", fr);
    FeedbackResponseAttributes fr2 = dataBundle.feedbackResponses.get("response2ForQ2S4C1");
    // necessary to get the correct responseId
    fr2 = frDb.getFeedbackResponse(fq.getId(), fr2.giver, fr2.recipient);
    assertNotNull("Feedback response not found in database", fr2);
    instructor1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1InCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "2", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "150", // Const sum question needs response to each recipient to sum up properly.
    Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-1", fr2.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr2.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr2.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr2.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-1", fr2.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr2.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-1", "50" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertFalse(r.isError);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    assertNotNull(frDb.getFeedbackResponse(fq.getId(), fr2.giver, fr2.recipient));
    ______TS("Successful case: const sum: question skipped");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-1", "1", Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-1-0", fr.getId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fr.feedbackSessionName, Const.ParamsNames.COURSE_ID, fr.courseId, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-1", fr.feedbackQuestionId, Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-1-0", fr.recipient, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-1", fr.feedbackQuestionType.toString(), Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-1-0", "" };
    a = getAction(submissionParams);
    r = getRedirectResult(a);
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, r.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, r.isError, "FSQTT.idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertNull(frDb.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient));
    ______TS("Successful case: contrib qn: typical case");
// No tests since contrib qn can only be answered by students to own team members including self.
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) FeedbackResponsesDb(teammates.storage.api.FeedbackResponsesDb) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) NullPostParameterException(teammates.common.exception.NullPostParameterException) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) DataBundle(teammates.common.datatransfer.DataBundle) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InstructorFeedbackSubmissionEditSaveAction(teammates.ui.controller.InstructorFeedbackSubmissionEditSaveAction) FeedbackQuestionsDb(teammates.storage.api.FeedbackQuestionsDb) FeedbackNumericalScaleQuestionDetails(teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails) Test(org.testng.annotations.Test)

Example 4 with NullPostParameterException

use of teammates.common.exception.NullPostParameterException in project teammates by TEAMMATES.

the class InstructorFeedbackPublishActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    gaeSimulation.loginAsInstructor(typicalBundle.instructors.get("instructor1OfCourse1").googleId);
    FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session2InCourse1");
    String[] paramsNormal = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithNullCourseId = { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithNullFeedbackSessionName = { Const.ParamsNames.COURSE_ID, session.getCourseId() };
    ______TS("Typical successful case: session publishable");
    makeFeedbackSessionUnpublished(session);
    InstructorFeedbackPublishAction publishAction = getAction(paramsNormal);
    RedirectResult result = getRedirectResult(publishAction);
    String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_PUBLISHED, result.getStatusMessage());
    assertFalse(result.isError);
    verifySpecifiedTasksAdded(publishAction, Const.TaskQueue.FEEDBACK_SESSION_PUBLISHED_EMAIL_QUEUE_NAME, 1);
    TaskWrapper taskAdded = publishAction.getTaskQueuer().getTasksAdded().get(0);
    Map<String, String[]> paramMap = taskAdded.getParamMap();
    assertEquals(session.getCourseId(), paramMap.get(ParamsNames.EMAIL_COURSE)[0]);
    assertEquals(session.getSessionName(), paramMap.get(ParamsNames.EMAIL_FEEDBACK)[0]);
    ______TS("Unsuccessful case 1: params with null course id");
    String errorMessage = "";
    publishAction = getAction(paramsWithNullCourseId);
    try {
        publishAction.executeAndPostProcess();
        signalFailureToDetectException("NullPostParameterException expected");
    } catch (NullPostParameterException e) {
        errorMessage = e.getMessage();
    }
    assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), errorMessage);
    ______TS("Unsuccessful case 2: params with null feedback session name");
    errorMessage = "";
    publishAction = getAction(paramsWithNullFeedbackSessionName);
    try {
        publishAction.executeAndPostProcess();
        signalFailureToDetectException("NullPostParameterException expected");
    } catch (NullPostParameterException e) {
        errorMessage = e.getMessage();
    }
    assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.FEEDBACK_SESSION_NAME), errorMessage);
    ______TS("Unsuccessful case 3: trying to publish a session not currently unpublished");
    makeFeedbackSessionPublished(session);
    publishAction = getAction(paramsNormal);
    result = getRedirectResult(publishAction);
    expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, true, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals("Error publishing feedback session: Session has already been published.", result.getStatusMessage());
    assertTrue(result.isError);
    verifyNoTasksAdded(publishAction);
    makeFeedbackSessionUnpublished(session);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) NullPostParameterException(teammates.common.exception.NullPostParameterException) InstructorFeedbackPublishAction(teammates.ui.controller.InstructorFeedbackPublishAction) RedirectResult(teammates.ui.controller.RedirectResult) Test(org.testng.annotations.Test)

Example 5 with NullPostParameterException

use of teammates.common.exception.NullPostParameterException 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

NullPostParameterException (teammates.common.exception.NullPostParameterException)14 Test (org.testng.annotations.Test)11 RedirectResult (teammates.ui.controller.RedirectResult)10 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)7 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)6 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)5 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)4 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)4 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)4 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)4 ShowPageResult (teammates.ui.controller.ShowPageResult)4 EmailWrapper (teammates.common.util.EmailWrapper)3 DataBundle (teammates.common.datatransfer.DataBundle)2 FeedbackNumericalScaleQuestionDetails (teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails)2 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)2 TaskWrapper (teammates.common.util.TaskWrapper)2 FeedbackSessionsDb (teammates.storage.api.FeedbackSessionsDb)2 DeadlineExceededException (com.google.apphosting.api.DeadlineExceededException)1 ArrayList (java.util.ArrayList)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1