Search in sources :

Example 1 with FileDownloadResult

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

the class InstructorCourseStudentListDownloadActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String instructorId = typicalBundle.instructors.get("instructor1OfCourse1").googleId;
    CourseAttributes course = typicalBundle.courses.get("typicalCourse1");
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid params");
    String[] submissionParams = {};
    verifyAssumptionFailure(submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, course.getId() };
    ______TS("Typical case: student list downloaded successfully");
    InstructorCourseStudentListDownloadAction a = getAction(submissionParams);
    FileDownloadResult r = getFileDownloadResult(a);
    String expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    String fileContent = r.getFileContent();
    String[] expected = { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student1 In Course1</td></div>'\"\"\",\"Course1</td></div>'\"\"\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
    ______TS("Typical case: student list downloaded successfully with student last name specified within braces");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    student1InCourse1.name = "new name {new last name}";
    StudentsLogic.inst().updateStudentCascade(student1InCourse1.email, student1InCourse1);
    a = getAction(submissionParams);
    r = getFileDownloadResult(a);
    expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    fileContent = r.getFileContent();
    expected = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"new name new last name\",\"new last name\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
    removeAndRestoreTypicalDataBundle();
    ______TS("Typical case: student list downloaded successfully with special team name");
    student1InCourse1 = StudentsLogic.inst().getStudentForEmail("idOfTypicalCourse1", "student1InCourse1@gmail.tmt");
    student1InCourse1.team = "N/A";
    StudentsLogic.inst().updateStudentCascade("student1InCourse1@gmail.tmt", student1InCourse1);
    a = getAction(submissionParams);
    r = getFileDownloadResult(a);
    expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    fileContent = r.getFileContent();
    expected = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"N/A\",\"student1 In Course1</td></div>'\"\"\",\"Course1</td></div>'\"\"\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
}
Also used : InstructorCourseStudentListDownloadAction(teammates.ui.controller.InstructorCourseStudentListDownloadAction) FileDownloadResult(teammates.ui.controller.FileDownloadResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 2 with FileDownloadResult

use of teammates.ui.controller.FileDownloadResult 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)

Example 3 with FileDownloadResult

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

the class ActionResultTest method testFileDownloadResult.

@Test
public void testFileDownloadResult() {
    FileDownloadResult download = new FileDownloadResult("/page/instructorFeedbackResultsDownload", null, null, "Normal name", "abcabc");
    assertEquals("attachment; filename=\"Normal name.csv\";filename*= UTF-8''Normal+name.csv", download.getContentDispositionHeader());
}
Also used : FileDownloadResult(teammates.ui.controller.FileDownloadResult) Test(org.testng.annotations.Test)

Example 4 with FileDownloadResult

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

the class ActionResultTest method testFileDownloadResult_fileNameWithUnicodeCharacters_hasCorrectContentDesposition.

@Test
public void testFileDownloadResult_fileNameWithUnicodeCharacters_hasCorrectContentDesposition() {
    FileDownloadResult download = new FileDownloadResult("/page/instructorFeedbackResultsDownload", null, null, "£ rates", "abcabc");
    assertEquals("attachment; filename=\" rates.csv\";filename*= UTF-8''%C2%A3+rates.csv", download.getContentDispositionHeader());
}
Also used : FileDownloadResult(teammates.ui.controller.FileDownloadResult) Test(org.testng.annotations.Test)

Aggregations

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