Search in sources :

Example 1 with TaskWrapper

use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.

the class FeedbackSessionClosedRemindersActionTest method allTests.

@Test
public void allTests() throws Exception {
    ______TS("default state of typical data bundle: 0 sessions closed recently");
    FeedbackSessionClosedRemindersAction action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
    ______TS("1 session closed recently, 1 session closed recently with disabled closed reminder, " + "1 session closed recently but still in grace period");
    // Session is closed recently
    FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
    session1.setTimeZone(ZoneId.of("UTC"));
    session1.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(-2));
    session1.setEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(-1));
    fsLogic.updateFeedbackSession(session1);
    verifyPresentInDatastore(session1);
    // Ditto, but with disabled closed reminder
    FeedbackSessionAttributes session2 = dataBundle.feedbackSessions.get("session2InCourse1");
    session2.setTimeZone(ZoneId.of("UTC"));
    session2.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(-2));
    session2.setEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(-1));
    session2.setClosingEmailEnabled(false);
    fsLogic.updateFeedbackSession(session2);
    verifyPresentInDatastore(session2);
    // Still in grace period; closed reminder should not be sent
    FeedbackSessionAttributes session3 = dataBundle.feedbackSessions.get("gracePeriodSession");
    session3.setTimeZone(ZoneId.of("UTC"));
    session3.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(-2));
    session3.setEndTime(Instant.now());
    fsLogic.updateFeedbackSession(session3);
    verifyPresentInDatastore(session3);
    action = getAction();
    action.execute();
    // 5 students and 5 instructors in course1
    verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 10);
    String courseName = coursesLogic.getCourse(session1.getCourseId()).getName();
    List<TaskWrapper> tasksAdded = action.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        assertEquals(String.format(EmailType.FEEDBACK_CLOSED.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
    }
    ______TS("1 session closed recently with closed emails sent");
    session1.setSentClosedEmail(true);
    fsLogic.updateFeedbackSession(session1);
    action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) FeedbackSessionClosedRemindersAction(teammates.ui.automated.FeedbackSessionClosedRemindersAction) Test(org.testng.annotations.Test)

Example 2 with TaskWrapper

use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.

the class FeedbackSessionClosingRemindersActionTest method allTests.

