Search in sources :

Example 56 with RedirectResult

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

the class InstructorCourseJoinAuthenticatedActionTest method testExecuteAndPostProcess.

@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    InstructorsDb instrDb = new InstructorsDb();
    instructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("Failure: Invalid key");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
    InstructorCourseJoinAuthenticatedAction joinAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, true, "idOfInstructor1OfCourse1", invalidEncryptedKey), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey, redirectResult.getStatusMessage());
    String expectedLogSegment = "Servlet Action Failure : You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey + "<br><br>Action Instructor Joins Course<br>" + "Google ID: idOfInstructor1OfCourse1<br>Key : invalidKey";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: Instructor already registered");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(instructor.googleId + " has already joined this course", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + instructor.googleId + " has already joined this course" + "<br><br>Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + instructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: the current key has been registered by another account");
    InstructorAttributes instructor2 = typicalBundle.instructors.get("instructor2OfCourse1");
    instructor2 = instrDb.getInstructorForGoogleId(instructor2.courseId, instructor2.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor2.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor2.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor2.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    AssertHelper.assertContains("The join link used belongs to a different user", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : The join link used belongs to a different user";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Typical case: authenticate for new instructor with corresponding key");
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAAT.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT.instr";
    AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    gaeSimulation.loginUser(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", false, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("", redirectResult.getStatusMessage());
    InstructorAttributes retrievedInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    assertEquals(instructor.googleId, retrievedInstructor.googleId);
    expectedLogSegment = "Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure case: the current unused key is not for this account ");
    String currentLoginId = instructor.googleId;
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor 2", "ICJAAT2.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT2.instr";
    newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", true, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId), redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId) + "<br><br>Action Instructor Joins Course<br>Google ID: " + currentLoginId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
}
Also used : InstructorCourseJoinAuthenticatedAction(teammates.ui.controller.InstructorCourseJoinAuthenticatedAction) InstructorsDb(teammates.storage.api.InstructorsDb) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 57 with RedirectResult

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

