Search in sources :

Example 1 with InstructorFeedbackResultsDownloadAction

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

the class InstructorFeedbackResultsDownloadActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    gaeSimulation.loginAsInstructor(typicalBundle.instructors.get("instructor1OfCourse1").googleId);
    FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] paramsNormal = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsNormalWithinSection = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.SECTION_NAME, "Section 1" };
    String[] paramsWithNullCourseId = { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithNullFeedbackSessionName = { Const.ParamsNames.COURSE_ID, session.getCourseId() };
    String[] paramsWithMissingResponsesShown = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_RESULTS_INDICATE_MISSING_RESPONSES, "true" };
    String[] paramsWithMissingResponsesHidden = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_RESULTS_INDICATE_MISSING_RESPONSES, "false" };
    ______TS("Typical case: results downloadable");
    InstructorFeedbackResultsDownloadAction action = getAction(paramsNormal);
    FileDownloadResult result = getFileDownloadResult(action);
    String expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    assertEquals("", result.getStatusMessage());
    String expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName();
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForSession1InCourse1(result.getFileContent(), session);
    ______TS("Typical successful case: student last name displayed properly after being specified with braces");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    student1InCourse1.name = "new name {new last name}";
    StudentsLogic studentsLogic = StudentsLogic.inst();
    studentsLogic.updateStudentCascade(student1InCourse1.email, student1InCourse1);
    action = getAction(paramsNormal);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    assertEquals("", result.getStatusMessage());
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName();
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForSession1InCourse1WithNewLastName(result.getFileContent(), session);
    removeAndRestoreTypicalDataBundle();
    ______TS("Typical case: results within section downloadable");
    action = getAction(paramsNormalWithinSection);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName() + "_Section 1";
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForSession1InCourse1WithinSection1(result.getFileContent(), session);
    ______TS("Failure case: params with null course id");
    try {
        action = getAction(paramsWithNullCourseId);
        result = getFileDownloadResult(action);
        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("Failure case: params with null feedback session name");
    try {
        action = getAction(paramsWithNullFeedbackSessionName);
        result = getFileDownloadResult(action);
        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("Typical case: results with missing responses shown");
    action = getAction(paramsWithMissingResponsesShown);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName();
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForDownloadWithMissingResponsesShown(result.getFileContent(), session);
    ______TS("Typical case: results with missing responses hidden");
    action = getAction(paramsWithMissingResponsesHidden);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName();
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForDownloadWithMissingResponsesHidden(result.getFileContent(), session);
    ______TS("Typical case: results downloadable by question");
    final int questionNum2 = typicalBundle.feedbackQuestions.get("qn2InSession1InCourse1").getQuestionNumber();
    final String question2Id = fqLogic.getFeedbackQuestion(session.getFeedbackSessionName(), session.getCourseId(), questionNum2).getId();
    String[] paramsQuestion2 = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "2", Const.ParamsNames.FEEDBACK_QUESTION_ID, question2Id };
    action = getAction(paramsQuestion2);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    assertEquals("", result.getStatusMessage());
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName() + "_question2";
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForQuestion2Session1InCourse1(result.getFileContent(), session);
    ______TS("Typical case: results within section downloadable by question");
    final int questionNum1 = typicalBundle.feedbackQuestions.get("qn1InSession1InCourse1").getQuestionNumber();
    final String question1Id = fqLogic.getFeedbackQuestion(session.getFeedbackSessionName(), session.getCourseId(), questionNum1).getId();
    String[] paramsQuestion1WithinSection = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName(), Const.ParamsNames.SECTION_NAME, "Section 1", Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, "1", Const.ParamsNames.FEEDBACK_QUESTION_ID, question1Id };
    action = getAction(paramsQuestion1WithinSection);
    result = getFileDownloadResult(action);
    expectedDestination = getPageResultDestination("filedownload", false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertFalse(result.isError);
    expectedFileName = session.getCourseId() + "_" + session.getFeedbackSessionName() + "_Section 1" + "_question1";
    assertEquals(expectedFileName, result.getFileName());
    verifyFileContentForQuestion1Session1InCourse1WithinSection1(result.getFileContent(), session);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackResultsDownloadAction(teammates.ui.controller.InstructorFeedbackResultsDownloadAction) StudentsLogic(teammates.logic.core.StudentsLogic) NullPostParameterException(teammates.common.exception.NullPostParameterException) FileDownloadResult(teammates.ui.controller.FileDownloadResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 NullPostParameterException (teammates.common.exception.NullPostParameterException)1 StudentsLogic (teammates.logic.core.StudentsLogic)1 FileDownloadResult (teammates.ui.controller.FileDownloadResult)1 InstructorFeedbackResultsDownloadAction (teammates.ui.controller.InstructorFeedbackResultsDownloadAction)1