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());
}
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);
}
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());
}
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());
}
Aggregations