Search in sources :

Example 6 with TaskWrapper

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

the class InstructorFeedbackPublishActionTest 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 publishable");
    makeFeedbackSessionUnpublished(session);
    InstructorFeedbackPublishAction publishAction = getAction(paramsNormal);
    RedirectResult result = getRedirectResult(publishAction);
    String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_PUBLISHED, result.getStatusMessage());
    assertFalse(result.isError);
    verifySpecifiedTasksAdded(publishAction, Const.TaskQueue.FEEDBACK_SESSION_PUBLISHED_EMAIL_QUEUE_NAME, 1);
    TaskWrapper taskAdded = publishAction.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 = "";
    publishAction = getAction(paramsWithNullCourseId);
    try {
        publishAction.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 = "";
    publishAction = getAction(paramsWithNullFeedbackSessionName);
    try {
        publishAction.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 publish a session not currently unpublished");
    makeFeedbackSessionPublished(session);
    publishAction = getAction(paramsNormal);
    result = getRedirectResult(publishAction);
    expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, true, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals("Error publishing feedback session: Session has already been published.", result.getStatusMessage());
    assertTrue(result.isError);
    verifyNoTasksAdded(publishAction);
    makeFeedbackSessionUnpublished(session);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) NullPostParameterException(teammates.common.exception.NullPostParameterException) InstructorFeedbackPublishAction(teammates.ui.controller.InstructorFeedbackPublishAction) RedirectResult(teammates.ui.controller.RedirectResult) Test(org.testng.annotations.Test)

Example 7 with TaskWrapper

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

the class InstructorCourseEnrollSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String enrollString = "";
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Typical case: add and edit students for non-empty course");
    enrollString = "Section | Team | Name | Email | Comment" + System.lineSeparator() + // A new student
    "Section 3 \t Team 1\tJean Wong\tjean@email.tmt\tExchange student" + System.lineSeparator() + // A new student with extra spaces in the team and name
    "Section 3 \t Team   1\tstudent  with   extra  spaces  \t" + "studentWithExtraSpaces@gmail.tmt\t" + System.lineSeparator() + // A student to be modified
    "Section 2 \t Team 1.3\tstudent1 In Course1</td></div>'\"\tstudent1InCourse1@gmail.tmt\t" + "New comment added" + System.lineSeparator() + // An existing student with no modification
    "Section 1 \t Team 1.1</td></div>'\"\tstudent2 In Course1\tstudent2InCourse1@gmail.tmt\t" + System.lineSeparator() + // An existing student, now with extra spaces, should cause no modification
    "Section 1 \t Team   1.1</td></div>'\"\tstudent3  In   Course1  \tstudent3InCourse1@gmail.tmt\t";
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollString };
    InstructorCourseEnrollSaveAction enrollAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(enrollAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL_RESULT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    // there are 6 sessions in this course
    verifySpecifiedTasksAdded(enrollAction, Const.TaskQueue.FEEDBACK_RESPONSE_ADJUSTMENT_QUEUE_NAME, 6);
    List<TaskWrapper> tasksAdded = enrollAction.getTaskQueuer().getTasksAdded();
    for (TaskWrapper task : tasksAdded) {
        Map<String, String[]> paramMap = task.getParamMap();
        assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    }
    InstructorCourseEnrollResultPageData pageData = (InstructorCourseEnrollResultPageData) pageResult.data;
    assertEquals(courseId, pageData.getCourseId());
    StudentAttributes newStudent = StudentAttributes.builder(courseId, "Jean Wong", "jean@email.tmt").withSection("Section 3").withTeam("Team 1").withComments("Exchange student").withGoogleId("jean").build();
    newStudent.updateStatus = StudentUpdateStatus.NEW;
    verifyStudentEnrollmentStatus(newStudent, pageData.getEnrollResultPanelList());
    StudentAttributes newStudentWithExtraSpaces = StudentAttributes.builder(courseId, "student with extra spaces", "studentWithExtraSpaces@gmail.tmt").withSection("Section 3").withTeam("Team 1").withComments("").withGoogleId("student").build();
    newStudentWithExtraSpaces.updateStatus = StudentUpdateStatus.NEW;
    verifyStudentEnrollmentStatus(newStudentWithExtraSpaces, pageData.getEnrollResultPanelList());
    StudentAttributes modifiedStudent = typicalBundle.students.get("student1InCourse1");
    modifiedStudent.comments = "New comment added";
    modifiedStudent.section = "Section 2";
    modifiedStudent.team = "Team 1.3";
    modifiedStudent.updateStatus = StudentUpdateStatus.MODIFIED;
    verifyStudentEnrollmentStatus(modifiedStudent, pageData.getEnrollResultPanelList());
    StudentAttributes unmodifiedStudent = typicalBundle.students.get("student2InCourse1");
    unmodifiedStudent.updateStatus = StudentUpdateStatus.UNMODIFIED;
    verifyStudentEnrollmentStatus(unmodifiedStudent, pageData.getEnrollResultPanelList());
    StudentAttributes unmodifiedStudentWithExtraSpaces = typicalBundle.students.get("student3InCourse1");
    unmodifiedStudentWithExtraSpaces.updateStatus = StudentUpdateStatus.UNMODIFIED;
    verifyStudentEnrollmentStatus(unmodifiedStudentWithExtraSpaces, pageData.getEnrollResultPanelList());
    String expectedLogSegment = "Students Enrolled in Course <span class=\"bold\">[" + courseId + "]" + ":</span><br>" + SanitizationHelper.sanitizeForHtml(enrollString).replace("\n", "<br>");
    AssertHelper.assertContains(expectedLogSegment, enrollAction.getLogMessage());
    ______TS("Masquerade mode, enrollment into empty course");
    if (CoursesLogic.inst().isCoursePresent("new-course")) {
        CoursesLogic.inst().deleteCourseCascade("new-course");
    }
    courseId = "new-course";
    CoursesLogic.inst().createCourseAndInstructor(instructorId, courseId, "New course", "UTC");
    gaeSimulation.loginAsAdmin("admin.user");
    String headerRow = "Name\tEmail\tTeam\tComment";
    String studentsInfo = "Jean Wong\tjean@email.tmt\tTeam 1\tExchange student" + System.lineSeparator() + "James Tan\tjames@email.tmt\tTeam 2\t";
    enrollString = headerRow + System.lineSeparator() + studentsInfo;
    submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollString };
    enrollAction = getAction(submissionParams);
    pageResult = getShowPageResult(enrollAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL_RESULT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    verifyNoTasksAdded(enrollAction);
    pageData = (InstructorCourseEnrollResultPageData) pageResult.data;
    assertEquals(courseId, pageData.getCourseId());
    StudentAttributes student1 = StudentAttributes.builder(courseId, "Jean Wong", "jean@email.tmt").withSection("None").withTeam("Team 1").withComments("Exchange student").withGoogleId("jean").build();
    student1.updateStatus = StudentUpdateStatus.NEW;
    verifyStudentEnrollmentStatus(student1, pageData.getEnrollResultPanelList());
    StudentAttributes student2 = StudentAttributes.builder(courseId, "James Tan", "james@email.tmt").withSection("None").withTeam("Team 2").withComments("").withGoogleId("james").build();
    student2.updateStatus = StudentUpdateStatus.NEW;
    verifyStudentEnrollmentStatus(student2, pageData.getEnrollResultPanelList());
    expectedLogSegment = "Students Enrolled in Course <span class=\"bold\">[" + courseId + "]:</span>" + "<br>" + enrollString.replace("\n", "<br>");
    AssertHelper.assertContains(expectedLogSegment, enrollAction.getLogMessage());
    ______TS("Failure case: enrollment failed due to invalid lines");
    gaeSimulation.loginAsInstructor(instructorId);
    String studentWithoutEnoughParam = "Team 1\tStudentWithNoEmailInput";
    String studentWithInvalidEmail = "Team 2\tBenjamin Tan\tinvalid.email.tmt";
    String invalidEmail = "invalid.email.tmt";
    enrollString = "Team | Name | Email" + System.lineSeparator() + studentWithoutEnoughParam + System.lineSeparator() + studentWithInvalidEmail;
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollString };
    enrollAction = getAction(submissionParams);
    pageResult = getShowPageResult(enrollAction);
    assertEquals(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageResult.destination);
    assertTrue(pageResult.isError);
    String expectedStatusMessage = "<p>" + "<span class=\"bold\">Problem in line : " + "<span class=\"invalidLine\">" + SanitizationHelper.sanitizeForHtml(studentWithoutEnoughParam) + "</span>" + "</span>" + "<br>" + "<span class=\"problemDetail\">&bull; " + StudentAttributesFactory.ERROR_ENROLL_LINE_TOOFEWPARTS + "</span>" + "</p>" + "<br>" + "<p>" + "<span class=\"bold\">Problem in line : " + "<span class=\"invalidLine\">" + SanitizationHelper.sanitizeForHtml(studentWithInvalidEmail) + "</span>" + "</span>" + "<br>" + "<span class=\"problemDetail\">&bull; " + SanitizationHelper.sanitizeForHtml(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH)) + "</span>" + "</p>";
    assertEquals(expectedStatusMessage, pageResult.getStatusMessage());
    verifyNoTasksAdded(enrollAction);
    InstructorCourseEnrollPageData enrollPageData = (InstructorCourseEnrollPageData) pageResult.data;
    assertEquals(courseId, enrollPageData.getCourseId());
    assertEquals(enrollString, enrollPageData.getEnrollStudents());
    expectedLogSegment = expectedStatusMessage + "<br>Enrollment string entered by user:<br>" + enrollString.replace("\n", "<br>");
    AssertHelper.assertContains(expectedLogSegment, enrollAction.getLogMessage());
    ______TS("Boundary test for size limit per enrollment");
    // can enroll, if within the size limit
    StringBuilder enrollStringBuilder = new StringBuilder(200);
    enrollStringBuilder.append("Section\tTeam\tName\tEmail");
    for (int i = 0; i < Const.SIZE_LIMIT_PER_ENROLLMENT; i++) {
        enrollStringBuilder.append(System.lineSeparator()).append("section" + i + "\tteam" + i + "\tname" + i + "\temail" + i + "@nonexistemail.nonexist");
    }
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollStringBuilder.toString() };
    enrollAction = getAction(submissionParams);
    pageResult = getShowPageResult(enrollAction);
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    verifyNoTasksAdded(enrollAction);
    // fail to enroll, if exceed the range
    enrollStringBuilder.append(System.lineSeparator()).append("section" + Const.SIZE_LIMIT_PER_ENROLLMENT + "\tteam" + Const.SIZE_LIMIT_PER_ENROLLMENT + "\tname" + Const.SIZE_LIMIT_PER_ENROLLMENT + "\temail" + Const.SIZE_LIMIT_PER_ENROLLMENT + "@nonexistemail.nonexist");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollStringBuilder.toString() };
    enrollAction = getAction(submissionParams);
    pageResult = getShowPageResult(enrollAction);
    assertEquals(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageResult.destination);
    assertTrue(pageResult.isError);
    assertEquals(Const.StatusMessages.QUOTA_PER_ENROLLMENT_EXCEED, pageResult.getStatusMessage());
    verifyNoTasksAdded(enrollAction);
    ______TS("Failure case: empty input");
    enrollString = "";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, enrollString };
    enrollAction = getAction(submissionParams);
    pageResult = getShowPageResult(enrollAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, true, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertTrue(pageResult.isError);
    assertEquals(Const.StatusMessages.ENROLL_LINE_EMPTY, pageResult.getStatusMessage());
    verifyNoTasksAdded(enrollAction);
    enrollPageData = (InstructorCourseEnrollPageData) pageResult.data;
    assertEquals(courseId, enrollPageData.getCourseId());
    assertEquals(enrollString, enrollPageData.getEnrollStudents());
    AssertHelper.assertContains(Const.StatusMessages.ENROLL_LINE_EMPTY, enrollAction.getLogMessage());
    CoursesLogic.inst().deleteCourseCascade("new-course");
    StudentsLogic.inst().deleteStudentsForCourseWithoutDocument(instructor1OfCourse1.courseId);
}
Also used : TaskWrapper(teammates.common.util.TaskWrapper) InstructorCourseEnrollResultPageData(teammates.ui.pagedata.InstructorCourseEnrollResultPageData) InstructorCourseEnrollPageData(teammates.ui.pagedata.InstructorCourseEnrollPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorCourseEnrollSaveAction(teammates.ui.controller.InstructorCourseEnrollSaveAction) ShowPageResult(teammates.ui.controller.ShowPageResult) Test(org.testng.annotations.Test)

Example 8 with TaskWrapper

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

the class InstructorCourseInstructorAddActionTest 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: add an instructor successfully");
    gaeSimulation.loginAsInstructor(instructorId);
    String newInstructorName = "New Instructor Name";
    String newInstructorEmail = "ICIAAT.newInstructor@email.tmt";
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
    InstructorCourseInstructorAddAction addAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(addAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, newInstructorName, newInstructorEmail), redirectResult.getStatusMessage());
    assertTrue(instructorsLogic.isEmailOfInstructorOfCourse(newInstructorEmail, courseId));
    InstructorAttributes instructorAdded = instructorsLogic.getInstructorForEmail(courseId, newInstructorEmail);
    assertEquals(newInstructorName, instructorAdded.name);
    assertEquals(newInstructorEmail, instructorAdded.email);
    String expectedLogSegment = "New instructor (<span class=\"bold\"> " + newInstructorEmail + "</span>)" + " for Course <span class=\"bold\">[" + courseId + "]</span> created.<br>";
    AssertHelper.assertContains(expectedLogSegment, addAction.getLogMessage());
    verifySpecifiedTasksAdded(addAction, Const.TaskQueue.INSTRUCTOR_COURSE_JOIN_EMAIL_QUEUE_NAME, 1);
    TaskWrapper taskAdded = addAction.getTaskQueuer().getTasksAdded().get(0);
    Map<String, String[]> paramMap = taskAdded.getParamMap();
    assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    assertEquals(instructorAdded.email, paramMap.get(ParamsNames.INSTRUCTOR_EMAIL)[0]);
    assertEquals(instructorId, paramMap.get(ParamsNames.INVITER_ID)[0]);
    ______TS("Error: try to add an existing instructor");
    addAction = getAction(submissionParams);
    redirectResult = getRedirectResult(addAction);
    AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_EXISTS, redirectResult.getStatusMessage());
    expectedLogSegment = "TEAMMATESLOG|||instructorCourseInstructorAdd|||instructorCourseInstructorAdd" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt" + "|||Servlet Action Failure : Trying to create a Instructor that exists: " + "idOfTypicalCourse1/ICIAAT.newInstructor@email.tmt" + "|||/page/instructorCourseInstructorAdd";
    AssertHelper.assertLogMessageEquals(expectedLogSegment, addAction.getLogMessage());
    verifyNoTasksAdded(addAction);
    ______TS("Error: try to add an instructor with invalid email");
    String newInvalidInstructorEmail = "ICIAAT.newInvalidInstructor.email.tmt";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInvalidInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER };
    addAction = getAction(submissionParams);
    redirectResult = getRedirectResult(addAction);
    AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, newInvalidInstructorEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH), redirectResult.getStatusMessage());
    expectedLogSegment = "TEAMMATESLOG|||instructorCourseInstructorAdd|||instructorCourseInstructorAdd" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt" + "|||Servlet Action Failure : " + getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, newInvalidInstructorEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH) + "|||/page/instructorCourseInstructorAdd";
    AssertHelper.assertLogMessageEquals(expectedLogSegment, addAction.getLogMessage());
    verifyNoTasksAdded(addAction);
    ______TS("Masquerade mode: add an instructor");
    instructorsLogic.deleteInstructorCascade(courseId, newInstructorEmail);
    gaeSimulation.loginAsAdmin(adminUserId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_NAME, newInstructorName, Const.ParamsNames.INSTRUCTOR_EMAIL, newInstructorEmail, Const.ParamsNames.INSTRUCTOR_ROLE_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME, Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, "true", Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, "true" };
    addAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(addAction);
    assertEquals(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, redirectResult.destination);
    assertFalse(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, newInstructorName, newInstructorEmail), redirectResult.getStatusMessage());
    assertTrue(instructorsLogic.isEmailOfInstructorOfCourse(newInstructorEmail, courseId));
    instructorAdded = instructorsLogic.getInstructorForEmail(courseId, newInstructorEmail);
    assertEquals(newInstructorName, instructorAdded.name);
    assertEquals(newInstructorEmail, instructorAdded.email);
    expectedLogSegment = "New instructor (<span class=\"bold\"> " + newInstructorEmail + "</span>)" + " for Course <span class=\"bold\">[" + courseId + "]</span> created.<br>";
    AssertHelper.assertContains(expectedLogSegment, addAction.getLogMessage());
    verifySpecifiedTasksAdded(addAction, Const.TaskQueue.INSTRUCTOR_COURSE_JOIN_EMAIL_QUEUE_NAME, 1);
    taskAdded = addAction.getTaskQueuer().getTasksAdded().get(0);
    paramMap = taskAdded.getParamMap();
    assertEquals(courseId, paramMap.get(ParamsNames.COURSE_ID)[0]);
    assertEquals(instructorAdded.email, paramMap.get(ParamsNames.INSTRUCTOR_EMAIL)[0]);
    assertEquals(adminUserId, paramMap.get(ParamsNames.INVITER_ID)[0]);
}
Also used : InstructorCourseInstructorAddAction(teammates.ui.controller.InstructorCourseInstructorAddAction) TaskWrapper(teammates.common.util.TaskWrapper) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 9 with TaskWrapper

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

the class TaskQueuer method addDeferredTask.

protected void addDeferredTask(String queueName, String workerUrl, Map<String, String> paramMap, long countdownTime) {
    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().addDeferredTask(task, countdownTime);
}
Also used : TaskWrapper(teammates.common.util.TaskWrapper) HashMap(java.util.HashMap) TaskQueuesLogic(teammates.logic.core.TaskQueuesLogic)

Example 10 with TaskWrapper

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

the class FeedbackSessionPublishedEmailWorkerActionTest 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() };
    FeedbackSessionPublishedEmailWorkerAction 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_PUBLISHED.getSubject(), courseName, session1.getSessionName()), paramMap.get(ParamsNames.EMAIL_SUBJECT)[0]);
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) FeedbackSessionPublishedEmailWorkerAction(teammates.ui.automated.FeedbackSessionPublishedEmailWorkerAction) 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