@Test
public void allTests() throws Exception {
    ______TS("default state of typical data bundle: 0 sessions closing soon");
    FeedbackSessionClosingRemindersAction action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
    ______TS("1 session closing soon, 1 session closing soon with disabled closing reminder, " + "1 session closing soon but not yet opened");
    // Modify session to close in 24 hours
    FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
    session1.setTimeZone(ZoneId.of("UTC"));
    session1.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(-1));
    session1.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(1));
    fsLogic.updateFeedbackSession(session1);
    verifyPresentInDatastore(session1);
    // Ditto, but disable the closing reminder
    FeedbackSessionAttributes session2 = dataBundle.feedbackSessions.get("session2InCourse2");
    session2.setTimeZone(ZoneId.of("UTC"));
    session2.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(-1));
    session2.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(1));
    session2.setClosingEmailEnabled(false);
    fsLogic.updateFeedbackSession(session2);
    verifyPresentInDatastore(session2);
    // 1 session not yet opened; do not send the closing reminder
    FeedbackSessionAttributes session3 = dataBundle.feedbackSessions.get("gracePeriodSession");
    session3.setTimeZone(ZoneId.of("UTC"));
    session3.setStartTime(TimeHelperExtension.getInstantHoursOffsetFromNow(1));
    session3.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(1));
    fsLogic.updateFeedbackSession(session3);
    verifyPresentInDatastore(session3);
    action = getAction();
    action.execute();
    // 5 students and 5 instructors in course1, 2 students have completed the feedback session
    verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 8);
    String courseName = coursesLogic.getCourse(session1.getCourseId()).getName();
    List<TaskWrapper> tasksAdded = action.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        assertEquals(String.format(EmailType.FEEDBACK_CLOSING.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
    }
    ______TS("1 session closing soon with emails sent");
    session1.setSentClosingEmail(true);
    fsLogic.updateFeedbackSession(session1);
    action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackSessionClosingRemindersAction(teammates.ui.automated.FeedbackSessionClosingRemindersAction) TaskWrapper(teammates.common.util.TaskWrapper) Test(org.testng.annotations.Test)

Example 3 with TaskWrapper

use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.

the class FeedbackSessionOpeningRemindersActionTest method allTests.

@Test
public void allTests() throws Exception {
    ______TS("default state of typical data bundle: no sessions opened");
    FeedbackSessionOpeningRemindersAction action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
    ______TS("1 session opened, 1 session opened with disabled opening reminder");
    // Close the session and re-open with the opening time 1 day before
    FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
    session1.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(2));
    session1.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(3));
    fsLogic.updateFeedbackSession(session1);
    session1.setStartTime(TimeHelperExtension.getInstantHoursOffsetFromNow(-23));
    fsLogic.updateFeedbackSession(session1);
    // Ditto, but disable the opening reminder, but currently open emails will still be sent regardless
    FeedbackSessionAttributes session2 = dataBundle.feedbackSessions.get("session2InCourse1");
    session2.setStartTime(TimeHelper.getInstantDaysOffsetFromNow(2));
    session2.setEndTime(TimeHelper.getInstantDaysOffsetFromNow(3));
    session2.setOpeningEmailEnabled(false);
    fsLogic.updateFeedbackSession(session2);
    session2.setStartTime(TimeHelperExtension.getInstantHoursOffsetFromNow(-23));
    fsLogic.updateFeedbackSession(session2);
    action = getAction();
    action.execute();
    // 5 students and 5 instructors in course1
    verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 20);
    String courseName = coursesLogic.getCourse(session1.getCourseId()).getName();
    List<TaskWrapper> tasksAdded = action.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        try {
            assertEquals(String.format(EmailType.FEEDBACK_OPENING.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
        } catch (AssertionError ae) {
            assertEquals(String.format(EmailType.FEEDBACK_OPENING.getSubject(), courseName, session2.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
        }
    }
    ______TS("2 sessions opened with emails sent");
    session1.setSentOpenEmail(true);
    fsLogic.updateFeedbackSession(session1);
    session2.setSentOpenEmail(true);
    fsLogic.updateFeedbackSession(session2);
    action = getAction();
    action.execute();
    verifyNoTasksAdded(action);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) FeedbackSessionOpeningRemindersAction(teammates.ui.automated.FeedbackSessionOpeningRemindersAction) Test(org.testng.annotations.Test)

Example 4 with TaskWrapper

use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.

the class FeedbackSessionRemindEmailWorkerActionTest method allTests.

@Test
public void allTests() throws Exception {
    ______TS("Send feedback session reminder email");
    FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
    InstructorAttributes instructor1 = dataBundle.instructors.get("instructor1OfCourse1");
    // re-read from Datastore to update the respondents list
    session1 = fsLogic.getFeedbackSession(session1.getFeedbackSessionName(), session1.getCourseId());
    String[] submissionParams = new String[] { ParamsNames.SUBMISSION_FEEDBACK, session1.getFeedbackSessionName(), ParamsNames.SUBMISSION_COURSE, session1.getCourseId(), ParamsNames.USER_ID, instructor1.getGoogleId() };
    FeedbackSessionRemindEmailWorkerAction action = getAction(submissionParams);
    action.execute();
    // 2 students and 4 instructors sent reminder, 1 instructor notified
    verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 7);
    List<String> studentRecipientList = new ArrayList<>();
    for (StudentAttributes student : studentsLogic.getStudentsForCourse(session1.getCourseId())) {
        if (!fsLogic.isFeedbackSessionCompletedByStudent(session1, student.email)) {
            studentRecipientList.add(student.email);
        }
    }
    List<String> instructorRecipientList = new ArrayList<>();
    List<String> instructorNotifiedList = new ArrayList<>();
    for (InstructorAttributes instructor : instructorsLogic.getInstructorsForCourse(session1.getCourseId())) {
        if (!fsLogic.isFeedbackSessionCompletedByInstructor(session1, instructor.email)) {
            instructorRecipientList.add(instructor.email);
        }
    }
    instructorNotifiedList.add(instructorsLogic.getInstructorForGoogleId(session1.getCourseId(), instructor1.getGoogleId()).email);
    String courseName = coursesLogic.getCourse(session1.getCourseId()).getName();
    List<TaskWrapper> tasksAdded = action.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        assertEquals(String.format(EmailType.FEEDBACK_SESSION_REMINDER.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
        String header = "The email below has been sent to students of course: [" + session1.getCourseId() + "]";
        String content = paramMap.get(ParamsNames.EMAIL_CONTENT)[0];
        String recipient = paramMap.get(ParamsNames.EMAIL_RECEIVER)[0];
        if (content.contains(header)) {
            // notification to only requesting instructors
            assertTrue(instructorNotifiedList.contains(recipient));
            instructorNotifiedList.remove(recipient);
            continue;
        }
        if (studentRecipientList.contains(recipient)) {
            studentRecipientList.remove(recipient);
            continue;
        }
        if (instructorRecipientList.contains(recipient)) {
            instructorRecipientList.remove(recipient);
            continue;
        }
        fail("Email recipient " + recipient + " is not in the list!");
    }
    // Ensure that every email recipient is accounted for
    assertTrue(String.valueOf(studentRecipientList.size()), studentRecipientList.isEmpty());
    assertTrue(String.valueOf(instructorRecipientList.size()), instructorRecipientList.isEmpty());
    assertTrue(instructorNotifiedList.isEmpty());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) FeedbackSessionRemindEmailWorkerAction(teammates.ui.automated.FeedbackSessionRemindEmailWorkerAction) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 5 with TaskWrapper

use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.

the class FeedbackSessionUnpublishedEmailWorkerActionTest method allTests.

@Test
public void allTests() {
    FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
    String[] submissionParams = new String[] { ParamsNames.EMAIL_COURSE, session1.getCourseId(), ParamsNames.EMAIL_FEEDBACK, session1.getFeedbackSessionName() };
    FeedbackSessionUnpublishedEmailWorkerAction action = getAction(submissionParams);
    action.execute();
    // 5 students and 5 instructors in course1
    verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 10);
    String courseName = coursesLogic.getCourse(session1.getCourseId()).getName();
    List<TaskWrapper> tasksAdded = action.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        assertEquals(String.format(EmailType.FEEDBACK_UNPUBLISHED.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) FeedbackSessionUnpublishedEmailWorkerAction(teammates.ui.automated.FeedbackSessionUnpublishedEmailWorkerAction) Test(org.testng.annotations.Test)

Aggregations

TaskWrapper (teammates.common.util.TaskWrapper)18 Test (org.testng.annotations.Test)12 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)9 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)5 HashMap (java.util.HashMap)4 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)4 RedirectResult (teammates.ui.controller.RedirectResult)4 TaskQueuesLogic (teammates.logic.core.TaskQueuesLogic)3 NullPostParameterException (teammates.common.exception.NullPostParameterException)2 ArrayList (java.util.ArrayList)1 FeedbackSessionClosedRemindersAction (teammates.ui.automated.FeedbackSessionClosedRemindersAction)1 FeedbackSessionClosingRemindersAction (teammates.ui.automated.FeedbackSessionClosingRemindersAction)1 FeedbackSessionOpeningRemindersAction (teammates.ui.automated.FeedbackSessionOpeningRemindersAction)1 FeedbackSessionPublishedEmailWorkerAction (teammates.ui.automated.FeedbackSessionPublishedEmailWorkerAction)1 FeedbackSessionRemindEmailWorkerAction (teammates.ui.automated.FeedbackSessionRemindEmailWorkerAction)1 FeedbackSessionRemindParticularUsersEmailWorkerAction (teammates.ui.automated.FeedbackSessionRemindParticularUsersEmailWorkerAction)1 FeedbackSessionUnpublishedEmailWorkerAction (teammates.ui.automated.FeedbackSessionUnpublishedEmailWorkerAction)1 InstructorCourseEnrollSaveAction (teammates.ui.controller.InstructorCourseEnrollSaveAction)1 InstructorCourseInstructorAddAction (teammates.ui.controller.InstructorCourseInstructorAddAction)1 InstructorCourseRemindAction (teammates.ui.controller.InstructorCourseRemindAction)1