the class InstructorCourseRemindActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    String adminUserId = "admin.user";
    ______TS("Typical case: Send email to remind an instructor to register for the course");
    gaeSimulation.loginAsInstructor(instructorId);
    InstructorAttributes anotherInstructorOfCourse1 = typicalBundle.instructors.get("instructorNotYetJoinCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, anotherInstructorOfCourse1.email };
    InstructorCourseRemindAction remindAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(remindAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_REMINDER_SENT_TO + anotherInstructorOfCourse1.email, redirectResult.getStatusMessage());
    String expectedLogSegment = "Registration Key sent to the following users " + "in Course <span class=\"bold\">[" + courseId + "]</span>:<br>" + anotherInstructorOfCourse1.name + "<span class=\"bold\"> (" + anotherInstructorOfCourse1.email + ")" + "</span>.<br>" + StringHelper.encrypt(anotherInstructorOfCourse1.key) + "<br>";
    AssertHelper.assertContains(expectedLogSegment, remindAction.getLogMessage());
    verifySpecifiedTasksAdded(remindAction, Const.TaskQueue.INSTRUCTOR_COURSE_JOIN_EMAIL_QUEUE_NAME, 1);
    TaskWrapper taskAdded = remindAction.getTaskQueuer().getTasksAdded().get(0);
    Map<String, String[]> paramMap = taskAdded.getParamMap();
    assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    assertEquals(anotherInstructorOfCourse1.email, paramMap.get(ParamsNames.INSTRUCTOR_EMAIL)[0]);
    ______TS("Typical case: Send email to remind a student to register for the course");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    remindAction = getAction(submissionParams);
    redirectResult = getRedirectResult(remindAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_REMINDER_SENT_TO + student1InCourse1.email, redirectResult.getStatusMessage());
    expectedLogSegment = "Registration Key sent to the following users " + "in Course <span class=\"bold\">[" + courseId + "]</span>:<br>" + student1InCourse1.name + "<span class=\"bold\"> (" + student1InCourse1.email + ")" + "</span>.<br>";
    AssertHelper.assertContains(expectedLogSegment, remindAction.getLogMessage());
    verifySpecifiedTasksAdded(remindAction, Const.TaskQueue.STUDENT_COURSE_JOIN_EMAIL_QUEUE_NAME, 1);
    taskAdded = remindAction.getTaskQueuer().getTasksAdded().get(0);
    paramMap = taskAdded.getParamMap();
    assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    assertEquals(student1InCourse1.email, paramMap.get(ParamsNames.STUDENT_EMAIL)[0]);
    ______TS("Masquerade mode: Send emails to all unregistered student to remind registering for the course");
    gaeSimulation.loginAsAdmin(adminUserId);
    StudentAttributes unregisteredStudent1 = StudentAttributes.builder(courseId, "Unregistered student 1", "unregistered1@email.com").withSection("Section 1").withTeam("Team Unregistered").withComments("").build();
    StudentAttributes unregisteredStudent2 = StudentAttributes.builder(courseId, "Unregistered student 2", "unregistered2@email.com").withSection("Section 1").withTeam("Team Unregistered").withComments("").build();
    StudentsLogic.inst().createStudentCascadeWithoutDocument(unregisteredStudent1);
    StudentsLogic.inst().createStudentCascadeWithoutDocument(unregisteredStudent2);
    /* Reassign the attributes to retrieve their keys */
    unregisteredStudent1 = StudentsLogic.inst().getStudentForEmail(courseId, unregisteredStudent1.email);
    unregisteredStudent2 = StudentsLogic.inst().getStudentForEmail(courseId, unregisteredStudent2.email);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId };
    remindAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(remindAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_REMINDERS_SENT, redirectResult.getStatusMessage());
    // 2 unregistered students, thus 2 emails queued to be sent
    verifySpecifiedTasksAdded(remindAction, Const.TaskQueue.STUDENT_COURSE_JOIN_EMAIL_QUEUE_NAME, 2);
    List<TaskWrapper> tasksAdded = remindAction.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        paramMap = task.getParamMap();
        assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    }
    expectedLogSegment = "Registration Key sent to the following users " + "in Course <span class=\"bold\">[" + courseId + "]</span>:<br>" + unregisteredStudent1.name + "<span class=\"bold\"> (" + unregisteredStudent1.email + ")" + "</span>.<br>" + StringHelper.encrypt(unregisteredStudent1.key) + "&studentemail=unregistered1%40email.com&courseid=idOfTypicalCourse1<br>" + unregisteredStudent2.name + "<span class=\"bold\"> (" + unregisteredStudent2.email + ")" + "</span>.<br>" + StringHelper.encrypt(unregisteredStudent2.key) + "&studentemail=unregistered2%40email.com&courseid=idOfTypicalCourse1<br>";
    AssertHelper.assertContains(expectedLogSegment, remindAction.getLogMessage());
    StudentsLogic.inst().deleteStudentCascadeWithoutDocument(courseId, unregisteredStudent1.email);
    StudentsLogic.inst().deleteStudentCascadeWithoutDocument(courseId, unregisteredStudent2.email);
    ______TS("Typical case: no unregistered students in course");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId };
    remindAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(remindAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_REMINDERS_SENT, redirectResult.getStatusMessage());
    expectedLogSegment = "Registration Key sent to the following users " + "in Course <span class=\"bold\">[" + courseId + "]</span>:<br>";
    AssertHelper.assertContains(expectedLogSegment, remindAction.getLogMessage());
    // no unregistered students, thus no emails sent
    verifyNoTasksAdded(remindAction);
    ______TS("Failure case: Invalid email parameter");
    String invalidEmail = "invalidEmail.com";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, invalidEmail };
    executeAndAssertEntityNotFoundException(instructorId, submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENT_EMAIL, invalidEmail };
    executeAndAssertEntityNotFoundException(instructorId, submissionParams);
    ______TS("Failure case: Invalid course id parameter");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "invalidCourseId", Const.ParamsNames.INSTRUCTOR_EMAIL, anotherInstructorOfCourse1.email };
    executeAndAssertEntityNotFoundException(instructorId, submissionParams);
}
Also used : TaskWrapper(teammates.common.util.TaskWrapper) InstructorCourseRemindAction(teammates.ui.controller.InstructorCourseRemindAction) RedirectResult(teammates.ui.controller.RedirectResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 58 with RedirectResult

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

the class InstructorCourseStudentDeleteActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    ______TS("success: delete a student ");
    gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    InstructorCourseStudentDeleteAction action = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(action);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.STUDENT_DELETED, redirectResult.getStatusMessage());
    AssertHelper.assertLogMessageEquals("TEAMMATESLOG|||instructorCourseStudentDelete|||instructorCourseStudentDelete|||" + "true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Student <span class=\"bold\">student1InCourse1@gmail.tmt</span> " + "in Course <span class=\"bold\">[idOfTypicalCourse1]</span> deleted.|||" + "/page/instructorCourseStudentDelete", action.getLogMessage());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorCourseStudentDeleteAction(teammates.ui.controller.InstructorCourseStudentDeleteAction) Test(org.testng.annotations.Test)

