use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.
the class FeedbackSessionRemindParticularUsersEmailWorkerActionTest method allTests.
@Test
public void allTests() {
______TS("Send feedback session reminder email");
FeedbackSessionAttributes session1 = dataBundle.feedbackSessions.get("session1InCourse1");
StudentAttributes student1 = dataBundle.students.get("student1InCourse1");
InstructorAttributes instructor1 = dataBundle.instructors.get("instructor1OfCourse1");
String[] submissionParams = new String[] { ParamsNames.SUBMISSION_FEEDBACK, session1.getFeedbackSessionName(), ParamsNames.SUBMISSION_COURSE, session1.getCourseId(), ParamsNames.SUBMISSION_REMIND_USERLIST, student1.email, ParamsNames.SUBMISSION_REMIND_USERLIST, instructor1.email, ParamsNames.USER_ID, instructor1.googleId, ParamsNames.SUBMISSION_REMIND_USERLIST, "non-existent" };
FeedbackSessionRemindParticularUsersEmailWorkerAction action = getAction(submissionParams);
action.execute();
// send 3 emails as specified in the submission parameters
verifySpecifiedTasksAdded(action, Const.TaskQueue.SEND_EMAIL_QUEUE_NAME, 3);
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 recipient = paramMap.get(ParamsNames.EMAIL_RECEIVER)[0];
assertTrue(recipient.equals(student1.email) || recipient.equals(instructor1.email));
}
}
use of teammates.common.util.TaskWrapper 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);
}
use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.
the class InstructorFeedbackUnpublishActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
gaeSimulation.loginAsInstructor(typicalBundle.instructors.get("instructor1OfCourse1").googleId);
FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session2InCourse1");
String[] paramsNormal = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
String[] paramsWithNullCourseId = { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
String[] paramsWithNullFeedbackSessionName = { Const.ParamsNames.COURSE_ID, session.getCourseId() };
______TS("Typical successful case: session unpublishable");
makeFeedbackSessionPublished(session);
InstructorFeedbackUnpublishAction unpublishAction = getAction(paramsNormal);
RedirectResult result = getRedirectResult(unpublishAction);
String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, "idOfInstructor1OfCourse1");
assertEquals(expectedDestination, result.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_SESSION_UNPUBLISHED, result.getStatusMessage());
assertFalse(result.isError);
verifySpecifiedTasksAdded(unpublishAction, Const.TaskQueue.FEEDBACK_SESSION_UNPUBLISHED_EMAIL_QUEUE_NAME, 1);
TaskWrapper taskAdded = unpublishAction.getTaskQueuer().getTasksAdded().get(0);
Map<String, String[]> paramMap = taskAdded.getParamMap();
assertEquals(session.getCourseId(), paramMap.get(ParamsNames.EMAIL_COURSE)[0]);
assertEquals(session.getSessionName(), paramMap.get(ParamsNames.EMAIL_FEEDBACK)[0]);
______TS("Unsuccessful case 1: params with null course id");
String errorMessage = "";
unpublishAction = getAction(paramsWithNullCourseId);
try {
unpublishAction.executeAndPostProcess();
signalFailureToDetectException("NullPostParameterException expected");
} catch (NullPostParameterException e) {
errorMessage = e.getMessage();
}
assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), errorMessage);
______TS("Unsuccessful case 2: params with null feedback session name");
errorMessage = "";
unpublishAction = getAction(paramsWithNullFeedbackSessionName);
try {
unpublishAction.executeAndPostProcess();
signalFailureToDetectException("NullPostParameterException expected");
} catch (NullPostParameterException e) {
errorMessage = e.getMessage();
}
assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.FEEDBACK_SESSION_NAME), errorMessage);
______TS("Unsuccessful case 3: trying to unpublish a session not currently published");
makeFeedbackSessionUnpublished(session);
unpublishAction = getAction(paramsNormal);
result = getRedirectResult(unpublishAction);
expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, true, "idOfInstructor1OfCourse1");
assertEquals(expectedDestination, result.getDestinationWithParams());
assertEquals("Error unpublishing feedback session: Session has already been unpublished.", result.getStatusMessage());
assertTrue(result.isError);
verifyNoTasksAdded(unpublishAction);
makeFeedbackSessionPublished(session);
}
use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.
the class TaskQueuer method addTaskMultisetParam.
protected void addTaskMultisetParam(String queueName, String workerUrl, Map<String, String[]> paramMap) {
TaskWrapper task = new TaskWrapper(queueName, workerUrl, paramMap);
new TaskQueuesLogic().addTask(task);
}
use of teammates.common.util.TaskWrapper in project teammates by TEAMMATES.
the class TaskQueuer method addTask.
// The following methods are facades to the actual logic for adding tasks to the queue.
// Using this method, the actual logic can still be black-boxed
// while at the same time allowing this API to be mocked during test.
protected void addTask(String queueName, String workerUrl, Map<String, String> paramMap) {
Map<String, String[]> multisetParamMap = new HashMap<>();
paramMap.forEach((key, value) -> multisetParamMap.put(key, new String[] { value }));
TaskWrapper task = new TaskWrapper(queueName, workerUrl, multisetParamMap);
new TaskQueuesLogic().addTask(task);
}
Aggregations