use of teammates.common.datatransfer.DataBundle in project teammates by TEAMMATES.
the class InstructorFeedbackQuestionEditActionTest method testExecuteAndPostProcessConstSumOption.
@Test
public void testExecuteAndPostProcessConstSumOption() {
DataBundle dataBundle = loadDataBundle("/FeedbackSessionQuestionTypeTest.json");
removeAndRestoreDataBundle(dataBundle);
InstructorAttributes instructor1ofCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("constSumSession");
FeedbackQuestionAttributes fq = FeedbackQuestionsLogic.inst().getFeedbackQuestion(fs.getFeedbackSessionName(), fs.getCourseId(), 1);
FeedbackResponsesDb frDb = new FeedbackResponsesDb();
______TS("Edit text");
// There are already responses for this question
assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
String[] editTextParams = { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, fq.giverType.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, fq.recipientType.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "CONSTSUM", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Split points among the options.(edited)", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTS, "100", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSFOREACHOPTION, "50", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSFOREACHRECIPIENT, "30", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSPEROPTION, "false", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "3", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMOPTION + "-0", "Grades", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMOPTION + "-1", "Fun", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMTORECIPIENTS, "false", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
InstructorFeedbackQuestionEditAction a = getAction(editTextParams);
RedirectResult r = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "CONSTSUM+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
assertFalse(r.isError);
// All existing responses should remain
assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
______TS("Edit points");
String[] editPointsParams = { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, fq.giverType.toString(), Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, fq.recipientType.toString(), Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, Integer.toString(fq.questionNumber), Const.ParamsNames.FEEDBACK_QUESTION_TYPE, "CONSTSUM", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "Split points among the options.(edited)", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTS, "1000", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSFOREACHOPTION, "300", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSFOREACHRECIPIENT, "500", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMPOINTSPEROPTION, "false", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "3", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMOPTION + "-0", "Grades", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMOPTION + "-1", "Fun", Const.ParamsNames.FEEDBACK_QUESTION_CONSTSUMTORECIPIENTS, "false", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, "max", Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO, FeedbackParticipantType.INSTRUCTORS.toString(), Const.ParamsNames.FEEDBACK_QUESTION_EDITTYPE, "edit", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId() };
a = getAction(editPointsParams);
r = getRedirectResult(a);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "CONSTSUM+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
assertFalse(r.isError);
// All existing responses should be deleted as the options are edited
assertTrue(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
}
use of teammates.common.datatransfer.DataBundle 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.
}
use of teammates.common.datatransfer.DataBundle in project teammates by TEAMMATES.
the class BackDoorServlet method executeBackEndAction.
// no default so that each case is accounted for
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
private String executeBackEndAction(HttpServletRequest req, BackDoorOperation opCode) throws IOException, InvalidParametersException, EntityDoesNotExistException {
BackDoorLogic backDoorLogic = new BackDoorLogic();
switch(opCode) {
case OPERATION_DELETE_ACCOUNT:
String googleId = req.getParameter(BackDoorOperation.PARAMETER_GOOGLE_ID);
backDoorLogic.deleteAccount(googleId);
break;
case OPERATION_DELETE_COURSE:
String courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
backDoorLogic.deleteCourse(courseId);
break;
case OPERATION_DELETE_FEEDBACK_QUESTION:
String questionId = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_QUESTION_ID);
backDoorLogic.deleteFeedbackQuestion(questionId);
break;
case OPERATION_DELETE_FEEDBACK_RESPONSE:
String feedbackQuestionId = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_QUESTION_ID);
String giverEmail = req.getParameter(BackDoorOperation.PARAMETER_GIVER_EMAIL);
String recipient = req.getParameter(BackDoorOperation.PARAMETER_RECIPIENT);
FeedbackResponseAttributes fr = backDoorLogic.getFeedbackResponse(feedbackQuestionId, giverEmail, recipient);
backDoorLogic.deleteFeedbackResponse(fr);
break;
case OPERATION_DELETE_FEEDBACK_SESSION:
String feedbackSessionName = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_SESSION_NAME);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
backDoorLogic.deleteFeedbackSession(feedbackSessionName, courseId);
break;
case OPERATION_DELETE_INSTRUCTOR:
String instructorEmail = req.getParameter(BackDoorOperation.PARAMETER_INSTRUCTOR_EMAIL);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
backDoorLogic.deleteInstructor(courseId, instructorEmail);
break;
case OPERATION_DELETE_STUDENT:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
String studentEmail = req.getParameter(BackDoorOperation.PARAMETER_STUDENT_EMAIL);
backDoorLogic.deleteStudent(courseId, studentEmail);
break;
case OPERATION_EDIT_FEEDBACK_QUESTION:
String newValues = req.getParameter(BackDoorOperation.PARAMETER_JSON_STRING);
backDoorLogic.editFeedbackQuestionAsJson(newValues);
break;
case OPERATION_EDIT_FEEDBACK_SESSION:
newValues = req.getParameter(BackDoorOperation.PARAMETER_JSON_STRING);
backDoorLogic.editFeedbackSessionAsJson(newValues);
break;
case OPERATION_EDIT_STUDENT:
studentEmail = req.getParameter(BackDoorOperation.PARAMETER_STUDENT_EMAIL);
newValues = req.getParameter(BackDoorOperation.PARAMETER_JSON_STRING);
backDoorLogic.editStudentAsJson(studentEmail, newValues);
break;
case OPERATION_EDIT_STUDENT_PROFILE_PICTURE:
String pictureDataJsonString = req.getParameter(BackDoorOperation.PARAMETER_PICTURE_DATA);
byte[] pictureData = JsonUtils.fromJson(pictureDataJsonString, byte[].class);
googleId = req.getParameter(BackDoorOperation.PARAMETER_GOOGLE_ID);
backDoorLogic.uploadAndUpdateStudentProfilePicture(googleId, pictureData);
break;
case OPERATION_GET_ACCOUNT_AS_JSON:
googleId = req.getParameter(BackDoorOperation.PARAMETER_GOOGLE_ID);
return backDoorLogic.getAccountAsJson(googleId);
case OPERATION_GET_COURSE_AS_JSON:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
return backDoorLogic.getCourseAsJson(courseId);
case OPERATION_GET_ENCRYPTED_KEY_FOR_INSTRUCTOR:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
studentEmail = req.getParameter(BackDoorOperation.PARAMETER_INSTRUCTOR_EMAIL);
return backDoorLogic.getEncryptedKeyForInstructor(courseId, studentEmail);
case OPERATION_GET_ENCRYPTED_KEY_FOR_STUDENT:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
studentEmail = req.getParameter(BackDoorOperation.PARAMETER_STUDENT_EMAIL);
return backDoorLogic.getEncryptedKeyForStudent(courseId, studentEmail);
case OPERATION_GET_FEEDBACK_QUESTION_AS_JSON:
feedbackSessionName = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_SESSION_NAME);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
int qnNumber = Integer.parseInt(req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_QUESTION_NUMBER));
return backDoorLogic.getFeedbackQuestionAsJson(feedbackSessionName, courseId, qnNumber);
case OPERATION_GET_FEEDBACK_QUESTION_FOR_ID_AS_JSON:
questionId = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_QUESTION_ID);
return backDoorLogic.getFeedbackQuestionForIdAsJson(questionId);
case OPERATION_GET_FEEDBACK_RESPONSE_AS_JSON:
feedbackQuestionId = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_QUESTION_ID);
giverEmail = req.getParameter(BackDoorOperation.PARAMETER_GIVER_EMAIL);
recipient = req.getParameter(BackDoorOperation.PARAMETER_RECIPIENT);
return backDoorLogic.getFeedbackResponseAsJson(feedbackQuestionId, giverEmail, recipient);
case OPERATION_GET_FEEDBACK_RESPONSES_FOR_GIVER_AS_JSON:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
giverEmail = req.getParameter(BackDoorOperation.PARAMETER_GIVER_EMAIL);
return backDoorLogic.getFeedbackResponsesForGiverAsJson(courseId, giverEmail);
case OPERATION_GET_FEEDBACK_RESPONSES_FOR_RECEIVER_AS_JSON:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
recipient = req.getParameter(BackDoorOperation.PARAMETER_RECIPIENT);
return backDoorLogic.getFeedbackResponsesForReceiverAsJson(courseId, recipient);
case OPERATION_GET_FEEDBACK_SESSION_AS_JSON:
feedbackSessionName = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_SESSION_NAME);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
return backDoorLogic.getFeedbackSessionAsJson(feedbackSessionName, courseId);
case OPERATION_GET_INSTRUCTOR_AS_JSON_BY_ID:
googleId = req.getParameter(BackDoorOperation.PARAMETER_GOOGLE_ID);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
return backDoorLogic.getInstructorAsJsonById(googleId, courseId);
case OPERATION_GET_INSTRUCTOR_AS_JSON_BY_EMAIL:
instructorEmail = req.getParameter(BackDoorOperation.PARAMETER_INSTRUCTOR_EMAIL);
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
return backDoorLogic.getInstructorAsJsonByEmail(instructorEmail, courseId);
case OPERATION_GET_STUDENT_AS_JSON:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
studentEmail = req.getParameter(BackDoorOperation.PARAMETER_STUDENT_EMAIL);
return backDoorLogic.getStudentAsJson(courseId, studentEmail);
case OPERATION_GET_STUDENTS_AS_JSON:
courseId = req.getParameter(BackDoorOperation.PARAMETER_COURSE_ID);
return backDoorLogic.getAllStudentsAsJson(courseId);
case OPERATION_GET_STUDENTPROFILE_AS_JSON:
googleId = req.getParameter(BackDoorOperation.PARAMETER_GOOGLE_ID);
return backDoorLogic.getStudentProfileAsJson(googleId);
case OPERATION_IS_PICTURE_PRESENT_IN_GCS:
String pictureKey = req.getParameter(BackDoorOperation.PARAMETER_PICTURE_KEY);
return String.valueOf(backDoorLogic.isPicturePresentInGcs(pictureKey));
case OPERATION_CREATE_FEEDBACK_RESPONSE:
String feedbackResponseJsonString = req.getParameter(BackDoorOperation.PARAMETER_FEEDBACK_RESPONSE_JSON);
FeedbackResponseAttributes feedbackResponse = JsonUtils.fromJson(feedbackResponseJsonString, FeedbackResponseAttributes.class);
return backDoorLogic.createFeedbackResponseAndUpdateSessionRespondents(feedbackResponse);
case OPERATION_PERSIST_DATABUNDLE:
String dataBundleJsonString = req.getParameter(BackDoorOperation.PARAMETER_DATABUNDLE_JSON);
DataBundle dataBundle = JsonUtils.fromJson(dataBundleJsonString, DataBundle.class);
backDoorLogic.persistDataBundle(dataBundle);
break;
case OPERATION_PUT_DOCUMENTS:
dataBundleJsonString = req.getParameter(BackDoorOperation.PARAMETER_DATABUNDLE_JSON);
dataBundle = JsonUtils.fromJson(dataBundleJsonString, DataBundle.class);
backDoorLogic.putDocuments(dataBundle);
break;
case OPERATION_REMOVE_AND_RESTORE_DATABUNDLE:
dataBundleJsonString = req.getParameter(BackDoorOperation.PARAMETER_DATABUNDLE_JSON);
dataBundle = JsonUtils.fromJson(dataBundleJsonString, DataBundle.class);
backDoorLogic.removeDataBundle(dataBundle);
backDoorLogic.persistDataBundle(dataBundle);
break;
case OPERATION_REMOVE_DATABUNDLE:
dataBundleJsonString = req.getParameter(BackDoorOperation.PARAMETER_DATABUNDLE_JSON);
dataBundle = JsonUtils.fromJson(dataBundleJsonString, DataBundle.class);
backDoorLogic.removeDataBundle(dataBundle);
break;
case OPERATION_IS_GROUP_LIST_FILE_PRESENT_IN_GCS:
String groupListKey = req.getParameter(BackDoorOperation.PARAMETER_GROUP_LIST_FILE_KEY);
return String.valueOf(backDoorLogic.isGroupListFilePresentInGcs(groupListKey));
case OPERATION_DELETE_GROUP_LIST_FILE:
String groupListFileKey = req.getParameter(BackDoorOperation.PARAMETER_GROUP_LIST_FILE_KEY);
backDoorLogic.deleteGroupListFile(groupListFileKey);
break;
}
return Const.StatusCodes.BACKDOOR_STATUS_SUCCESS;
}
use of teammates.common.datatransfer.DataBundle in project teammates by TEAMMATES.
the class DataBundleRegenerator method regenerateDataBundleJson.
private static void regenerateDataBundleJson(File folder) throws IOException {
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
if (!file.getName().endsWith(".json") || NON_DATA_BUNDLE_JSON.contains(file.getName())) {
continue;
}
if (LOGS_JSON.contains(file.getName())) {
regenerateGenericJson(file);
continue;
}
String jsonString = FileHelper.readFile(file.getCanonicalPath());
DataBundle db = JsonUtils.fromJson(jsonString, DataBundle.class);
db.feedbackResponses.forEach((key, feedbackResponseAttributes) -> fixResponse(feedbackResponseAttributes));
db.feedbackQuestions.forEach((key, feedbackQuestionAttributes) -> fixQuestion(feedbackQuestionAttributes));
String regeneratedJsonString = JsonUtils.toJson(db).replace("+0000", "UTC");
saveFile(file.getCanonicalPath(), regeneratedJsonString + System.lineSeparator());
}
}
use of teammates.common.datatransfer.DataBundle in project teammates by TEAMMATES.
the class FeedbackSessionsLogicTest method testGetFeedbackSessionResultsForUser.
private void testGetFeedbackSessionResultsForUser() throws Exception {
// This file contains a session with a private session + a standard
// session which needs to have enough qn/response combinations to cover as much
// of the SUT as possible
DataBundle responseBundle = loadDataBundle("/FeedbackSessionResultsTest.json");
removeAndRestoreDataBundle(responseBundle);
______TS("standard session with varied visibilities");
FeedbackSessionAttributes session = responseBundle.feedbackSessions.get("standard.session");
/**
* Test result bundle for student1 **
*/
StudentAttributes student = responseBundle.students.get("student1InCourse1");
FeedbackSessionResultsBundle results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
// We just check for correct session once
assertEquals(session.toString(), results.feedbackSession.toString());
// Student can see responses: q1r1, q2r1,3, q3r1, qr4r2-3, q5r1, q7r1-2, q8r1-2
// We don't check the actual IDs as this is also implicitly tested
// later when checking the visibility table.
assertEquals(11, results.responses.size());
assertEquals(7, results.questions.size());
// Test the user email-name maps used for display purposes
String mapString = results.emailNameTable.toString();
List<String> expectedStrings = new ArrayList<>();
String student2AnonEmail = getStudentAnonEmail(responseBundle, "student2InCourse1");
String student2AnonName = getStudentAnonName(responseBundle, "student2InCourse1");
String student4AnonEmail = getStudentAnonEmail(responseBundle, "student4InCourse1");
String student4AnonName = getStudentAnonName(responseBundle, "student4InCourse1");
Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "Team 1.1</td></div>'\"=Team 1.1</td></div>'\"", "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.student1InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student2InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student4InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.2", student2AnonEmail + "=" + student2AnonName, student4AnonEmail + "=" + student4AnonName);
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(13, results.emailNameTable.size());
// Test the user email-teamName maps used for display purposes
mapString = results.emailTeamNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student1InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt's Team=", "FSRTest.student4InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.1</td></div>'\"=", "Team 1.3=", "Team 1.2=", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors", student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student4AnonEmail + "=" + student4AnonName + Const.TEAM_OF_EMAIL_OWNER);
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(13, results.emailTeamNameTable.size());
// Test 'Append TeamName to Name' for display purposes with Typical Cases
expectedStrings.clear();
List<String> actualStrings = new ArrayList<>();
for (FeedbackResponseAttributes response : results.responses) {
String giverName = results.getNameForEmail(response.giver);
String giverTeamName = results.getTeamNameForEmail(response.giver);
giverName = results.appendTeamNameToName(giverName, giverTeamName);
String recipientName = results.getNameForEmail(response.recipient);
String recipientTeamName = results.getTeamNameForEmail(response.recipient);
recipientName = results.appendTeamNameToName(recipientName, recipientTeamName);
actualStrings.add(giverName);
actualStrings.add(recipientName);
}
Collections.addAll(expectedStrings, getStudentAnonName(responseBundle, "student2InCourse1"), getStudentAnonName(responseBundle, "student4InCourse1"), "student1 In Course1</td></div>'\" (Team 1.1</td></div>'\")", "student2 In Course1 (Team 1.1</td></div>'\")", "student4 In Course1 (Team 1.2)", "Instructor1 Course1 (Instructors)", "Team 1.1</td></div>'\"", "Team 1.2", "Team 1.3", "Team 1.4");
AssertHelper.assertContains(expectedStrings, actualStrings.toString());
// Test 'Append TeamName to Name' for display purposes with Special Cases
expectedStrings.clear();
actualStrings.clear();
// case: Unknown User
String unknownUserName = Const.USER_UNKNOWN_TEXT;
String someTeamName = "Some Team Name";
unknownUserName = results.appendTeamNameToName(unknownUserName, someTeamName);
actualStrings.add(unknownUserName);
// case: Nobody
String nobodyUserName = Const.USER_NOBODY_TEXT;
nobodyUserName = results.appendTeamNameToName(nobodyUserName, someTeamName);
actualStrings.add(nobodyUserName);
// case: Anonymous User
String anonymousUserName = Const.DISPLAYED_NAME_FOR_ANONYMOUS_PARTICIPANT + " " + System.currentTimeMillis();
anonymousUserName = results.appendTeamNameToName(anonymousUserName, someTeamName);
actualStrings.add(anonymousUserName);
Collections.addAll(expectedStrings, Const.USER_UNKNOWN_TEXT, Const.USER_NOBODY_TEXT, anonymousUserName);
assertEquals(expectedStrings.toString(), actualStrings.toString());
// Test the generated response visibilityTable for userNames.
mapString = tableToString(results.visibilityTable);
expectedStrings.clear();
Collections.addAll(expectedStrings, getResponseId("qn1.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={true,true}", getResponseId("qn3.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={false,true}", getResponseId("qn5.resp1", responseBundle) + "={true,false}", getResponseId("qn7.resp1", responseBundle) + "={true,true}", getResponseId("qn7.resp2", responseBundle) + "={true,true}", getResponseId("qn8.resp1", responseBundle) + "={true,true}", getResponseId("qn8.resp2", responseBundle) + "={true,true}");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(11, results.visibilityTable.size());
/**
* Test result bundle for instructor1 within a course **
*/
InstructorAttributes instructor = responseBundle.instructors.get("instructor1OfCourse1");
results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
// Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
assertEquals(10, results.responses.size());
// Instructor should still see all questions
assertEquals(8, results.questions.size());
// Test the user email-name maps used for display purposes
mapString = results.emailNameTable.toString();
expectedStrings.clear();
String student1AnonEmail = getStudentAnonEmail(responseBundle, "student1InCourse1");
String student1AnonName = getStudentAnonName(responseBundle, "student1InCourse1");
String student3AnonEmail = getStudentAnonEmail(responseBundle, "student3InCourse1");
String student3AnonName = getStudentAnonName(responseBundle, "student3InCourse1");
String student6AnonEmail = getStudentAnonEmail(responseBundle, "student6InCourse1");
String student6AnonName = getStudentAnonName(responseBundle, "student6InCourse1");
String instructor1AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
String instructor1AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
String instructor2AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
String instructor2AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
Collections.addAll(expectedStrings, "%GENERAL%=%NOBODY%", "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student3InCourse1@gmail.tmt=student3 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "FSRTest.student5InCourse1@gmail.tmt=student5 In Course1", "FSRTest.student6InCourse1@gmail.tmt=student6 In Course1", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.instr2@course1.tmt=Instructor2 Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, instructor2AnonEmail + "=" + instructor2AnonName, "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(18, results.emailNameTable.size());
// Test the user email-teamName maps used for display purposes
mapString = results.emailTeamNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "%GENERAL%=", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student3InCourse1@gmail.tmt=Team 1.2", "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student5InCourse1@gmail.tmt=Team 1.3", "FSRTest.student6InCourse1@gmail.tmt=Team 1.4", "FSRTest.instr2@course1.tmt=Instructors", "FSRTest.instr1@course1.tmt=Instructors", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor2AnonEmail + "=" + instructor2AnonName + Const.TEAM_OF_EMAIL_OWNER, "Team 1.3=", "Team 1.2=", "Team 1.4=");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(18, results.emailTeamNameTable.size());
// Test the generated response visibilityTable for userNames.
mapString = tableToString(results.visibilityTable);
expectedStrings.clear();
Collections.addAll(expectedStrings, getResponseId("qn2.resp1", responseBundle) + "={false,false}", getResponseId("qn2.resp2", responseBundle) + "={false,false}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn3.resp2", responseBundle) + "={false,false}", getResponseId("qn4.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn5.resp1", responseBundle) + "={false,true}", getResponseId("qn6.resp1", responseBundle) + "={true,true}");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(10, results.visibilityTable.size());
/**
* Test result bundle for instructor1 within a section **
*/
results = fsLogic.getFeedbackSessionResultsForInstructorInSection(session.getFeedbackSessionName(), session.getCourseId(), instructor.email, "Section A");
// Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
assertEquals(7, results.responses.size());
// Instructor should still see all questions
assertEquals(8, results.questions.size());
// Test the user email-name maps used for display purposes
mapString = results.emailNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(13, results.emailNameTable.size());
// Test the user email-teamName maps used for display purposes
mapString = results.emailTeamNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(13, results.emailTeamNameTable.size());
// Test the generated response visibilityTable for userNames.
mapString = tableToString(results.visibilityTable);
expectedStrings.clear();
Collections.addAll(expectedStrings, getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn2.resp1", responseBundle) + "={false,false}");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(7, results.visibilityTable.size());
// TODO: test student2 too.
______TS("private session");
session = responseBundle.feedbackSessions.get("private.session");
/**
* Test result bundle for student1 **
*/
student = responseBundle.students.get("student1InCourse1");
results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
assertEquals(0, results.questions.size());
assertEquals(0, results.responses.size());
assertEquals(0, results.emailNameTable.size());
assertEquals(0, results.emailTeamNameTable.size());
assertEquals(0, results.visibilityTable.size());
/**
* Test result bundle for instructor1 **
*/
instructor = responseBundle.instructors.get("instructor1OfCourse1");
results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
// Can see all responses regardless of visibility settings.
assertEquals(2, results.questions.size());
assertEquals(2, results.responses.size());
// Test the user email-name maps used for display purposes
mapString = results.emailNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "Team 1.2=Team 1.2", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructor1 Course1");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(4, results.emailNameTable.size());
// Test the user email-teamName maps used for display purposes
mapString = results.emailTeamNameTable.toString();
expectedStrings.clear();
Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.2=", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructors");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(4, results.emailTeamNameTable.size());
// Test that name visibility is adhered to even when
// it is a private session. (to protect anonymity during session type conversion)"
mapString = tableToString(results.visibilityTable);
expectedStrings.clear();
Collections.addAll(expectedStrings, getResponseId("p.qn1.resp1", responseBundle) + "={true,true}", getResponseId("p.qn2.resp1", responseBundle) + "={true,false}");
AssertHelper.assertContains(expectedStrings, mapString);
assertEquals(2, results.visibilityTable.size());
______TS("failure: no session");
try {
fsLogic.getFeedbackSessionResultsForInstructor("invalid session", session.getCourseId(), instructor.email);
signalFailureToDetectException("Did not detect that session does not exist.");
} catch (EntityDoesNotExistException e) {
assertEquals("Trying to view a non-existent feedback session: " + session.getCourseId() + "/" + "invalid session", e.getMessage());
}
// TODO: check for cases where a person is both a student and an instructor
}
Aggregations