Example 59 with RedirectResult

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

the class InstructorFeedbackQuestionEditActionTest method testExecuteAndPostProcessMsq.

@Test
public void testExecuteAndPostProcessMsq() {
    DataBundle dataBundle = loadDataBundle("/FeedbackSessionQuestionTypeTest.json");
    removeAndRestoreDataBundle(dataBundle);
    InstructorAttributes instructor1ofCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("msqSession");
    FeedbackQuestionAttributes fq = FeedbackQuestionsLogic.inst().getFeedbackQuestion(fs.getFeedbackSessionName(), fs.getCourseId(), 1);
    FeedbackMsqQuestionDetails msqDetails = (FeedbackMsqQuestionDetails) fq.getQuestionDetails();
    FeedbackResponsesDb frDb = new FeedbackResponsesDb();
    ______TS("Edit text");
    // There is 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, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, Integer.toString(msqDetails.getNumOfMsqChoices()), Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", msqDetails.getMsqChoices().get(0), Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-1", msqDetails.getMsqChoices().get(1), 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(), Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    InstructorFeedbackQuestionEditAction a = getAction(editTextParams);
    RedirectResult r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MSQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    // All existing response should remain
    assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    ______TS("Edit options");
    // There should already be responses for this question
    assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    String[] editOptionParams = { 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, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "5", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-2", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-3", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-4", "The Atmosphere", 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(), Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    a = getAction(editOptionParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MSQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    // All existing response should be deleted as option is edited
    assertTrue(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    ______TS("Edit to generated options");
    String[] editToGeneratedOptionParams = { 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, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "4", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-1", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-2", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-3", "The Atmosphere", 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(), Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    a = getAction(editToGeneratedOptionParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MSQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Delete Feedback");
    String[] deleteParams = { 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, "MSQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "4", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-1", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-2", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MSQCHOICE + "-3", "The Atmosphere", 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, "delete", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId(), Const.ParamsNames.FEEDBACK_QUESTION_MSQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    a = getAction(deleteParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MSQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_DELETED, r.getStatusMessage());
    assertFalse(r.isError);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackMsqQuestionDetails(teammates.common.datatransfer.questions.FeedbackMsqQuestionDetails) InstructorFeedbackQuestionEditAction(teammates.ui.controller.InstructorFeedbackQuestionEditAction) DataBundle(teammates.common.datatransfer.DataBundle) RedirectResult(teammates.ui.controller.RedirectResult) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackResponsesDb(teammates.storage.api.FeedbackResponsesDb) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 60 with RedirectResult

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

the class InstructorFeedbackQuestionEditActionTest method testExecuteAndPostProcessMcq.

@Test
public void testExecuteAndPostProcessMcq() {
    DataBundle dataBundle = loadDataBundle("/FeedbackSessionQuestionTypeTest.json");
    removeAndRestoreDataBundle(dataBundle);
    InstructorAttributes instructor1ofCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("mcqSession");
    FeedbackQuestionAttributes fq = FeedbackQuestionsLogic.inst().getFeedbackQuestion(fs.getFeedbackSessionName(), fs.getCourseId(), 1);
    FeedbackMcqQuestionDetails mcqDetails = (FeedbackMcqQuestionDetails) fq.getQuestionDetails();
    FeedbackResponsesDb frDb = new FeedbackResponsesDb();
    ______TS("Edit text");
    // There is 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, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, Integer.toString(mcqDetails.getNumOfMcqChoices()), Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", mcqDetails.getMcqChoices().get(0), Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-1", mcqDetails.getMcqChoices().get(1), 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(), Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    InstructorFeedbackQuestionEditAction a = getAction(editTextParams);
    RedirectResult r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MCQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    // All existing response should remain
    assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    ______TS("Edit options");
    // There should already be responses for this question
    assertFalse(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    String[] editOptionParams = { 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, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "5", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-2", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-3", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-4", "The Atmosphere", 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(), Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.NONE.toString() };
    a = getAction(editOptionParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MCQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    // All existing response should be deleted as option is edited
    assertTrue(frDb.getFeedbackResponsesForQuestion(fq.getId()).isEmpty());
    ______TS("Edit to generated");
    String[] editToGeneratedOptionParams = { 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, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_TEXT, "What do you like best about the class?", Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION, "more details", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "4", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-1", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-2", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-3", "The Atmosphere", 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(), Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    a = getAction(editToGeneratedOptionParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MCQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_EDITED, r.getStatusMessage());
    assertFalse(r.isError);
    ______TS("Delete Feedback");
    String[] deleteParams = { 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, "MCQ", Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED, "4", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-0", "The Content", // empty option
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-1", // empty option
    "", // empty option with extra whitespace
    Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-2", "          ", Const.ParamsNames.FEEDBACK_QUESTION_MCQCHOICE + "-3", "The Atmosphere", 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, "delete", Const.ParamsNames.FEEDBACK_QUESTION_ID, fq.getId(), Const.ParamsNames.FEEDBACK_QUESTION_MCQ_GENERATED_OPTIONS, FeedbackParticipantType.STUDENTS.toString() };
    a = getAction(deleteParams);
    r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_EDIT_PAGE, "FSQTT.idOfTypicalCourse1", "MCQ+Session", "FSQTT.idOfInstructor1OfCourse1", false), r.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_QUESTION_DELETED, r.getStatusMessage());
    assertFalse(r.isError);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackQuestionEditAction(teammates.ui.controller.InstructorFeedbackQuestionEditAction) DataBundle(teammates.common.datatransfer.DataBundle) RedirectResult(teammates.ui.controller.RedirectResult) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackResponsesDb(teammates.storage.api.FeedbackResponsesDb) FeedbackMcqQuestionDetails(teammates.common.datatransfer.questions.FeedbackMcqQuestionDetails) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

RedirectResult (teammates.ui.controller.RedirectResult)68 Test (org.testng.annotations.Test)49 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)46 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)27 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 NullPostParameterException (teammates.common.exception.NullPostParameterException)10 ShowPageResult (teammates.ui.controller.ShowPageResult)10 DataBundle (teammates.common.datatransfer.DataBundle)9 StudentProfilePictureEditAction (teammates.ui.controller.StudentProfilePictureEditAction)9 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)8 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)8 InstructorFeedbackQuestionAddAction (teammates.ui.controller.InstructorFeedbackQuestionAddAction)8 InstructorFeedbackQuestionEditAction (teammates.ui.controller.InstructorFeedbackQuestionEditAction)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 FeedbackSessionsDb (teammates.storage.api.FeedbackSessionsDb)5 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)4 TaskWrapper (teammates.common.util.TaskWrapper)4